xcstrings #10

Merged
q.bandera merged 11 commits from xcstrings into master 2024-04-19 16:59:04 +02:00
2 changed files with 265 additions and 1 deletions
Showing only changes of commit 6c3f3a8982 - Show all commits

View File

@ -166,7 +166,6 @@ class StringsFileGenerator {
}
if !skipDefinition {
for (lang, value) in definition.translations {
let localization = XCStringLocalization(
lang: lang,

View File

@ -191,6 +191,32 @@ final class StringsFileGeneratorTests: XCTestCase {
func testGenerateXcStringsRootObject() {
// 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")
sectionOne.definitions = [
getDefinition(name: "s1_def_one",
@ -209,6 +235,245 @@ final class StringsFileGeneratorTests: XCTestCase {
translations: ["fr": "Section Deux - Definition Un",
"en": "Section Two - Definition One"],
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",
translations: ["fr": "Section Deux - Definition Deux"],
tags: ["notranslation"])