Handle bundle for Stringium
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good
This commit is contained in:
@@ -105,7 +105,8 @@ class Definition {
|
||||
translation: String,
|
||||
isStatic: Bool,
|
||||
comment: String?,
|
||||
visibility: ExtensionVisibility
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
"""
|
||||
/// Translation in \(lang) :
|
||||
@@ -114,7 +115,7 @@ class Definition {
|
||||
/// Comment :
|
||||
/// \(comment?.isEmpty == false ? comment! : "No comment")
|
||||
\(visibility) \(isStatic ? "static " : "")var \(name): String {
|
||||
NSLocalizedString("\(name)", tableName: kStringsFileName, bundle: Bundle.main, value: "\(translation)", comment: "\(comment ?? "")")
|
||||
NSLocalizedString("\(name)", tableName: kStringsFileName, bundle: Bundle.\(assetBundle), value: "\(translation)", comment: "\(comment ?? "")")
|
||||
}
|
||||
"""
|
||||
}
|
||||
@@ -141,7 +142,12 @@ class Definition {
|
||||
"""
|
||||
}
|
||||
|
||||
func getNSLocalizedStringProperty(forLang lang: String, visibility: ExtensionVisibility) -> String {
|
||||
func getNSLocalizedStringProperty(
|
||||
forLang lang: String,
|
||||
isStatic: Bool,
|
||||
visibility: ExtensionVisibility,
|
||||
assetBundle: AssetBundle
|
||||
) -> String {
|
||||
guard let translation = translations[lang] else {
|
||||
let error = StringiumError.langNotDefined(lang, name, reference != nil)
|
||||
print(error.description)
|
||||
@@ -152,9 +158,10 @@ class Definition {
|
||||
let property = getBaseProperty(
|
||||
lang: lang,
|
||||
translation: translation,
|
||||
isStatic: false,
|
||||
isStatic: isStatic,
|
||||
comment: self.comment,
|
||||
visibility: visibility
|
||||
visibility: visibility,
|
||||
assetBundle: assetBundle
|
||||
)
|
||||
|
||||
// Generate method
|
||||
@@ -163,40 +170,7 @@ class Definition {
|
||||
method = getBaseMethod(
|
||||
lang: lang,
|
||||
translation: translation,
|
||||
isStatic: false,
|
||||
inputParameters: parameters.inputParameters,
|
||||
translationArguments: parameters.translationArguments,
|
||||
comment: self.comment,
|
||||
visibility: visibility
|
||||
)
|
||||
}
|
||||
|
||||
return property + method
|
||||
}
|
||||
|
||||
func getNSLocalizedStringStaticProperty(forLang lang: String, visibility: ExtensionVisibility) -> String {
|
||||
guard let translation = translations[lang] else {
|
||||
let error = StringiumError.langNotDefined(lang, name, reference != nil)
|
||||
print(error.description)
|
||||
Stringium.exit(withError: error)
|
||||
}
|
||||
|
||||
// Generate property
|
||||
let property = getBaseProperty(
|
||||
lang: lang,
|
||||
translation: translation,
|
||||
isStatic: true,
|
||||
comment: self.comment,
|
||||
visibility: visibility
|
||||
)
|
||||
|
||||
// Generate method
|
||||
var method = ""
|
||||
if let parameters = self.getStringParameters(input: translation) {
|
||||
method = getBaseMethod(
|
||||
lang: lang,
|
||||
translation: translation,
|
||||
isStatic: true,
|
||||
isStatic: isStatic,
|
||||
inputParameters: parameters.inputParameters,
|
||||
translationArguments: parameters.translationArguments,
|
||||
comment: self.comment,
|
||||
@@ -209,7 +183,11 @@ class Definition {
|
||||
|
||||
// MARK: - Raw strings
|
||||
|
||||
func getProperty(forLang lang: String, visibility: ExtensionVisibility) -> String {
|
||||
func getProperty(
|
||||
forLang lang: String,
|
||||
visibility: ExtensionVisibility,
|
||||
isStatic: Bool
|
||||
) -> String {
|
||||
guard let translation = translations[lang] else {
|
||||
let error = StringiumError.langNotDefined(lang, name, reference != nil)
|
||||
print(error.description)
|
||||
@@ -222,26 +200,7 @@ class Definition {
|
||||
///
|
||||
/// Comment :
|
||||
/// \(comment?.isEmpty == false ? comment! : "No comment")
|
||||
\(visibility) var \(name): String {
|
||||
"\(translation)"
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
func getStaticProperty(forLang lang: String, visibility: ExtensionVisibility) -> String {
|
||||
guard let translation = translations[lang] else {
|
||||
let error = StringiumError.langNotDefined(lang, name, reference != nil)
|
||||
print(error.description)
|
||||
Stringium.exit(withError: error)
|
||||
}
|
||||
|
||||
return """
|
||||
/// Translation in \(lang) :
|
||||
/// \(translation)
|
||||
///
|
||||
/// Comment :
|
||||
/// \(comment?.isEmpty == false ? comment! : "No comment")
|
||||
\(visibility) static var \(name): String {
|
||||
\(visibility) \(isStatic ? "static " : "")var \(name): String {
|
||||
"\(translation)"
|
||||
}
|
||||
"""
|
||||
|
Reference in New Issue
Block a user