DEVTOOLS-181 Gérer le tag noTranslation pour les xcstrings
This commit is contained in:
parent
27f86f5c4d
commit
fb2ddb2227
@ -9,7 +9,7 @@ import Foundation
|
|||||||
|
|
||||||
enum GenerateError: Error {
|
enum GenerateError: Error {
|
||||||
case fileNotExists(String)
|
case fileNotExists(String)
|
||||||
case invalidConfigurationFile(String)
|
case invalidConfigurationFile(String, String)
|
||||||
case commandError([String], String)
|
case commandError([String], String)
|
||||||
case writeFile(String, String)
|
case writeFile(String, String)
|
||||||
|
|
||||||
@ -18,8 +18,8 @@ enum GenerateError: Error {
|
|||||||
case .fileNotExists(let filename):
|
case .fileNotExists(let filename):
|
||||||
return "error: [\(Generate.toolName)] File \(filename) does not exists"
|
return "error: [\(Generate.toolName)] File \(filename) does not exists"
|
||||||
|
|
||||||
case .invalidConfigurationFile(let filename):
|
case .invalidConfigurationFile(let filename, let underneathErrorDescription):
|
||||||
return "error: [\(Generate.toolName)] File \(filename) is not a valid configuration file"
|
return "error: [\(Generate.toolName)] File \(filename) is not a valid configuration file. Underneath error: \(underneathErrorDescription)"
|
||||||
|
|
||||||
case .commandError(let command, let terminationStatus):
|
case .commandError(let command, let terminationStatus):
|
||||||
let readableCommand = command
|
let readableCommand = command
|
||||||
|
@ -16,12 +16,15 @@ class ConfigurationFileParser {
|
|||||||
Generate.exit(withError: error)
|
Generate.exit(withError: error)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let configuration = try? YAMLDecoder().decode(ConfigurationFile.self, from: data) else {
|
do {
|
||||||
let error = GenerateError.invalidConfigurationFile(configurationFile)
|
return try YAMLDecoder().decode(ConfigurationFile.self, from: data)
|
||||||
|
} catch {
|
||||||
|
let error = GenerateError.invalidConfigurationFile(
|
||||||
|
configurationFile,
|
||||||
|
error.localizedDescription.description
|
||||||
|
)
|
||||||
print(error.description)
|
print(error.description)
|
||||||
Generate.exit(withError: error)
|
Generate.exit(withError: error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return configuration
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,7 @@ class StringsFileGenerator {
|
|||||||
|
|
||||||
section.definitions.forEach { definition in
|
section.definitions.forEach { definition in
|
||||||
var skipDefinition = false
|
var skipDefinition = false
|
||||||
|
var isNoTranslation = false
|
||||||
|
|
||||||
var localizationTab: [XCStringLocalization] = []
|
var localizationTab: [XCStringLocalization] = []
|
||||||
|
|
||||||
@ -170,17 +171,37 @@ class StringsFileGenerator {
|
|||||||
skipDefinition = true
|
skipDefinition = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if definition.tags.contains(Stringium.noTranslationTag) {
|
||||||
|
isNoTranslation = true
|
||||||
|
}
|
||||||
|
|
||||||
if !skipDefinition {
|
if !skipDefinition {
|
||||||
for (lang, value) in definition.translations where !value.isEmpty {
|
if isNoTranslation {
|
||||||
|
// Search for langs in yaml
|
||||||
|
for lang in langs {
|
||||||
|
if let value = definition.translations[defaultLang], !value.isEmpty {
|
||||||
|
let localization = XCStringLocalization(
|
||||||
|
lang: lang,
|
||||||
|
content: XCStringLocalizationLangContent(
|
||||||
|
stringUnit: DefaultStringUnit(state: "translated", value: value)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
localizationTab.append(localization)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Search for langs in twine
|
||||||
|
for (lang, value) in definition.translations where !value.isEmpty {
|
||||||
|
|
||||||
let localization = XCStringLocalization(
|
let localization = XCStringLocalization(
|
||||||
lang: lang,
|
lang: lang,
|
||||||
content: XCStringLocalizationLangContent(
|
content: XCStringLocalizationLangContent(
|
||||||
stringUnit: DefaultStringUnit(state: "translated", value: value)
|
stringUnit: DefaultStringUnit(state: "translated", value: value)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
localizationTab.append(localization)
|
localizationTab.append(localization)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let xcStringDefinition = XCStringDefinition(
|
let xcStringDefinition = XCStringDefinition(
|
||||||
|
@ -53,17 +53,6 @@ struct Stringium: ParsableCommand {
|
|||||||
tags: options.tags,
|
tags: options.tags,
|
||||||
outputPath: options.stringsFileOutputPath,
|
outputPath: options.stringsFileOutputPath,
|
||||||
inputFilenameWithoutExt: options.inputFilenameWithoutExt)
|
inputFilenameWithoutExt: options.inputFilenameWithoutExt)
|
||||||
|
|
||||||
// Generate extension
|
|
||||||
StringsFileGenerator.writeExtensionFiles(sections: sections,
|
|
||||||
defaultLang: options.defaultLang,
|
|
||||||
tags: options.tags,
|
|
||||||
staticVar: options.staticMembers,
|
|
||||||
inputFilename: options.inputFilenameWithoutExt,
|
|
||||||
extensionName: options.extensionName,
|
|
||||||
extensionFilePath: options.extensionFilePath,
|
|
||||||
extensionSuffix: options.extensionSuffix)
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print("[\(Self.toolName)] Will generate xcStrings")
|
print("[\(Self.toolName)] Will generate xcStrings")
|
||||||
StringsFileGenerator.writeXcStringsFiles(sections: sections,
|
StringsFileGenerator.writeXcStringsFiles(sections: sections,
|
||||||
@ -74,6 +63,16 @@ struct Stringium: ParsableCommand {
|
|||||||
inputFilenameWithoutExt: options.inputFilenameWithoutExt)
|
inputFilenameWithoutExt: options.inputFilenameWithoutExt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate extension
|
||||||
|
StringsFileGenerator.writeExtensionFiles(sections: sections,
|
||||||
|
defaultLang: options.defaultLang,
|
||||||
|
tags: options.tags,
|
||||||
|
staticVar: options.staticMembers,
|
||||||
|
inputFilename: options.inputFilenameWithoutExt,
|
||||||
|
extensionName: options.extensionName,
|
||||||
|
extensionFilePath: options.extensionFilePath,
|
||||||
|
extensionSuffix: options.extensionSuffix)
|
||||||
|
|
||||||
print("[\(Self.toolName)] Strings generated")
|
print("[\(Self.toolName)] Strings generated")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ final class ParsedColorTests: XCTestCase {
|
|||||||
// When
|
// When
|
||||||
let contentJson = color.contentsJSON()
|
let contentJson = color.contentsJSON()
|
||||||
guard let data = contentJson.data(using: .utf8),
|
guard let data = contentJson.data(using: .utf8),
|
||||||
let parsedJson = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
|
let parsedJson = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
|
||||||
XCTFail("Cannot convert `contentJSON` string to Data")
|
XCTFail("Cannot convert `contentJSON` string to Data")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
// [s2_def_two]
|
// [s2_def_two]
|
||||||
// fr = Section Deux - Definition deux
|
// fr = Section Deux - Definition deux
|
||||||
// en = Section Two - Definition Two
|
// en = Section Two - Definition Two
|
||||||
// tags = ios,iosonly
|
// tags = notranslation
|
||||||
// comments =
|
// comments =
|
||||||
|
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
content: XCStringLocalizationLangContent(
|
content: XCStringLocalizationLangContent(
|
||||||
stringUnit: DefaultStringUnit(
|
stringUnit: DefaultStringUnit(
|
||||||
state: "translated",
|
state: "translated",
|
||||||
value: "Section Deux - Definition Deux"
|
value: "Section Two - Definition Two"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -372,82 +372,6 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
version: "1.0"
|
version: "1.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
// """
|
|
||||||
// {
|
|
||||||
// "sourceLanguage" : "en",
|
|
||||||
// "strings" : {
|
|
||||||
// "s1_def_one" : {
|
|
||||||
// "extractionState" : "manual",
|
|
||||||
// "localizations" : {
|
|
||||||
// "en" : {
|
|
||||||
// "stringUnit" : {
|
|
||||||
// "state" : "translated",
|
|
||||||
// "value" : "Section One - Definition One"
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "fr" : {
|
|
||||||
// "stringUnit" : {
|
|
||||||
// "state" : "translated",
|
|
||||||
// "value" : "Section Un - Definition Un"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "s1_def_two" : {
|
|
||||||
// "extractionState" : "manual",
|
|
||||||
// "localizations" : {
|
|
||||||
// "en" : {
|
|
||||||
// "stringUnit" : {
|
|
||||||
// "state" : "translated",
|
|
||||||
// "value" : "Section One - Definition Two"
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "fr" : {
|
|
||||||
// "stringUnit" : {
|
|
||||||
// "state" : "translated",
|
|
||||||
// "value" : "Section Un - Definition Deux"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "s2_def_one" : {
|
|
||||||
// "extractionState" : "manual",
|
|
||||||
// "localizations" : {
|
|
||||||
// "en" : {
|
|
||||||
// "stringUnit" : {
|
|
||||||
// "state" : "translated",
|
|
||||||
// "value" : "Section Two - Definition One"
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "fr" : {
|
|
||||||
// "stringUnit" : {
|
|
||||||
// "state" : "translated",
|
|
||||||
// "value" : "Section Deux - Definition Une"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "s2_def_two" : {
|
|
||||||
// "extractionState" : "manual",
|
|
||||||
// "localizations" : {
|
|
||||||
// "en" : {
|
|
||||||
// "stringUnit" : {
|
|
||||||
// "state" : "translated",
|
|
||||||
// "value" : "Section Two - Definition Two"
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "fr" : {
|
|
||||||
// "stringUnit" : {
|
|
||||||
// "state" : "translated",
|
|
||||||
// "value" : "Section Deux - Definition Deux"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// "version" : "1.0"
|
|
||||||
// }
|
|
||||||
// """
|
|
||||||
XCTAssertEqual(rootObject, expect)
|
XCTAssertEqual(rootObject, expect)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,8 +396,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
"en": "Section Two - Definition One"],
|
"en": "Section Two - Definition One"],
|
||||||
tags: ["ios","iosonly"]),
|
tags: ["ios","iosonly"]),
|
||||||
getDefinition(name: "s2_def_two",
|
getDefinition(name: "s2_def_two",
|
||||||
translations: ["fr": "Section Deux - Definition Deux",
|
translations: ["en": "Section Two - Definition Two"],
|
||||||
"en": "Section Two - Definition Two"],
|
|
||||||
tags: ["notranslation"])
|
tags: ["notranslation"])
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -504,9 +427,8 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
// tags = ios,iosonly
|
// tags = ios,iosonly
|
||||||
// comments =
|
// comments =
|
||||||
// [s2_def_two]
|
// [s2_def_two]
|
||||||
// fr = Section Deux - Definition deux
|
|
||||||
// en = Section Two - Definition Two
|
// en = Section Two - Definition Two
|
||||||
// tags = ios,iosonly
|
// tags = notranslation
|
||||||
// comments =
|
// comments =
|
||||||
|
|
||||||
// Expect
|
// Expect
|
||||||
@ -592,7 +514,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
content: XCStringLocalizationLangContent(
|
content: XCStringLocalizationLangContent(
|
||||||
stringUnit: DefaultStringUnit(
|
stringUnit: DefaultStringUnit(
|
||||||
state: "translated",
|
state: "translated",
|
||||||
value: "Section Deux - Definition Deux"
|
value: "Section Two - Definition Two"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -740,7 +662,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
// [s2_def_two]
|
// [s2_def_two]
|
||||||
// fr = Section Deux - Definition deux
|
// fr = Section Deux - Definition deux
|
||||||
// en = Section Two - Definition Two
|
// en = Section Two - Definition Two
|
||||||
// tags = ios,iosonly
|
// tags = notranslation
|
||||||
// comments =
|
// comments =
|
||||||
|
|
||||||
|
|
||||||
@ -765,15 +687,14 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
"en": "Section Two - Definition One"],
|
"en": "Section Two - Definition One"],
|
||||||
tags: ["ios","iosonly"]),
|
tags: ["ios","iosonly"]),
|
||||||
getDefinition(name: "s2_def_two",
|
getDefinition(name: "s2_def_two",
|
||||||
translations: ["fr": "Section Deux - Definition Deux",
|
translations: ["fr": "Section Deux - Definition Deux"],
|
||||||
"en": "Section Two - Definition Two"],
|
|
||||||
tags: ["notranslation"])
|
tags: ["notranslation"])
|
||||||
]
|
]
|
||||||
|
|
||||||
// When
|
// When
|
||||||
let rootObject = StringsFileGenerator.generateRootObject(
|
let rootObject = StringsFileGenerator.generateRootObject(
|
||||||
langs: ["fr", "en"],
|
langs: ["fr", "en"],
|
||||||
defaultLang: "en",
|
defaultLang: "fr",
|
||||||
tags: ["ios", "iosonly", "notranslation"],
|
tags: ["ios", "iosonly", "notranslation"],
|
||||||
sections: [sectionOne, sectionTwo]
|
sections: [sectionOne, sectionTwo]
|
||||||
)
|
)
|
||||||
@ -781,7 +702,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
// Expect
|
// Expect
|
||||||
let expect =
|
let expect =
|
||||||
Root(
|
Root(
|
||||||
sourceLanguage: "en",
|
sourceLanguage: "fr",
|
||||||
strings: XCStringDefinitionContainer(
|
strings: XCStringDefinitionContainer(
|
||||||
strings: [
|
strings: [
|
||||||
XCStringDefinition(
|
XCStringDefinition(
|
||||||
@ -881,7 +802,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
content: XCStringLocalizationLangContent(
|
content: XCStringLocalizationLangContent(
|
||||||
stringUnit: DefaultStringUnit(
|
stringUnit: DefaultStringUnit(
|
||||||
state: "translated",
|
state: "translated",
|
||||||
value: "Section Two - Definition Two"
|
value: "Section Deux - Definition Deux"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user