xcstrings #10
@ -166,7 +166,6 @@ class StringsFileGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !skipDefinition {
|
if !skipDefinition {
|
||||||
|
|
||||||
for (lang, value) in definition.translations {
|
for (lang, value) in definition.translations {
|
||||||
let localization = XCStringLocalization(
|
let localization = XCStringLocalization(
|
||||||
lang: lang,
|
lang: lang,
|
||||||
|
@ -191,6 +191,32 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
|
|
||||||
func testGenerateXcStringsRootObject() {
|
func testGenerateXcStringsRootObject() {
|
||||||
// Given
|
// Given
|
||||||
|
|
||||||
|
// [[section_one]]
|
||||||
|
// [s1_def_one]
|
||||||
|
// fr = Section Un - Definition Un
|
||||||
|
// en = Section One - Definition One
|
||||||
|
// tags = ios,iosonly
|
||||||
|
// comments =
|
||||||
|
// [s1_def_two]
|
||||||
|
// fr = Section Un - Definition Deux
|
||||||
|
// en = Section One - Definition Two
|
||||||
|
// tags = ios,iosonly
|
||||||
|
// comments =
|
||||||
|
//
|
||||||
|
// [[section_two]
|
||||||
|
// [s2_def_one]
|
||||||
|
// fr = Section Deux - Definition Un
|
||||||
|
// en = Section Two - Definition One
|
||||||
|
// tags = ios,iosonly
|
||||||
|
// comments =
|
||||||
|
// [s2_def_two]
|
||||||
|
// fr = Section Deux - Definition deux
|
||||||
|
// en = Section Two - Definition Two
|
||||||
|
// tags = ios,iosonly
|
||||||
|
// comments =
|
||||||
|
|
||||||
|
|
||||||
let sectionOne = Section(name: "section_one")
|
let sectionOne = Section(name: "section_one")
|
||||||
sectionOne.definitions = [
|
sectionOne.definitions = [
|
||||||
getDefinition(name: "s1_def_one",
|
getDefinition(name: "s1_def_one",
|
||||||
@ -209,6 +235,245 @@ final class StringsFileGeneratorTests: XCTestCase {
|
|||||||
translations: ["fr": "Section Deux - Definition Un",
|
translations: ["fr": "Section Deux - Definition Un",
|
||||||
"en": "Section Two - Definition One"],
|
"en": "Section Two - Definition One"],
|
||||||
tags: ["ios","iosonly"]),
|
tags: ["ios","iosonly"]),
|
||||||
|
getDefinition(name: "s2_def_two",
|
||||||
|
translations: ["fr": "Section Deux - Definition Deux",
|
||||||
|
"en": "Section Two - Definition Two"],
|
||||||
|
tags: ["notranslation"])
|
||||||
|
]
|
||||||
|
|
||||||
|
// When
|
||||||
|
let rootObject = StringsFileGenerator.generateRootObject(
|
||||||
|
langs: ["fr", "en"],
|
||||||
|
defaultLang: "en",
|
||||||
|
tags: ["ios", "iosonly", "notranslation"],
|
||||||
|
sections: [sectionOne, sectionTwo]
|
||||||
|
)
|
||||||
|
|
||||||
|
// Expect
|
||||||
|
let expect =
|
||||||
|
Root(
|
||||||
|
sourceLanguage: "en",
|
||||||
|
strings: XCStringDefinitionContainer(
|
||||||
|
strings: [
|
||||||
|
XCStringDefinition(
|
||||||
|
title: "s1_def_one",
|
||||||
|
content: XCStringDefinitionContent(
|
||||||
|
extractionState: "manual",
|
||||||
|
localizations: XCStringLocalizationContainer(
|
||||||
|
localizations: [
|
||||||
|
XCStringLocalization(
|
||||||
|
lang: "en",
|
||||||
|
content: XCStringLocalizationLangContent(
|
||||||
|
stringUnit: DefaultStringUnit(
|
||||||
|
state: "translated",
|
||||||
|
value: "Section One - Definition One"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
XCStringLocalization(
|
||||||
|
lang: "fr",
|
||||||
|
content: XCStringLocalizationLangContent(
|
||||||
|
stringUnit: DefaultStringUnit(
|
||||||
|
state: "translated",
|
||||||
|
value: "Section Un - Definition Un"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
XCStringDefinition(
|
||||||
|
title: "s1_def_two",
|
||||||
|
content: XCStringDefinitionContent(
|
||||||
|
extractionState: "manual",
|
||||||
|
localizations: XCStringLocalizationContainer(
|
||||||
|
localizations: [
|
||||||
|
XCStringLocalization(
|
||||||
|
lang: "en",
|
||||||
|
content: XCStringLocalizationLangContent(
|
||||||
|
stringUnit: DefaultStringUnit(
|
||||||
|
state: "translated",
|
||||||
|
value: "Section One - Definition Two"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
XCStringLocalization(
|
||||||
|
lang: "fr",
|
||||||
|
content: XCStringLocalizationLangContent(
|
||||||
|
stringUnit: DefaultStringUnit(
|
||||||
|
state: "translated",
|
||||||
|
value: "Section Un - Definition Deux"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
XCStringDefinition(
|
||||||
|
title: "s2_def_one",
|
||||||
|
content: XCStringDefinitionContent(
|
||||||
|
extractionState: "manual",
|
||||||
|
localizations: XCStringLocalizationContainer(
|
||||||
|
localizations: [
|
||||||
|
XCStringLocalization(
|
||||||
|
lang: "en",
|
||||||
|
content: XCStringLocalizationLangContent(
|
||||||
|
stringUnit: DefaultStringUnit(
|
||||||
|
state: "translated",
|
||||||
|
value: "Section Two - Definition One"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
XCStringLocalization(
|
||||||
|
lang: "fr",
|
||||||
|
content: XCStringLocalizationLangContent(
|
||||||
|
stringUnit: DefaultStringUnit(
|
||||||
|
state: "translated",
|
||||||
|
value: "Section Deux - Definition Un"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
XCStringDefinition(
|
||||||
|
title: "s2_def_two",
|
||||||
|
content: XCStringDefinitionContent(
|
||||||
|
extractionState: "manual",
|
||||||
|
localizations: XCStringLocalizationContainer(
|
||||||
|
localizations: [
|
||||||
|
XCStringLocalization(
|
||||||
|
lang: "en",
|
||||||
|
content: XCStringLocalizationLangContent(
|
||||||
|
stringUnit: DefaultStringUnit(
|
||||||
|
state: "translated",
|
||||||
|
value: "Section Two - Definition Two"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
XCStringLocalization(
|
||||||
|
lang: "fr",
|
||||||
|
content: XCStringLocalizationLangContent(
|
||||||
|
stringUnit: DefaultStringUnit(
|
||||||
|
state: "translated",
|
||||||
|
value: "Section Deux - Definition Deux"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
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"
|
||||||
|
// }
|
||||||
|
// """
|
||||||
|
debugPrint(rootObject)
|
||||||
|
debugPrint(expect)
|
||||||
|
|
||||||
|
XCTAssertEqual(rootObject, expect)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGenerateXcStringsRootObjectWithEmptyTranslations() {
|
||||||
|
// Given
|
||||||
|
let sectionOne = Section(name: "section_one")
|
||||||
|
sectionOne.definitions = [
|
||||||
|
getDefinition(name: "s1_def_one",
|
||||||
|
translations: ["fr": "",
|
||||||
|
"en": "Section One - Definition One"],
|
||||||
|
tags: ["ios","iosonly"]),
|
||||||
|
getDefinition(name: "s1_def_two",
|
||||||
|
translations: ["fr": "Section Un - Definition Deux",
|
||||||
|
"en": "Section One - Definition Two"],
|
||||||
|
tags: ["ios","iosonly"])
|
||||||
|
]
|
||||||
|
|
||||||
|
let sectionTwo = Section(name: "section_two")
|
||||||
|
sectionTwo.definitions = [
|
||||||
|
getDefinition(name: "s2_def_one",
|
||||||
|
translations: ["fr": "",
|
||||||
|
"en": "Section Two - Definition One"],
|
||||||
|
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"],
|
||||||
tags: ["notranslation"])
|
tags: ["notranslation"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user