From a00d5d40314d42a227fae8214986a6497c68573e Mon Sep 17 00:00:00 2001 From: david-swift Date: Mon, 4 Mar 2024 21:22:42 +0100 Subject: [PATCH] Fix generation not working for single language --- Sources/GenerationLibrary/Generation.swift | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Sources/GenerationLibrary/Generation.swift b/Sources/GenerationLibrary/Generation.swift index 44eeb33..4d83d54 100644 --- a/Sources/GenerationLibrary/Generation.swift +++ b/Sources/GenerationLibrary/Generation.swift @@ -223,17 +223,25 @@ public enum Generation { defaultLanguage: String ) -> String { var result = "func string(for language: String) -> String {\n" - for language in getLanguages(dictionary: dictionary) where language != defaultLanguage { + let languages = getLanguages(dictionary: dictionary) + for language in languages where language != defaultLanguage { result += indent("if language.hasPrefix(\"\(language)\") {", by: indentTwo) result += indent("\nreturn \(language)", by: indentThree) result += indent("\n} else", by: indentTwo) } - result += """ - { - return \(defaultLanguage) + if languages.count <= 1 { + result += """ + return \(defaultLanguage) + } + """ + } else { + result += """ + { + return \(defaultLanguage) + } + } + """ } - } - """ return result }