EmbeddedSocial-iOS-SDK/Templates/strings-structured-swift3.s...

64 строки
2.4 KiB
Plaintext

// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
{% if tables.count > 0 %}
import Foundation
// swiftlint:disable file_length
{% macro parametersBlock types %}{% filter removeNewlines:"leading" %}
{% for type in types %}
_ p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %}
{% endfor %}
{% endfilter %}{% endmacro %}
{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %}
{% for type in types %}
p{{forloop.counter}}{% if not forloop.last %}, {% endif %}
{% endfor %}
{% endfilter %}{% endmacro %}
{% macro recursiveBlock table item sp %}
{{sp}} {% for string in item.strings %}
{{sp}} {% if not param.noComments %}
{{sp}} /// {{string.translation}}
{{sp}} {% endif %}
{{sp}} {% if string.types %}
{{sp}} static func {{string.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String {
{{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %})
{{sp}} }
{{sp}} {% else %}
{{sp}} static let {{string.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}")
{{sp}} {% endif %}
{{sp}} {% endfor %}
{{sp}} {% for child in item.children %}
{{sp}} enum {{child.name|swiftIdentifier|snakeToCamelCase}} {
{{sp}} {% set sp2 %}{{sp}} {% endset %}
{{sp}} {% call recursiveBlock table child sp2 %}
{{sp}} }
{{sp}} {% endfor %}
{% endmacro %}
// swiftlint:disable explicit_type_interface identifier_name line_length nesting type_body_length type_name
{% set enumName %}{{param.enumName|default:"L10n"}}{% endset %}
enum {{enumName}} {
{% if tables.count > 1 %}
{% for table in tables %}
enum {{table.name|swiftIdentifier|snakeToCamelCase}} {
{% call recursiveBlock table.name table.levels " " %}
}
{% endfor %}
{% else %}
{% call recursiveBlock tables.first.name tables.first.levels "" %}
{% endif %}
}
// swiftlint:enable explicit_type_interface identifier_name line_length nesting type_body_length type_name
extension {{enumName}} {
fileprivate static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "")
return String(format: format, locale: Locale.current, arguments: args)
}
}
private final class BundleToken {}
{% else %}
// No string found
{% endif %}