Thibault Wittemberg | 1f9ce46 | 2017-07-05 17:33:36 -0400 | [diff] [blame^] | 1 | // Generated using SwiftGen, by O.Halligon — https://github.com/AliSoftware/SwiftGen |
| 2 | |
| 3 | {% if structuredStrings %} |
| 4 | import Foundation |
| 5 | |
| 6 | private class RingStringsBundleToken {} |
| 7 | |
| 8 | // swiftlint:disable file_length |
| 9 | // swiftlint:disable line_length |
| 10 | |
| 11 | // swiftlint:disable type_body_length |
| 12 | // swiftlint:disable nesting |
| 13 | // swiftlint:disable variable_name |
| 14 | // swiftlint:disable valid_docs |
| 15 | {% macro parametersBlock params %}{% for type in params.types %}_ p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} |
| 16 | {% macro argumentsBlock params %}{% for type in params.types %}p{{forloop.counter}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} |
| 17 | {% macro recursiveBlock strings sp %} |
| 18 | {{sp}} {% for string in strings.strings %} |
| 19 | {{sp}} /// {{string.translation}} |
| 20 | {{sp}} {% if string.params %} |
| 21 | {{sp}} static func {{string.keytail|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.params %}) -> LocalizableString { |
| 22 | {{sp}} return {{enumName}}.tr("{{string.key}}", {% call argumentsBlock string.params %}) |
| 23 | {{sp}} } |
| 24 | {{sp}} {% else %} |
| 25 | {{sp}} static let {{string.keytail|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{string.key}}") |
| 26 | {{sp}} {% endif %} |
| 27 | {{sp}} {% endfor %} |
| 28 | {{sp}} {% if strings.subenums %} |
| 29 | {{sp}} {% for subenum in strings.subenums %} |
| 30 | |
| 31 | {{sp}} enum {{subenum.name|swiftIdentifier|snakeToCamelCase}} { |
| 32 | {{sp}} {% set sp2 %}{{sp}} {% endset %} |
| 33 | {{sp}} {% call recursiveBlock subenum sp2 %} |
| 34 | {{sp}} } |
| 35 | {{sp}} {% endfor %} |
| 36 | {{sp}} {% endif %} |
| 37 | {% endmacro %} |
| 38 | |
| 39 | enum {{enumName}} { |
| 40 | {% call recursiveBlock structuredStrings sp %} |
| 41 | } |
| 42 | |
| 43 | struct LocalizableString { |
| 44 | let key: String |
| 45 | let args: [CVarArg] |
| 46 | |
| 47 | /** |
| 48 | Returns String from Current Bundle |
| 49 | */ |
| 50 | public var string: String { |
| 51 | let format: String = NSLocalizedString(key, tableName: nil, bundle: Bundle(for: RingStringsBundleToken.self), value: "", comment: "") |
| 52 | return String(format: format, locale: Locale.current, arguments: args) |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | Returns String translated from App's Bundle is found, otherwise from Current Bundle |
| 57 | */ |
| 58 | public var smartString: String { |
| 59 | // Load from App's Bundle first |
| 60 | var format: String = NSLocalizedString(key, tableName: nil, bundle: Bundle.main, value: "", comment: "") |
| 61 | if format != "" && format != key { |
| 62 | return String(format: format, locale: Locale.current, arguments: args) |
| 63 | } |
| 64 | // Load from Current Bundle |
| 65 | format = NSLocalizedString(key, tableName: nil, bundle: Bundle(for: RingStringsBundleToken.self), value: "", comment: "") |
| 66 | |
| 67 | return String(format: format, locale: Locale.current, arguments: args) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | extension {{enumName}} { |
| 72 | fileprivate static func tr(_ key: String, _ args: CVarArg...) -> LocalizableString { |
| 73 | return LocalizableString(key: key, args: args) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // swiftlint:enable type_body_length |
| 78 | // swiftlint:enable nesting |
| 79 | // swiftlint:enable variable_name |
| 80 | // swiftlint:enable valid_docs |
| 81 | {% else %} |
| 82 | // No string found |
| 83 | {% endif %} |