xcstrings #10

Merged
q.bandera merged 11 commits from xcstrings into master 2024-04-19 16:59:04 +02:00
3 changed files with 120 additions and 70 deletions
Showing only changes of commit 5d4e461933 - Show all commits

View File

@ -86,54 +86,28 @@ class Definition {
private func getBaseProperty(lang: String, translation: String, isStatic: Bool, comment: String?) -> String { private func getBaseProperty(lang: String, translation: String, isStatic: Bool, comment: String?) -> String {
if let comment, !comment.isEmpty {
return
""" """

On va simplifier et éviter la duplcation de la property. Mets toujours le commentaire :

/// Translation in \(lang) :
/// \(translation)
///
/// Comment:
/// \(comment?.isEmpty ? comment : "No comment")

et dans la property tu peux toujours mettre , comment: "\(comment ?? "")"

On va simplifier et éviter la duplcation de la property. Mets toujours le commentaire : ``` /// Translation in \(lang) : /// \(translation) /// /// Comment: /// \(comment?.isEmpty ? comment : "No comment") ``` et dans la property tu peux toujours mettre `, comment: "\(comment ?? "")"`
/// Translation in \(lang) : /// Translation in \(lang) :
/// \(translation) /// \(translation)
/// ///
/// Comment : /// Comment :
/// \(comment) /// \((comment ?? "").isEmpty ? "No comment" : comment!)
\(isStatic ? "static ": "")var \(name): String { \(isStatic ? "static ": "")var \(name): String {
NSLocalizedString("\(name)", tableName: kStringsFileName, bundle: Bundle.main, value: "\(translation)", comment: "\(comment)") NSLocalizedString("\(name)", tableName: kStringsFileName, bundle: Bundle.main, value: "\(translation)", comment: "\(comment ?? "")")
} }
""" """
}
return
"""
/// Translation in \(lang) :
/// \(translation)
\(isStatic ? "static ": "")var \(name): String {
NSLocalizedString("\(name)", tableName: kStringsFileName, bundle: Bundle.main, value: "\(translation)", comment: "")
}
"""
} }
private func getBaseMethod(lang: String, translation: String, isStatic: Bool, inputParameters: [String], translationArguments: [String], comment: String?) -> String { private func getBaseMethod(lang: String, translation: String, isStatic: Bool, inputParameters: [String], translationArguments: [String], comment: String?) -> String {
if let comment, !comment.isEmpty {
return
""" """
/// Translation in \(lang) : /// Translation in \(lang) :
/// \(translation) /// \(translation)
/// ///
/// Comment : /// Comment :
/// \(comment) /// \((comment ?? "").isEmpty ? "No comment" : comment!)
\(isStatic ? "static ": "")func \(name)(\(inputParameters.joined(separator: ", "))) -> String {
String(format: \(isStatic ? "Self" : "self").\(name), \(translationArguments.joined(separator: ", ")))
}
"""
}
return
"""
/// Translation in \(lang) :
/// \(translation)
\(isStatic ? "static ": "")func \(name)(\(inputParameters.joined(separator: ", "))) -> String { \(isStatic ? "static ": "")func \(name)(\(inputParameters.joined(separator: ", "))) -> String {
String(format: \(isStatic ? "Self" : "self").\(name), \(translationArguments.joined(separator: ", "))) String(format: \(isStatic ? "Self" : "self").\(name), \(translationArguments.joined(separator: ", ")))
} }
@ -207,13 +181,12 @@ class Definition {
Stringium.exit(withError: error) Stringium.exit(withError: error)
} }
if let comment, !comment.isEmpty {
return """ return """
/// Translation in \(lang) : /// Translation in \(lang) :
/// \(translation) /// \(translation)
/// ///
/// Comment : /// Comment :
/// \(comment) /// \((comment ?? "").isEmpty ? "No comment" : comment!)
var \(name): String { var \(name): String {
"\(translation)" "\(translation)"
@ -221,15 +194,6 @@ class Definition {
""" """
} }
return """
/// Translation in \(lang) :
/// \(translation)
var \(name): String {
"\(translation)"
}
"""
}
func getStaticProperty(forLang lang: String) -> String { func getStaticProperty(forLang lang: String) -> String {
guard let translation = translations[lang] else { guard let translation = translations[lang] else {
let error = StringiumError.langNotDefined(lang, name, reference != nil) let error = StringiumError.langNotDefined(lang, name, reference != nil)
@ -237,22 +201,12 @@ class Definition {
Stringium.exit(withError: error) Stringium.exit(withError: error)
} }
if let comment, !comment.isEmpty {
return """ return """
/// Translation in \(lang) : /// Translation in \(lang) :
/// \(translation) /// \(translation)
/// ///
/// Comment : /// Comment :
/// \(comment) /// \((comment ?? "").isEmpty ? "No comment" : comment!)
static var \(name): String {
"\(translation)"
}
"""
}
return """
/// Translation in \(lang) :
/// \(translation)
static var \(name): String { static var \(name): String {
"\(translation)" "\(translation)"
} }

View File

@ -155,6 +155,9 @@ final class DefinitionTests: XCTestCase {
let expectFr = """ let expectFr = """
/// Translation in fr : /// Translation in fr :
/// C'est la traduction francaise /// C'est la traduction francaise
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "")
} }
@ -163,6 +166,9 @@ final class DefinitionTests: XCTestCase {
let expectEn = """ let expectEn = """
/// Translation in en : /// Translation in en :
/// This is the english translation /// This is the english translation
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "")
} }
@ -171,6 +177,9 @@ final class DefinitionTests: XCTestCase {
let expectEnUs = """ let expectEnUs = """
/// Translation in en-us : /// Translation in en-us :
/// This is the english us translation /// This is the english us translation
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
} }
@ -200,6 +209,9 @@ final class DefinitionTests: XCTestCase {
let expectFr = """ let expectFr = """
/// Translation in fr : /// Translation in fr :
/// C'est la traduction francaise /// C'est la traduction francaise
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "")
} }
@ -208,6 +220,9 @@ final class DefinitionTests: XCTestCase {
let expectEn = """ let expectEn = """
/// Translation in en : /// Translation in en :
/// This is the english translation /// This is the english translation
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "")
} }
@ -216,6 +231,9 @@ final class DefinitionTests: XCTestCase {
let expectEnUs = """ let expectEnUs = """
/// Translation in en-us : /// Translation in en-us :
/// This is the english us translation /// This is the english us translation
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
} }
@ -303,6 +321,9 @@ final class DefinitionTests: XCTestCase {
let expectFr = """ let expectFr = """
/// Translation in fr : /// Translation in fr :
/// C'est la traduction francaise /// C'est la traduction francaise
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "")
} }
@ -311,6 +332,9 @@ final class DefinitionTests: XCTestCase {
let expectEn = """ let expectEn = """
/// Translation in en : /// Translation in en :
/// This is the english translation /// This is the english translation
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "")
} }
@ -319,6 +343,9 @@ final class DefinitionTests: XCTestCase {
let expectEnUs = """ let expectEnUs = """
/// Translation in en-us : /// Translation in en-us :
/// This is the english us translation /// This is the english us translation
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
} }
@ -348,6 +375,9 @@ final class DefinitionTests: XCTestCase {
let expectFr = """ let expectFr = """
/// Translation in fr : /// Translation in fr :
/// C'est la traduction francaise /// C'est la traduction francaise
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "C'est la traduction francaise", comment: "")
} }
@ -356,6 +386,9 @@ final class DefinitionTests: XCTestCase {
let expectEn = """ let expectEn = """
/// Translation in en : /// Translation in en :
/// This is the english translation /// This is the english translation
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english translation", comment: "")
} }
@ -364,6 +397,9 @@ final class DefinitionTests: XCTestCase {
let expectEnUs = """ let expectEnUs = """
/// Translation in en-us : /// Translation in en-us :
/// This is the english us translation /// This is the english us translation
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "") NSLocalizedString("definition_name", tableName: kStringsFileName, bundle: Bundle.main, value: "This is the english us translation", comment: "")
} }
@ -581,6 +617,9 @@ final class DefinitionTests: XCTestCase {
let expectFr = """ let expectFr = """
/// Translation in fr : /// Translation in fr :
/// C'est la traduction francaise /// C'est la traduction francaise
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
"C'est la traduction francaise" "C'est la traduction francaise"
} }
@ -589,6 +628,9 @@ final class DefinitionTests: XCTestCase {
let expectEn = """ let expectEn = """
/// Translation in en : /// Translation in en :
/// This is the english translation /// This is the english translation
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
"This is the english translation" "This is the english translation"
} }
@ -597,6 +639,9 @@ final class DefinitionTests: XCTestCase {
let expectEnUs = """ let expectEnUs = """
/// Translation in en-us : /// Translation in en-us :
/// This is the english us translation /// This is the english us translation
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
"This is the english us translation" "This is the english us translation"
} }
@ -626,6 +671,9 @@ final class DefinitionTests: XCTestCase {
let expectFr = """ let expectFr = """
/// Translation in fr : /// Translation in fr :
/// C'est la traduction francaise /// C'est la traduction francaise
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
"C'est la traduction francaise" "C'est la traduction francaise"
} }
@ -634,6 +682,9 @@ final class DefinitionTests: XCTestCase {
let expectEn = """ let expectEn = """
/// Translation in en : /// Translation in en :
/// This is the english translation /// This is the english translation
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
"This is the english translation" "This is the english translation"
} }
@ -642,6 +693,9 @@ final class DefinitionTests: XCTestCase {
let expectEnUs = """ let expectEnUs = """
/// Translation in en-us : /// Translation in en-us :
/// This is the english us translation /// This is the english us translation
///
/// Comment :
/// No comment
var definition_name: String { var definition_name: String {
"This is the english us translation" "This is the english us translation"
} }
@ -729,6 +783,9 @@ final class DefinitionTests: XCTestCase {
let expectFr = """ let expectFr = """
/// Translation in fr : /// Translation in fr :
/// C'est la traduction francaise /// C'est la traduction francaise
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
"C'est la traduction francaise" "C'est la traduction francaise"
} }
@ -737,6 +794,9 @@ final class DefinitionTests: XCTestCase {
let expectEn = """ let expectEn = """
/// Translation in en : /// Translation in en :
/// This is the english translation /// This is the english translation
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
"This is the english translation" "This is the english translation"
} }
@ -745,6 +805,9 @@ final class DefinitionTests: XCTestCase {
let expectEnUs = """ let expectEnUs = """
/// Translation in en-us : /// Translation in en-us :
/// This is the english us translation /// This is the english us translation
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
"This is the english us translation" "This is the english us translation"
} }
@ -774,6 +837,9 @@ final class DefinitionTests: XCTestCase {
let expectFr = """ let expectFr = """
/// Translation in fr : /// Translation in fr :
/// C'est la traduction francaise /// C'est la traduction francaise
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
"C'est la traduction francaise" "C'est la traduction francaise"
} }
@ -782,6 +848,9 @@ final class DefinitionTests: XCTestCase {
let expectEn = """ let expectEn = """
/// Translation in en : /// Translation in en :
/// This is the english translation /// This is the english translation
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
"This is the english translation" "This is the english translation"
} }
@ -790,6 +859,9 @@ final class DefinitionTests: XCTestCase {
let expectEnUs = """ let expectEnUs = """
/// Translation in en-us : /// Translation in en-us :
/// This is the english us translation /// This is the english us translation
///
/// Comment :
/// No comment
static var definition_name: String { static var definition_name: String {
"This is the english us translation" "This is the english us translation"
} }

View File

@ -252,12 +252,18 @@ final class StringsFileGeneratorTests: XCTestCase {
/// Translation in fr : /// Translation in fr :
/// Section Un - Definition Un /// Section Un - Definition Un
///
/// Comment :
/// No comment
var s1_def_one: String { var s1_def_one: String {
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "") NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "")
} }
/// Translation in fr : /// Translation in fr :
/// Section Un - Definition Deux /// Section Un - Definition Deux
///
/// Comment :
/// No comment
var s1_def_two: String { var s1_def_two: String {
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "") NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "")
} }
@ -266,12 +272,18 @@ final class StringsFileGeneratorTests: XCTestCase {
/// Translation in fr : /// Translation in fr :
/// Section Deux - Definition Un /// Section Deux - Definition Un
///
/// Comment :
/// No comment
var s2_def_one: String { var s2_def_one: String {
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "") NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "")
} }
/// Translation in fr : /// Translation in fr :
/// Section Deux - Definition Deux /// Section Deux - Definition Deux
///
/// Comment :
/// No comment
var s2_def_two: String { var s2_def_two: String {
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "") NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "")
} }
@ -461,12 +473,18 @@ final class StringsFileGeneratorTests: XCTestCase {
/// Translation in fr : /// Translation in fr :
/// Section Un - Definition Un /// Section Un - Definition Un
///
/// Comment :
/// No comment
static var s1_def_one: String { static var s1_def_one: String {
NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "") NSLocalizedString("s1_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Un", comment: "")
} }
/// Translation in fr : /// Translation in fr :
/// Section Un - Definition Deux /// Section Un - Definition Deux
///
/// Comment :
/// No comment
static var s1_def_two: String { static var s1_def_two: String {
NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "") NSLocalizedString("s1_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Un - Definition Deux", comment: "")
} }
@ -475,12 +493,18 @@ final class StringsFileGeneratorTests: XCTestCase {
/// Translation in fr : /// Translation in fr :
/// Section Deux - Definition Un /// Section Deux - Definition Un
///
/// Comment :
/// No comment
static var s2_def_one: String { static var s2_def_one: String {
NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "") NSLocalizedString("s2_def_one", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Un", comment: "")
} }
/// Translation in fr : /// Translation in fr :
/// Section Deux - Definition Deux /// Section Deux - Definition Deux
///
/// Comment :
/// No comment
static var s2_def_two: String { static var s2_def_two: String {
NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "") NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "")
} }