v1.2.1 #4
@ -12,7 +12,12 @@ class StringsFileGenerator {
|
||||
|
||||
// MARK: - Strings Files
|
||||
|
||||
static func writeStringsFiles(sections: [Section], langs: [String], defaultLang: String, tags: [String], outputPath: String, inputFilenameWithoutExt: String) {
|
||||
static func writeStringsFiles(sections: [Section],
|
||||
langs: [String],
|
||||
defaultLang: String,
|
||||
tags: [String],
|
||||
outputPath: String,
|
||||
inputFilenameWithoutExt: String) {
|
||||
var stringsFilesContent = [String: String]()
|
||||
for lang in langs {
|
||||
stringsFilesContent[lang] = Self.generateStringsFileContent(lang: lang,
|
||||
@ -37,7 +42,10 @@ class StringsFileGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
static func generateStringsFileContent(lang: String, defaultLang: String, tags inputTags: [String], sections: [Section]) -> String {
|
||||
static func generateStringsFileContent(lang: String,
|
||||
defaultLang: String,
|
||||
tags inputTags: [String],
|
||||
sections: [Section]) -> String {
|
||||
var stringsFileContent = """
|
||||
/**
|
||||
* Apple Strings File
|
||||
@ -86,14 +94,22 @@ class StringsFileGenerator {
|
||||
|
||||
// MARK: - Extension file
|
||||
|
||||
static func writeExtensionFiles(sections: [Section], defaultLang lang: String, tags: [String], staticVar: Bool, inputFilename: String, extensionName: String, extensionFilePath: String) {
|
||||
static func writeExtensionFiles(sections: [Section],
|
||||
defaultLang lang: String,
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
inputFilename: String,
|
||||
extensionName: String,
|
||||
extensionFilePath: String,
|
||||
extensionSuffix: String) {
|
||||
// Get extension content
|
||||
let extensionFileContent = Self.getExtensionContent(sections: sections,
|
||||
defaultLang: lang,
|
||||
tags: tags,
|
||||
staticVar: staticVar,
|
||||
inputFilename: inputFilename,
|
||||
extensionName: extensionName)
|
||||
extensionName: extensionName,
|
||||
extensionSuffix: extensionSuffix)
|
||||
|
||||
// Write content
|
||||
let extensionFilePathURL = URL(fileURLWithPath: extensionFilePath)
|
||||
@ -108,10 +124,16 @@ class StringsFileGenerator {
|
||||
|
||||
// MARK: - Extension content
|
||||
|
||||
static func getExtensionContent(sections: [Section], defaultLang lang: String, tags: [String], staticVar: Bool, inputFilename: String, extensionName: String) -> String {
|
||||
static func getExtensionContent(sections: [Section],
|
||||
defaultLang lang: String,
|
||||
tags: [String],
|
||||
staticVar: Bool,
|
||||
inputFilename: String,
|
||||
extensionName: String,
|
||||
extensionSuffix: String) -> String {
|
||||
[
|
||||
Self.getHeader(stringsFilename: inputFilename, extensionClassname: extensionName),
|
||||
Self.getEnumKey(sections: sections, tags: tags),
|
||||
Self.getEnumKey(sections: sections, tags: tags, extensionSuffix: extensionSuffix),
|
||||
Self.getProperties(sections: sections, defaultLang: lang, tags: tags, staticVar: staticVar),
|
||||
Self.getFooter()
|
||||
]
|
||||
@ -132,8 +154,8 @@ class StringsFileGenerator {
|
||||
"""
|
||||
}
|
||||
|
||||
private static func getEnumKey(sections: [Section], tags: [String]) -> String {
|
||||
var enumDefinition = "\n enum Key: String {\n"
|
||||
private static func getEnumKey(sections: [Section], tags: [String], extensionSuffix: String) -> String {
|
||||
var enumDefinition = "\n enum Key\(extensionSuffix.uppercasedFirst()): String {\n"
|
||||
|
||||
sections.forEach { section in
|
||||
// Check that at least one string will be generated
|
||||
|
@ -57,7 +57,8 @@ struct Stringium: ParsableCommand {
|
||||
staticVar: options.staticMembers,
|
||||
inputFilename: options.inputFilenameWithoutExt,
|
||||
extensionName: options.extensionName,
|
||||
extensionFilePath: options.extensionFilePath)
|
||||
extensionFilePath: options.extensionFilePath,
|
||||
extensionSuffix: options.extensionSuffix)
|
||||
|
||||
print("[\(Self.toolName)] Strings generated")
|
||||
}
|
||||
|
@ -36,8 +36,8 @@ struct StringiumOptions: ParsableArguments {
|
||||
@Option(help: "Extension name. If not specified, it will generate an String extension.")
|
||||
var extensionName: String = Stringium.defaultExtensionName
|
||||
|
||||
@Option(help: "Extension suffix. Ex: MyApp, it will generate {extensionName}+{extensionSuffix}.swift")
|
||||
var extensionSuffix: String?
|
||||
@Option(help: "Extension suffix: {extensionName}+{extensionSuffix}.swift")
|
||||
var extensionSuffix: String
|
||||
}
|
||||
|
||||
// MARK: - Private var getter
|
||||
@ -68,10 +68,7 @@ extension StringiumOptions {
|
||||
|
||||
extension StringiumOptions {
|
||||
var extensionFileName: String {
|
||||
if let extensionSuffix = extensionSuffix {
|
||||
return "\(extensionName)+\(extensionSuffix).swift"
|
||||
}
|
||||
return "\(extensionName).swift"
|
||||
"\(extensionName)+\(extensionSuffix).swift"
|
||||
}
|
||||
|
||||
var extensionFilePath: String {
|
||||
|
@ -85,4 +85,8 @@ public extension String {
|
||||
blue = String(colorClean.prefix(2))
|
||||
return (alpha: alpha, red: red, green: green, blue: blue)
|
||||
}
|
||||
|
||||
func uppercasedFirst() -> String {
|
||||
prefix(1).uppercased() + dropFirst()
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,8 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: false,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings")
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
@ -207,7 +208,8 @@ final class StringsFileGeneratorTests: XCTestCase {
|
||||
tags: ["ios", "iosonly", "notranslation"],
|
||||
staticVar: true,
|
||||
inputFilename: "myInputFilename",
|
||||
extensionName: "GenStrings")
|
||||
extensionName: "GenStrings",
|
||||
extensionSuffix: "strings")
|
||||
|
||||
// Expect
|
||||
let expect = """
|
||||
|
Loading…
x
Reference in New Issue
Block a user