diff --git a/Sources/ResgenSwift/Strings/Model/Definition.swift b/Sources/ResgenSwift/Strings/Model/Definition.swift index 380bde0..d985e34 100644 --- a/Sources/ResgenSwift/Strings/Model/Definition.swift +++ b/Sources/ResgenSwift/Strings/Model/Definition.swift @@ -86,58 +86,32 @@ class Definition { private func getBaseProperty(lang: String, translation: String, isStatic: Bool, comment: String?) -> String { - if let comment, !comment.isEmpty { - return - """ - /// Translation in \(lang) : - /// \(translation) - /// - /// Comment : - /// \(comment) - \(isStatic ? "static ": "")var \(name): String { - NSLocalizedString("\(name)", tableName: kStringsFileName, bundle: Bundle.main, value: "\(translation)", comment: "\(comment)") - } - """ - } + """ + /// Translation in \(lang) : + /// \(translation) + /// + /// Comment : + /// \((comment ?? "").isEmpty ? "No comment" : comment!) + \(isStatic ? "static ": "")var \(name): String { + 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 { - if let comment, !comment.isEmpty { - return - """ + """ - - /// Translation in \(lang) : - /// \(translation) - /// - /// 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 { - String(format: \(isStatic ? "Self" : "self").\(name), \(translationArguments.joined(separator: ", "))) - } - """ + /// Translation in \(lang) : + /// \(translation) + /// + /// Comment : + /// \((comment ?? "").isEmpty ? "No comment" : comment!) + \(isStatic ? "static ": "")func \(name)(\(inputParameters.joined(separator: ", "))) -> String { + String(format: \(isStatic ? "Self" : "self").\(name), \(translationArguments.joined(separator: ", "))) + } + """ } func getNSLocalizedStringProperty(forLang lang: String) -> String { @@ -207,27 +181,17 @@ class Definition { Stringium.exit(withError: error) } - if let comment, !comment.isEmpty { - return """ + return """ /// Translation in \(lang) : /// \(translation) /// /// Comment : - /// \(comment) + /// \((comment ?? "").isEmpty ? "No comment" : comment!) var \(name): String { "\(translation)" } """ - } - - return """ - /// Translation in \(lang) : - /// \(translation) - var \(name): String { - "\(translation)" - } - """ } func getStaticProperty(forLang lang: String) -> String { @@ -237,22 +201,12 @@ class Definition { Stringium.exit(withError: error) } - if let comment, !comment.isEmpty { - return """ + return """ /// Translation in \(lang) : /// \(translation) /// /// Comment : - /// \(comment) - static var \(name): String { - "\(translation)" - } - """ - } - - return """ - /// Translation in \(lang) : - /// \(translation) + /// \((comment ?? "").isEmpty ? "No comment" : comment!) static var \(name): String { "\(translation)" } diff --git a/Tests/ResgenSwiftTests/Strings/DefinitionTests.swift b/Tests/ResgenSwiftTests/Strings/DefinitionTests.swift index 9d477a3..c25b3ff 100644 --- a/Tests/ResgenSwiftTests/Strings/DefinitionTests.swift +++ b/Tests/ResgenSwiftTests/Strings/DefinitionTests.swift @@ -155,6 +155,9 @@ final class DefinitionTests: XCTestCase { let expectFr = """ /// Translation in fr : /// C'est la traduction francaise + /// + /// Comment : + /// No comment var definition_name: String { 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 = """ /// Translation in en : /// This is the english translation + /// + /// Comment : + /// No comment var definition_name: String { 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 = """ /// Translation in en-us : /// This is the english us translation + /// + /// Comment : + /// No comment var definition_name: String { 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 = """ /// Translation in fr : /// C'est la traduction francaise + /// + /// Comment : + /// No comment var definition_name: String { 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 = """ /// Translation in en : /// This is the english translation + /// + /// Comment : + /// No comment var definition_name: String { 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 = """ /// Translation in en-us : /// This is the english us translation + /// + /// Comment : + /// No comment var definition_name: String { 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 = """ /// Translation in fr : /// C'est la traduction francaise + /// + /// Comment : + /// No comment static var definition_name: String { 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 = """ /// Translation in en : /// This is the english translation + /// + /// Comment : + /// No comment static var definition_name: String { 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 = """ /// Translation in en-us : /// This is the english us translation + /// + /// Comment : + /// No comment static var definition_name: String { 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 = """ /// Translation in fr : /// C'est la traduction francaise + /// + /// Comment : + /// No comment static var definition_name: String { 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 = """ /// Translation in en : /// This is the english translation + /// + /// Comment : + /// No comment static var definition_name: String { 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 = """ /// Translation in en-us : /// This is the english us translation + /// + /// Comment : + /// No comment static var definition_name: String { 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 = """ /// Translation in fr : /// C'est la traduction francaise + /// + /// Comment : + /// No comment var definition_name: String { "C'est la traduction francaise" } @@ -589,6 +628,9 @@ final class DefinitionTests: XCTestCase { let expectEn = """ /// Translation in en : /// This is the english translation + /// + /// Comment : + /// No comment var definition_name: String { "This is the english translation" } @@ -597,6 +639,9 @@ final class DefinitionTests: XCTestCase { let expectEnUs = """ /// Translation in en-us : /// This is the english us translation + /// + /// Comment : + /// No comment var definition_name: String { "This is the english us translation" } @@ -626,6 +671,9 @@ final class DefinitionTests: XCTestCase { let expectFr = """ /// Translation in fr : /// C'est la traduction francaise + /// + /// Comment : + /// No comment var definition_name: String { "C'est la traduction francaise" } @@ -634,6 +682,9 @@ final class DefinitionTests: XCTestCase { let expectEn = """ /// Translation in en : /// This is the english translation + /// + /// Comment : + /// No comment var definition_name: String { "This is the english translation" } @@ -642,6 +693,9 @@ final class DefinitionTests: XCTestCase { let expectEnUs = """ /// Translation in en-us : /// This is the english us translation + /// + /// Comment : + /// No comment var definition_name: String { "This is the english us translation" } @@ -729,6 +783,9 @@ final class DefinitionTests: XCTestCase { let expectFr = """ /// Translation in fr : /// C'est la traduction francaise + /// + /// Comment : + /// No comment static var definition_name: String { "C'est la traduction francaise" } @@ -737,6 +794,9 @@ final class DefinitionTests: XCTestCase { let expectEn = """ /// Translation in en : /// This is the english translation + /// + /// Comment : + /// No comment static var definition_name: String { "This is the english translation" } @@ -745,6 +805,9 @@ final class DefinitionTests: XCTestCase { let expectEnUs = """ /// Translation in en-us : /// This is the english us translation + /// + /// Comment : + /// No comment static var definition_name: String { "This is the english us translation" } @@ -774,6 +837,9 @@ final class DefinitionTests: XCTestCase { let expectFr = """ /// Translation in fr : /// C'est la traduction francaise + /// + /// Comment : + /// No comment static var definition_name: String { "C'est la traduction francaise" } @@ -782,6 +848,9 @@ final class DefinitionTests: XCTestCase { let expectEn = """ /// Translation in en : /// This is the english translation + /// + /// Comment : + /// No comment static var definition_name: String { "This is the english translation" } @@ -790,6 +859,9 @@ final class DefinitionTests: XCTestCase { let expectEnUs = """ /// Translation in en-us : /// This is the english us translation + /// + /// Comment : + /// No comment static var definition_name: String { "This is the english us translation" } diff --git a/Tests/ResgenSwiftTests/Strings/StringsFileGeneratorTests.swift b/Tests/ResgenSwiftTests/Strings/StringsFileGeneratorTests.swift index 747d14e..2456d44 100644 --- a/Tests/ResgenSwiftTests/Strings/StringsFileGeneratorTests.swift +++ b/Tests/ResgenSwiftTests/Strings/StringsFileGeneratorTests.swift @@ -252,12 +252,18 @@ final class StringsFileGeneratorTests: XCTestCase { /// Translation in fr : /// Section Un - Definition Un + /// + /// Comment : + /// No comment 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 + /// + /// Comment : + /// No comment var s1_def_two: String { 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 : /// Section Deux - Definition Un + /// + /// Comment : + /// No comment 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 + /// + /// Comment : + /// No comment var s2_def_two: String { 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 : /// Section Un - Definition Un + /// + /// Comment : + /// No comment 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 + /// + /// Comment : + /// No comment static var s1_def_two: String { 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 : /// Section Deux - Definition Un + /// + /// Comment : + /// No comment 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 + /// + /// Comment : + /// No comment static var s2_def_two: String { NSLocalizedString("s2_def_two", tableName: kStringsFileName, bundle: Bundle.main, value: "Section Deux - Definition Deux", comment: "") }