Correction Stringium pour bien prendre en compte les tags des chaines strings (ex: ios,droid, iosonly...-
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
This commit is contained in:
parent
150445b906
commit
e3f90e0d48
@ -54,16 +54,26 @@ class StringsFileGenerator {
|
||||
|
||||
stringsFileContent += "\n/********** \(section.name) **********/\n\n"
|
||||
section.definitions.forEach { definition in
|
||||
var skipDefinition = false // Set to true if not matching tag
|
||||
let translationOpt: String? = {
|
||||
// If no matching tag => skip
|
||||
if definition.hasOneOrMoreMatchingTags(inputTags: inputTags) == false {
|
||||
skipDefinition = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// If tags contains `noTranslationTag` => get default lang
|
||||
if definition.tags.contains(Stringium.noTranslationTag) {
|
||||
return definition.translations[defaultLang]
|
||||
}
|
||||
|
||||
// Else: get specific lang
|
||||
return definition.translations[lang]
|
||||
}()
|
||||
|
||||
if let translation = translationOpt {
|
||||
stringsFileContent += "\"\(definition.name)\" = \"\(translation)\";\n\n"
|
||||
} else {
|
||||
} else if skipDefinition == false {
|
||||
let error = StringiumError.langNotDefined(lang, definition.name, definition.reference != nil)
|
||||
print(error.localizedDescription)
|
||||
Stringium.exit(withError: error)
|
||||
@ -90,6 +100,10 @@ class StringsFileGenerator {
|
||||
|
||||
content += "\n\t// MARK: - \(section.name)"
|
||||
section.definitions.forEach { definition in
|
||||
guard definition.hasOneOrMoreMatchingTags(inputTags: tags) == true else {
|
||||
return // Go to next definition
|
||||
}
|
||||
|
||||
if staticVar {
|
||||
content += "\n\n\(definition.getNSLocalizedStringStaticProperty(forLang: lang))"
|
||||
} else {
|
||||
|
@ -36,6 +36,13 @@ class Definition {
|
||||
return Definition(name: definitionName)
|
||||
}
|
||||
|
||||
func hasOneOrMoreMatchingTags(inputTags: [String]) -> Bool {
|
||||
if Set(inputTags).intersection(Set(self.tags)).isEmpty {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
private func getStringParameters(input: String) -> (inputParameters: [String], translationArguments: [String])? {
|
||||
|
@ -28,12 +28,12 @@ class Section {
|
||||
|
||||
func hasOneOrMoreMatchingTags(tags: [String]) -> Bool {
|
||||
let allTags = definitions.flatMap { $0.tags }
|
||||
let allTagsSet = Set(allTags)
|
||||
|
||||
for tag in tags {
|
||||
if allTags.contains(tag) {
|
||||
return true
|
||||
}
|
||||
let intersection = Set(tags).intersection(allTagsSet)
|
||||
if intersection.isEmpty {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user