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"
|
stringsFileContent += "\n/********** \(section.name) **********/\n\n"
|
||||||
section.definitions.forEach { definition in
|
section.definitions.forEach { definition in
|
||||||
|
var skipDefinition = false // Set to true if not matching tag
|
||||||
let translationOpt: String? = {
|
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) {
|
if definition.tags.contains(Stringium.noTranslationTag) {
|
||||||
return definition.translations[defaultLang]
|
return definition.translations[defaultLang]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Else: get specific lang
|
||||||
return definition.translations[lang]
|
return definition.translations[lang]
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if let translation = translationOpt {
|
if let translation = translationOpt {
|
||||||
stringsFileContent += "\"\(definition.name)\" = \"\(translation)\";\n\n"
|
stringsFileContent += "\"\(definition.name)\" = \"\(translation)\";\n\n"
|
||||||
} else {
|
} else if skipDefinition == false {
|
||||||
let error = StringiumError.langNotDefined(lang, definition.name, definition.reference != nil)
|
let error = StringiumError.langNotDefined(lang, definition.name, definition.reference != nil)
|
||||||
print(error.localizedDescription)
|
print(error.localizedDescription)
|
||||||
Stringium.exit(withError: error)
|
Stringium.exit(withError: error)
|
||||||
@ -90,6 +100,10 @@ class StringsFileGenerator {
|
|||||||
|
|
||||||
content += "\n\t// MARK: - \(section.name)"
|
content += "\n\t// MARK: - \(section.name)"
|
||||||
section.definitions.forEach { definition in
|
section.definitions.forEach { definition in
|
||||||
|
guard definition.hasOneOrMoreMatchingTags(inputTags: tags) == true else {
|
||||||
|
return // Go to next definition
|
||||||
|
}
|
||||||
|
|
||||||
if staticVar {
|
if staticVar {
|
||||||
content += "\n\n\(definition.getNSLocalizedStringStaticProperty(forLang: lang))"
|
content += "\n\n\(definition.getNSLocalizedStringStaticProperty(forLang: lang))"
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,6 +36,13 @@ class Definition {
|
|||||||
return Definition(name: definitionName)
|
return Definition(name: definitionName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasOneOrMoreMatchingTags(inputTags: [String]) -> Bool {
|
||||||
|
if Set(inputTags).intersection(Set(self.tags)).isEmpty {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: -
|
// MARK: -
|
||||||
|
|
||||||
private func getStringParameters(input: String) -> (inputParameters: [String], translationArguments: [String])? {
|
private func getStringParameters(input: String) -> (inputParameters: [String], translationArguments: [String])? {
|
||||||
|
@ -28,12 +28,12 @@ class Section {
|
|||||||
|
|
||||||
func hasOneOrMoreMatchingTags(tags: [String]) -> Bool {
|
func hasOneOrMoreMatchingTags(tags: [String]) -> Bool {
|
||||||
let allTags = definitions.flatMap { $0.tags }
|
let allTags = definitions.flatMap { $0.tags }
|
||||||
|
let allTagsSet = Set(allTags)
|
||||||
|
|
||||||
for tag in tags {
|
let intersection = Set(tags).intersection(allTagsSet)
|
||||||
if allTags.contains(tag) {
|
if intersection.isEmpty {
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user