-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_L10n.stencil
71 lines (63 loc) · 2.63 KB
/
custom_L10n.stencil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
{% if tables.count > 0 %}
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}} static func {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String {
{{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %})
{{sp}} }
{{sp}} {% else %}
{{sp}} static var {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}: String {
{{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}")
{{sp}} }
{{sp}} {% endif %}
{{sp}} {% endfor %}
{{sp}} {% for child in item.children %}
{{sp}} enum {{child.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
{{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}} {
/// Update bundle if you need to change app language
static var bundle: Bundle?
{% if tables.count > 1 %}
{% for table in tables %}
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 explicit_type_interface identifier_name line_length nesting type_body_length type_name
extension {{enumName}} {
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
let format = NSLocalizedString(key, tableName: table, bundle: bundle ?? Bundle(for: BundleToken.self), comment: "")
return String(format: format, locale: Locale.current, arguments: args)
}
}
private final class BundleToken {}
{% else %}
// No string found
{% endif %}