Première implémentation des xcstrings
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
//
|
||||
// StringsFileGeneratorTests.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by Thibaut Schmitt on 06/09/2022.
|
||||
//
|
||||
@ -12,7 +12,7 @@ import ToolCore
|
||||
@testable import ResgenSwift
|
||||
|
||||
final class StringsFileGeneratorTests: XCTestCase {
|
||||
|
||||
|
||||
private func getDefinition(name: String, translations: [String: String], tags: [String], comment: String? = nil) -> Definition {
|
||||
let definition = Definition(name: name)
|
||||
definition.tags = tags
|
||||
@ -36,7 +36,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
"en": "Section One - Definition Two"],
|
||||
tags: ["ios","iosonly"])
|
||||
]
|
||||
|
||||
|
||||
let sectionTwo = Section(name: "section_two")
|
||||
sectionTwo.definitions = [
|
||||
getDefinition(name: "s2_def_one",
|
||||
@ -47,7 +47,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"])
|
||||
]
|
||||
|
||||
|
||||
// When
|
||||
let stringsFileContentFr = StringsFileGenerator.generateStringsFileContent(lang: "fr",
|
||||
defaultLang: "fr",
|
||||
@ -57,7 +57,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
defaultLang: "fr",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
sections: [sectionOne, sectionTwo])
|
||||
|
||||
|
||||
// Expect
|
||||
let expectFr = """
|
||||
/**
|
||||
@ -65,40 +65,40 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
* Generated by ResgenSwift \(ResgenSwiftVersion)
|
||||
* Language: fr
|
||||
*/
|
||||
|
||||
|
||||
/********** section_one **********/
|
||||
|
||||
|
||||
"s1_def_one" = "Section Un - Definition Un";
|
||||
|
||||
|
||||
"s1_def_two" = "Section Un - Definition Deux";
|
||||
|
||||
|
||||
/********** section_two **********/
|
||||
|
||||
|
||||
"s2_def_one" = "Section Deux - Definition Un";
|
||||
|
||||
"s2_def_two" = "Section Deux - Definition Deux";
|
||||
"""
|
||||
|
||||
|
||||
let expectEn = """
|
||||
/**
|
||||
* Apple Strings File
|
||||
* Generated by ResgenSwift \(ResgenSwiftVersion)
|
||||
* Language: en
|
||||
*/
|
||||
|
||||
|
||||
/********** section_one **********/
|
||||
|
||||
|
||||
"s1_def_one" = "Section One - Definition One";
|
||||
|
||||
|
||||
"s1_def_two" = "Section One - Definition Two";
|
||||
|
||||
|
||||
/********** section_two **********/
|
||||
|
||||
|
||||
"s2_def_one" = "Section Two - Definition One";
|
||||
|
||||
"s2_def_two" = "Section Deux - Definition Deux";
|
||||
"""
|
||||
|
||||
|
||||
XCTAssertEqual(stringsFileContentFr.adaptForXCTest(), expectFr.adaptForXCTest())
|
||||
XCTAssertEqual(stringsFileContentEn.adaptForXCTest(), expectEn.adaptForXCTest())
|
||||
}
|
||||
@ -187,6 +187,268 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
XCTAssertEqual(stringsFileContentEn.adaptForXCTest(), expectEn.adaptForXCTest())
|
||||
}
|
||||
|
||||
// MARK: - XcString File Content
|
||||
|
||||
func testGenerateXcStringsRootObject() {
|
||||
// Given
|
||||
let sectionOne = Section(name: "section_one")
|
||||
sectionOne.definitions = [
|
||||
getDefinition(name: "s1_def_one",
|
||||
translations: ["fr": "Section Un - Definition Un",
|
||||
"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": "Section Deux - Definition Un",
|
||||
"en": "Section Two - Definition One"],
|
||||
tags: ["ios","iosonly"]),
|
||||
getDefinition(name: "s2_def_two",
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"])
|
||||
]
|
||||
|
||||
// When
|
||||
let rootObject = StringsFileGenerator.generateRootObject(
|
||||
langs: ["fr", "en"],
|
||||
defaultLang: "en",
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
sections: [sectionOne, sectionTwo]
|
||||
)
|
||||
|
||||
// [[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 =
|
||||
|
||||
// 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 Two - 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"
|
||||
// }
|
||||
// """
|
||||
|
||||
XCTAssertEqual(rootObject, expect)
|
||||
}
|
||||
|
||||
// MARK: - Extension Content
|
||||
func testGeneratedExtensionContent() {
|
||||
// Given
|
||||
@ -201,7 +463,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
"en": "Section One - Definition Two"],
|
||||
tags: ["ios","iosonly"])
|
||||
]
|
||||
|
||||
|
||||
let sectionTwo = Section(name: "section_two")
|
||||
sectionTwo.definitions = [
|
||||
getDefinition(name: "s2_def_one",
|
||||
@ -212,7 +474,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"])
|
||||
]
|
||||
|
||||
|
||||
// When
|
||||
let extensionContent = StringsFileGenerator.getExtensionContent(sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
@ -221,23 +483,23 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings")
|
||||
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Strings.Stringium \(ResgenSwiftVersion)
|
||||
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
fileprivate let kStringsFileName = "myInputFilename"
|
||||
|
||||
|
||||
extension GenStrings {
|
||||
|
||||
|
||||
enum KeyStrings: String {
|
||||
case s1_def_one = "s1_def_one"
|
||||
case s1_def_two = "s1_def_two"
|
||||
case s2_def_one = "s2_def_one"
|
||||
case s2_def_two = "s2_def_two"
|
||||
|
||||
|
||||
var keyPath: KeyPath<GenStrings, String> {
|
||||
switch self {
|
||||
case .s1_def_one: return \\GenStrings.s1_def_one
|
||||
@ -247,9 +509,9 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - section_one
|
||||
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Un
|
||||
///
|
||||
@ -258,7 +520,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
var s1_def_one: String {
|
||||
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "")
|
||||
}
|
||||
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Deux
|
||||
///
|
||||
@ -267,9 +529,9 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
var s1_def_two: String {
|
||||
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "")
|
||||
}
|
||||
|
||||
|
||||
// MARK: - section_two
|
||||
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Un
|
||||
///
|
||||
@ -278,7 +540,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
var s2_def_one: String {
|
||||
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "")
|
||||
}
|
||||
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Deux
|
||||
///
|
||||
@ -289,7 +551,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
if extensionContent != expect {
|
||||
print(prettyFirstDifferenceBetweenStrings(s1: extensionContent, s2: expect))
|
||||
}
|
||||
@ -422,7 +684,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
"en": "Section One - Definition Two"],
|
||||
tags: ["ios","iosonly"])
|
||||
]
|
||||
|
||||
|
||||
let sectionTwo = Section(name: "section_two")
|
||||
sectionTwo.definitions = [
|
||||
getDefinition(name: "s2_def_one",
|
||||
@ -433,7 +695,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
translations: ["fr": "Section Deux - Definition Deux"],
|
||||
tags: ["notranslation"])
|
||||
]
|
||||
|
||||
|
||||
// When
|
||||
let extensionContent = StringsFileGenerator.getExtensionContent(sections: [sectionOne, sectionTwo],
|
||||
defaultLang: "fr",
|
||||
@ -442,23 +704,23 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings")
|
||||
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
// Generated by ResgenSwift.Strings.Stringium \(ResgenSwiftVersion)
|
||||
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
fileprivate let kStringsFileName = "myInputFilename"
|
||||
|
||||
|
||||
extension GenStrings {
|
||||
|
||||
|
||||
enum KeyStrings: String {
|
||||
case s1_def_one = "s1_def_one"
|
||||
case s1_def_two = "s1_def_two"
|
||||
case s2_def_one = "s2_def_one"
|
||||
case s2_def_two = "s2_def_two"
|
||||
|
||||
|
||||
var keyPath: KeyPath<GenStrings, String> {
|
||||
switch self {
|
||||
case .s1_def_one: return \\GenStrings.s1_def_one
|
||||
@ -468,9 +730,9 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - section_one
|
||||
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Un
|
||||
///
|
||||
@ -479,7 +741,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
static var s1_def_one: String {
|
||||
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "")
|
||||
}
|
||||
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Un - Definition Deux
|
||||
///
|
||||
@ -488,9 +750,9 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
static var s1_def_two: String {
|
||||
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "")
|
||||
}
|
||||
|
||||
|
||||
// MARK: - section_two
|
||||
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Un
|
||||
///
|
||||
@ -499,7 +761,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
static var s2_def_one: String {
|
||||
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "")
|
||||
}
|
||||
|
||||
|
||||
/// Translation in fr :
|
||||
/// Section Deux - Definition Deux
|
||||
///
|
||||
@ -510,7 +772,7 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
if extensionContent != expect {
|
||||
print(prettyFirstDifferenceBetweenStrings(s1: extensionContent, s2: expect))
|
||||
}
|
||||
|
Reference in New Issue
Block a user