Created
May 8, 2018 16:04
-
-
Save beloso/9fbc3d5bf1f660f3ef9033ebf3d6de08 to your computer and use it in GitHub Desktop.
SwiftGen non caching Strings template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
{% 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}} {{accessModifier}} static func {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { | |
{{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %}) | |
{{sp}} } | |
{{sp}} {% else %} | |
{{sp}} {{accessModifier}} static var {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}: String { return {{enumName}}.tr("{{table}}", "{{string.key}}") } | |
{{sp}} {% endif %} | |
{{sp}} {% endfor %} | |
{{sp}} {% for child in item.children %} | |
{{sp}} {% call recursiveBlock table child sp %} | |
{{sp}} {% endfor %} | |
{% endmacro %} | |
// swiftlint:disable 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}} { | |
{% call recursiveBlock table.name table.levels " " %} | |
} | |
{% endfor %} | |
{% else %} | |
{% call recursiveBlock tables.first.name tables.first.levels "" %} | |
{% endif %} | |
} | |
// swiftlint:enable identifier_name line_length type_body_length | |
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: "") | |
return String(format: format, locale: Locale.current, arguments: args) | |
} | |
} | |
private final class BundleToken {} | |
{% else %} | |
// No string found | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment