xcstrings #10
@ -14,8 +14,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
|
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "db51c407d3be4a051484a141bf0bff36c43d3b1e",
|
"revision" : "c9c3df6ab812de32bae61fc0cd1bf6d45170ebf0",
|
||||||
"version" : "1.8.0"
|
"version" : "1.8.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -269,6 +269,7 @@ struct StringsConfiguration: Codable, CustomDebugStringConvertible {
|
|||||||
let extensionName: String?
|
let extensionName: String?
|
||||||
let extensionSuffix: String?
|
let extensionSuffix: String?
|
||||||
private let staticMembers: Bool?
|
private let staticMembers: Bool?
|
||||||
|
private let xcStrings: Bool?
|
||||||
|
|
||||||
var staticMembersOptions: Bool {
|
var staticMembersOptions: Bool {
|
||||||
if let staticMembers = staticMembers {
|
if let staticMembers = staticMembers {
|
||||||
@ -277,6 +278,13 @@ struct StringsConfiguration: Codable, CustomDebugStringConvertible {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var xcStringsOptions: Bool {
|
||||||
|
if let xcStrings = xcStrings {
|
||||||
|
return xcStrings
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
internal init(inputFile: String,
|
internal init(inputFile: String,
|
||||||
outputPath: String,
|
outputPath: String,
|
||||||
langs: String,
|
langs: String,
|
||||||
@ -284,7 +292,8 @@ struct StringsConfiguration: Codable, CustomDebugStringConvertible {
|
|||||||
extensionOutputPath: String,
|
extensionOutputPath: String,
|
||||||
extensionName: String?,
|
extensionName: String?,
|
||||||
extensionSuffix: String?,
|
extensionSuffix: String?,
|
||||||
staticMembers: Bool?) {
|
staticMembers: Bool?,
|
||||||
|
xcStrings: Bool?) {
|
||||||
self.inputFile = inputFile
|
self.inputFile = inputFile
|
||||||
self.outputPath = outputPath
|
self.outputPath = outputPath
|
||||||
self.langs = langs
|
self.langs = langs
|
||||||
@ -293,6 +302,7 @@ struct StringsConfiguration: Codable, CustomDebugStringConvertible {
|
|||||||
self.extensionName = extensionName
|
self.extensionName = extensionName
|
||||||
self.extensionSuffix = extensionSuffix
|
self.extensionSuffix = extensionSuffix
|
||||||
self.staticMembers = staticMembers
|
self.staticMembers = staticMembers
|
||||||
|
self.xcStrings = xcStrings
|
||||||
}
|
}
|
||||||
|
|
||||||
var debugDescription: String {
|
var debugDescription: String {
|
||||||
|
@ -26,7 +26,9 @@ extension StringsConfiguration: Runnable {
|
|||||||
"--extension-output-path",
|
"--extension-output-path",
|
||||||
extensionOutputPath.prependIfRelativePath(projectDirectory),
|
extensionOutputPath.prependIfRelativePath(projectDirectory),
|
||||||
"--static-members",
|
"--static-members",
|
||||||
"\(staticMembersOptions)"
|
"\(staticMembersOptions)",
|
||||||
|
"--xc-strings",
|
||||||
|
"\(xcStringsOptions)"
|
||||||
]
|
]
|
||||||
|
|
||||||
if let extensionName = extensionName {
|
if let extensionName = extensionName {
|
||||||
|
@ -17,10 +17,8 @@ class StringsFileGenerator {
|
|||||||
defaultLang: String,
|
defaultLang: String,
|
||||||
tags: [String],
|
tags: [String],
|
||||||
outputPath: String,
|
outputPath: String,
|
||||||
inputFilenameWithoutExt: String,
|
inputFilenameWithoutExt: String) {
|
||||||
isXcString: Bool = false) {
|
|
||||||
|
|
||||||
if !isXcString {
|
|
||||||
var stringsFilesContent = [String: String]()
|
var stringsFilesContent = [String: String]()
|
||||||
for lang in langs {
|
for lang in langs {
|
||||||
stringsFilesContent[lang] = Self.generateStringsFileContent(lang: lang,
|
stringsFilesContent[lang] = Self.generateStringsFileContent(lang: lang,
|
||||||
@ -43,7 +41,15 @@ class StringsFileGenerator {
|
|||||||
Stringium.exit(withError: error)
|
Stringium.exit(withError: error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
static func writeXcStringsFiles(sections: [Section],
|
||||||
|
langs: [String],
|
||||||
|
defaultLang: String,
|
||||||
|
tags: [String],
|
||||||
|
outputPath: String,
|
||||||
|
inputFilenameWithoutExt: String) {
|
||||||
|
|
||||||
let fileContent: String = Self.generateXcStringsFileContent(
|
let fileContent: String = Self.generateXcStringsFileContent(
|
||||||
langs: langs,
|
langs: langs,
|
||||||
defaultLang: defaultLang,
|
defaultLang: defaultLang,
|
||||||
@ -51,7 +57,7 @@ class StringsFileGenerator {
|
|||||||
sections: sections
|
sections: sections
|
||||||
)
|
)
|
||||||
|
|
||||||
let stringsFilePath = "\(outputPath)/Localizable.xcstrings"
|
let stringsFilePath = "\(outputPath)/\(inputFilenameWithoutExt).xcstrings"
|
||||||
let stringsFilePathURL = URL(fileURLWithPath: stringsFilePath)
|
let stringsFilePathURL = URL(fileURLWithPath: stringsFilePath)
|
||||||
do {
|
do {
|
||||||
try fileContent.write(to: stringsFilePathURL, atomically: false, encoding: .utf8)
|
try fileContent.write(to: stringsFilePathURL, atomically: false, encoding: .utf8)
|
||||||
@ -61,7 +67,6 @@ class StringsFileGenerator {
|
|||||||
Stringium.exit(withError: error)
|
Stringium.exit(withError: error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static func generateStringsFileContent(lang: String,
|
static func generateStringsFileContent(lang: String,
|
||||||
defaultLang: String,
|
defaultLang: String,
|
||||||
|
@ -40,7 +40,9 @@ struct XCStringDefinitionContainer: Codable, Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func == (lhs: XCStringDefinitionContainer, rhs: XCStringDefinitionContainer) -> Bool {
|
static func == (lhs: XCStringDefinitionContainer, rhs: XCStringDefinitionContainer) -> Bool {
|
||||||
return lhs.strings.count == rhs.strings.count && lhs.strings.sorted(by: { $0.title < $1.title }) == rhs.strings.sorted(by: { $0.title < $1.title })
|
return lhs.strings.sorted(by: {
|
||||||
|
$0.title < $1.title
|
||||||
|
}) == rhs.strings.sorted(by: { $0.title < $1.title })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,13 +43,16 @@ struct Stringium: ParsableCommand {
|
|||||||
let sections = TwineFileParser.parse(options.inputFile)
|
let sections = TwineFileParser.parse(options.inputFile)
|
||||||
|
|
||||||
// Generate strings files
|
// Generate strings files
|
||||||
|
print(options.xcStrings)
|
||||||
|
if !options.xcStrings {
|
||||||
|
print("[\(Self.toolName)] Will generate strings")
|
||||||
|
|
||||||
StringsFileGenerator.writeStringsFiles(sections: sections,
|
StringsFileGenerator.writeStringsFiles(sections: sections,
|
||||||
langs: options.langs,
|
langs: options.langs,
|
||||||
defaultLang: options.defaultLang,
|
defaultLang: options.defaultLang,
|
||||||
tags: options.tags,
|
tags: options.tags,
|
||||||
outputPath: options.stringsFileOutputPath,
|
outputPath: options.stringsFileOutputPath,
|
||||||
inputFilenameWithoutExt: options.inputFilenameWithoutExt,
|
inputFilenameWithoutExt: options.inputFilenameWithoutExt)
|
||||||
isXcString: options.isXcstring)
|
|
||||||
|
|
||||||
// Generate extension
|
// Generate extension
|
||||||
StringsFileGenerator.writeExtensionFiles(sections: sections,
|
StringsFileGenerator.writeExtensionFiles(sections: sections,
|
||||||
@ -61,6 +64,16 @@ struct Stringium: ParsableCommand {
|
|||||||
extensionFilePath: options.extensionFilePath,
|
extensionFilePath: options.extensionFilePath,
|
||||||
extensionSuffix: options.extensionSuffix)
|
extensionSuffix: options.extensionSuffix)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
print("[\(Self.toolName)] Will generate xcStrings")
|
||||||
|
StringsFileGenerator.writeXcStringsFiles(sections: sections,
|
||||||
|
langs: options.langs,
|
||||||
|
defaultLang: options.defaultLang,
|
||||||
|
tags: options.tags,
|
||||||
|
outputPath: options.stringsFileOutputPath,
|
||||||
|
inputFilenameWithoutExt: options.inputFilenameWithoutExt)
|
||||||
|
}
|
||||||
|
|
||||||
print("[\(Self.toolName)] Strings generated")
|
print("[\(Self.toolName)] Strings generated")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,10 +12,7 @@ struct StringiumOptions: ParsableArguments {
|
|||||||
@Flag(name: [.customShort("f"), .customShort("F")], help: "Should force generation")
|
@Flag(name: [.customShort("f"), .customShort("F")], help: "Should force generation")
|
||||||
var forceGeneration = false
|
var forceGeneration = false
|
||||||
|
|
||||||
@Flag(name: [.customShort("x"), .customLong("xcstrings")], help: "Generate xcstrings catalog")
|
@Argument(help: "Input files where strings are defined.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
||||||
var isXcstring = false
|
|
||||||
|
|
||||||
@Argument(help: "Input files where strings ared defined.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
|
||||||
var inputFile: String
|
var inputFile: String
|
||||||
|
|
||||||
@Option(name: .customLong("output-path"), help: "Path where to strings file.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
@Option(name: .customLong("output-path"), help: "Path where to strings file.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
||||||
@ -36,6 +33,9 @@ struct StringiumOptions: ParsableArguments {
|
|||||||
@Option(help: "Tell if it will generate static properties or not")
|
@Option(help: "Tell if it will generate static properties or not")
|
||||||
var staticMembers: Bool = false
|
var staticMembers: Bool = false
|
||||||
|
|
||||||
|
@Option(help: "Tell if it will generate xcStrings file or not")
|
||||||
|
var xcStrings: Bool = false
|
||||||
|
|
||||||
@Option(help: "Extension name. If not specified, it will generate an String extension.")
|
@Option(help: "Extension name. If not specified, it will generate an String extension.")
|
||||||
var extensionName: String = Stringium.defaultExtensionName
|
var extensionName: String = Stringium.defaultExtensionName
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user