mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
Add SwiftGen custom template for strings. Update SwiftGen config file.
This commit is contained in:
84
Tools/SwiftGen/Templates/Strings/flat-swift4-vector.stencil
Normal file
84
Tools/SwiftGen/Templates/Strings/flat-swift4-vector.stencil
Normal file
@@ -0,0 +1,84 @@
|
||||
// swiftlint:disable all
|
||||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
|
||||
|
||||
{% if tables.count > 0 %}
|
||||
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
||||
import Foundation
|
||||
|
||||
// swiftlint:disable superfluous_disable_command
|
||||
// swiftlint:disable file_length
|
||||
|
||||
// MARK: - Strings
|
||||
|
||||
{% macro parametersBlock types %}{% filter removeNewlines:"leading" %}
|
||||
{% for type in types %}
|
||||
_ p{{forloop.counter}}: {{type}}{{ ", " if not forloop.last }}
|
||||
{% endfor %}
|
||||
{% endfilter %}{% endmacro %}
|
||||
{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %}
|
||||
{% for type in types %}
|
||||
{% if type == "UnsafeRawPointer" %}
|
||||
Int(bitPattern: p{{forloop.counter}})
|
||||
{% else %}
|
||||
p{{forloop.counter}}
|
||||
{% endif %}
|
||||
{{ ", " if not forloop.last }}
|
||||
{% endfor %}
|
||||
{% endfilter %}{% endmacro %}
|
||||
{% macro recursiveBlock table item %}
|
||||
{% for string in item.strings %}
|
||||
{% if not param.noComments %}
|
||||
/// {{string.translation}}
|
||||
{% endif %}
|
||||
{% if string.types %}
|
||||
{{accessModifier}} static func {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String {
|
||||
return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %})
|
||||
}
|
||||
{% else %}
|
||||
{{accessModifier}} static var {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}: String {
|
||||
return {{enumName}}.tr("{{table}}", "{{string.key}}")
|
||||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% for child in item.children %}
|
||||
{% call recursiveBlock table child %}
|
||||
{% endfor %}
|
||||
{% endmacro %}
|
||||
// swiftlint:disable function_parameter_count identifier_name line_length type_body_length
|
||||
{% set enumName %}{{param.enumName|default:"L10n"}}{% endset %}
|
||||
{{accessModifier}} enum {{enumName}} {
|
||||
{% if tables.count > 1 %}
|
||||
{% for table in tables %}
|
||||
{{accessModifier}} enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
||||
{% filter indent:2 %}{% call recursiveBlock table.name table.levels %}{% endfilter %}
|
||||
}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% call recursiveBlock tables.first.name tables.first.levels %}
|
||||
{% endif %}
|
||||
}
|
||||
// swiftlint:enable function_parameter_count identifier_name line_length type_body_length
|
||||
|
||||
// MARK: - Implementation Details
|
||||
|
||||
extension {{enumName}} {
|
||||
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
|
||||
let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "")
|
||||
let locale: Locale
|
||||
|
||||
if let localeIdentifier = Bundle.mxk_language() {
|
||||
locale = Locale(identifier: localeIdentifier)
|
||||
} else if let fallbackLocaleIdentifier = Bundle.mxk_fallbackLanguage() {
|
||||
locale = Locale(identifier: fallbackLocaleIdentifier)
|
||||
} else {
|
||||
locale = Locale.current
|
||||
}
|
||||
|
||||
return String(format: format, locale: locale, arguments: args)
|
||||
}
|
||||
}
|
||||
|
||||
private final class BundleToken {}
|
||||
{% else %}
|
||||
// No string found
|
||||
{% endif %}
|
||||
@@ -2,14 +2,14 @@ input_dir: ../../Riot/
|
||||
output_dir: ../../Riot/Generated/
|
||||
ib:
|
||||
- inputs:
|
||||
- Assets/Base.lproj/LaunchScreen.storyboard
|
||||
- Modules/KeyBackup/
|
||||
outputs:
|
||||
- templateName: scenes-swift4
|
||||
output: Storyboards.swift
|
||||
strings:
|
||||
inputs: Assets/en.lproj/Vector.strings
|
||||
outputs:
|
||||
- templateName: flat-swift4
|
||||
- templatePath: Templates/Strings/flat-swift4-vector.stencil
|
||||
output: Strings.swift
|
||||
params:
|
||||
enumName: VectorL10n
|
||||
|
||||
Reference in New Issue
Block a user