danger-localizationlinter 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +12 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +167 -0
- data/Guardfile +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +25 -0
- data/danger-localizationlinter.gemspec +60 -0
- data/ext/localizationlinter/helper/validate_wording_cli.rb +21 -0
- data/ext/localizationlinter/localizationlinter.rb +331 -0
- data/ext/localizationlinter/swiftgen_localizables_check.stencil +36 -0
- data/lib/danger_localizationlinter.rb +3 -0
- data/lib/danger_plugin.rb +3 -0
- data/lib/localizationlinter/gem_version.rb +5 -0
- data/lib/localizationlinter/plugin.rb +96 -0
- data/spec/Test/Podfile +6 -0
- data/spec/Test/Podfile.lock +16 -0
- data/spec/Test/Pods/SwiftGen/CHANGELOG.md +1357 -0
- data/spec/Test/Pods/SwiftGen/LICENCE +21 -0
- data/spec/Test/Pods/SwiftGen/README.md +892 -0
- data/spec/Test/Pods/SwiftGen/bin/swiftgen +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Commander +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/A/Commander +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/Current/Commander +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Commander.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Kanna +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/A/Kanna +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/Current/Kanna +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Kanna.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/PathKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/A/PathKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/Current/PathKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/PathKit.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Stencil +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/A/Stencil +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/Current/Stencil +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Stencil.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/StencilSwiftKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/Current/StencilSwiftKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/StencilSwiftKit.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/SwiftGenKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/Current/SwiftGenKit +0 -0
- data/spec/Test/Pods/SwiftGen/lib/SwiftGenKit.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/A/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/A/Yams +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/A/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/Current/Resources/Info.plist +48 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/Current/Yams +0 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Versions/Current/_CodeSignature/CodeResources +132 -0
- data/spec/Test/Pods/SwiftGen/lib/Yams.framework/Yams +0 -0
- data/spec/Test/Pods/SwiftGen/templates/colors/literals-swift4.stencil +43 -0
- data/spec/Test/Pods/SwiftGen/templates/colors/literals-swift5.stencil +43 -0
- data/spec/Test/Pods/SwiftGen/templates/colors/swift4.stencil +84 -0
- data/spec/Test/Pods/SwiftGen/templates/colors/swift5.stencil +84 -0
- data/spec/Test/Pods/SwiftGen/templates/coredata/swift4.stencil +211 -0
- data/spec/Test/Pods/SwiftGen/templates/coredata/swift5.stencil +211 -0
- data/spec/Test/Pods/SwiftGen/templates/fonts/swift4.stencil +110 -0
- data/spec/Test/Pods/SwiftGen/templates/fonts/swift5.stencil +113 -0
- data/spec/Test/Pods/SwiftGen/templates/ib/scenes-swift4.stencil +157 -0
- data/spec/Test/Pods/SwiftGen/templates/ib/scenes-swift5.stencil +159 -0
- data/spec/Test/Pods/SwiftGen/templates/ib/segues-swift4.stencil +60 -0
- data/spec/Test/Pods/SwiftGen/templates/ib/segues-swift5.stencil +60 -0
- data/spec/Test/Pods/SwiftGen/templates/json/inline-swift4.stencil +82 -0
- data/spec/Test/Pods/SwiftGen/templates/json/inline-swift5.stencil +82 -0
- data/spec/Test/Pods/SwiftGen/templates/json/runtime-swift4.stencil +112 -0
- data/spec/Test/Pods/SwiftGen/templates/json/runtime-swift5.stencil +112 -0
- data/spec/Test/Pods/SwiftGen/templates/plist/inline-swift4.stencil +82 -0
- data/spec/Test/Pods/SwiftGen/templates/plist/inline-swift5.stencil +82 -0
- data/spec/Test/Pods/SwiftGen/templates/plist/runtime-swift4.stencil +117 -0
- data/spec/Test/Pods/SwiftGen/templates/plist/runtime-swift5.stencil +117 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/flat-swift4.stencil +97 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/flat-swift5.stencil +97 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/objc-h.stencil +66 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/objc-m.stencil +90 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/structured-swift4.stencil +102 -0
- data/spec/Test/Pods/SwiftGen/templates/strings/structured-swift5.stencil +102 -0
- data/spec/Test/Pods/SwiftGen/templates/xcassets/swift4.stencil +266 -0
- data/spec/Test/Pods/SwiftGen/templates/xcassets/swift5.stencil +274 -0
- data/spec/Test/Pods/SwiftGen/templates/yaml/inline-swift4.stencil +92 -0
- data/spec/Test/Pods/SwiftGen/templates/yaml/inline-swift5.stencil +92 -0
- data/spec/Test/Test.xcodeproj/project.pbxproj +406 -0
- data/spec/Test/Test.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/spec/Test/Test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/spec/Test/Test.xcworkspace/contents.xcworkspacedata +10 -0
- data/spec/Test/Test.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/spec/Test/Test/AppDelegate.swift +36 -0
- data/spec/Test/Test/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
- data/spec/Test/Test/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
- data/spec/Test/Test/Assets.xcassets/Contents.json +6 -0
- data/spec/Test/Test/ContentView.swift +21 -0
- data/spec/Test/Test/Info.plist +62 -0
- data/spec/Test/Test/SceneDelegate.swift +63 -0
- data/spec/Test/Test/all_target_main_language.yml +1 -0
- data/spec/Test/Test/en.lproj/LaunchScreen.storyboard +25 -0
- data/spec/Test/Test/en.lproj/localizable.strings +3 -0
- data/spec/Test/Test/fr.lproj/LaunchScreen.storyboard +25 -0
- data/spec/Test/Test/fr.lproj/localizable.strings +3 -0
- data/spec/localizationofficer_spec.rb +116 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/fixtures/all_target_main_language.yml +1 -0
- data/spec/support/fixtures/resources/TEST/en.lproj/Localizable.strings +8 -0
- data/spec/support/fixtures/resources/TEST/en.lproj/Localizable.stringsdict +30 -0
- data/spec/support/fixtures/resources/TEST_KO/en.lproj/Localizable.strings +11 -0
- data/spec/support/fixtures/resources/TEST_KO/en.lproj/Localizable.stringsdict +30 -0
- data/spec/support/fixtures/resources/TEST_KO/fr.lproj/Localizable.strings +11 -0
- data/spec/support/fixtures/resources/TEST_KO/fr.lproj/Localizable.stringsdict +30 -0
- metadata +491 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// swiftlint:disable all
|
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
|
3
|
+
|
|
4
|
+
{% if tables.count > 0 %}
|
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
|
6
|
+
import Foundation
|
|
7
|
+
|
|
8
|
+
// swiftlint:disable superfluous_disable_command file_length implicit_return
|
|
9
|
+
|
|
10
|
+
// MARK: - Strings
|
|
11
|
+
|
|
12
|
+
{% macro parametersBlock types %}{% filter removeNewlines:"leading" %}
|
|
13
|
+
{% for type in types %}
|
|
14
|
+
{% if type == "String" %}
|
|
15
|
+
_ p{{forloop.counter}}: Any
|
|
16
|
+
{% else %}
|
|
17
|
+
_ p{{forloop.counter}}: {{type}}
|
|
18
|
+
{% endif %}
|
|
19
|
+
{{ ", " if not forloop.last }}
|
|
20
|
+
{% endfor %}
|
|
21
|
+
{% endfilter %}{% endmacro %}
|
|
22
|
+
{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %}
|
|
23
|
+
{% for type in types %}
|
|
24
|
+
{% if type == "String" %}
|
|
25
|
+
String(describing: p{{forloop.counter}})
|
|
26
|
+
{% elif type == "UnsafeRawPointer" %}
|
|
27
|
+
Int(bitPattern: p{{forloop.counter}})
|
|
28
|
+
{% else %}
|
|
29
|
+
p{{forloop.counter}}
|
|
30
|
+
{% endif %}
|
|
31
|
+
{{ ", " if not forloop.last }}
|
|
32
|
+
{% endfor %}
|
|
33
|
+
{% endfilter %}{% endmacro %}
|
|
34
|
+
{% macro recursiveBlock table item %}
|
|
35
|
+
{% for string in item.strings %}
|
|
36
|
+
{% if not param.noComments %}
|
|
37
|
+
/// {{string.translation}}
|
|
38
|
+
{% endif %}
|
|
39
|
+
{% if string.types %}
|
|
40
|
+
{{accessModifier}} static func {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String {
|
|
41
|
+
return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %})
|
|
42
|
+
}
|
|
43
|
+
{% elif param.lookupFunction %}
|
|
44
|
+
{# custom localization function is mostly used for in-app lang selection, so we want the loc to be recomputed at each call for those (hence the computed var) #}
|
|
45
|
+
{{accessModifier}} static var {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}: String { return {{enumName}}.tr("{{table}}", "{{string.key}}") }
|
|
46
|
+
{% else %}
|
|
47
|
+
{{accessModifier}} static let {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}")
|
|
48
|
+
{% endif %}
|
|
49
|
+
{% endfor %}
|
|
50
|
+
{% for child in item.children %}
|
|
51
|
+
{% call recursiveBlock table child %}
|
|
52
|
+
{% endfor %}
|
|
53
|
+
{% endmacro %}
|
|
54
|
+
// swiftlint:disable function_parameter_count identifier_name line_length type_body_length
|
|
55
|
+
{% set enumName %}{{param.enumName|default:"L10n"}}{% endset %}
|
|
56
|
+
{{accessModifier}} enum {{enumName}} {
|
|
57
|
+
{% if tables.count > 1 or param.forceFileNameEnum %}
|
|
58
|
+
{% for table in tables %}
|
|
59
|
+
{{accessModifier}} enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
|
60
|
+
{% filter indent:2 %}{% call recursiveBlock table.name table.levels %}{% endfilter %}
|
|
61
|
+
}
|
|
62
|
+
{% endfor %}
|
|
63
|
+
{% else %}
|
|
64
|
+
{% call recursiveBlock tables.first.name tables.first.levels %}
|
|
65
|
+
{% endif %}
|
|
66
|
+
}
|
|
67
|
+
// swiftlint:enable function_parameter_count identifier_name line_length type_body_length
|
|
68
|
+
|
|
69
|
+
// MARK: - Implementation Details
|
|
70
|
+
|
|
71
|
+
extension {{enumName}} {
|
|
72
|
+
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
|
|
73
|
+
{% if param.lookupFunction %}
|
|
74
|
+
let format = {{ param.lookupFunction }}(key, table)
|
|
75
|
+
{% else %}
|
|
76
|
+
let format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: nil, table: table)
|
|
77
|
+
{% endif %}
|
|
78
|
+
return String(format: format, locale: Locale.current, arguments: args)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
{% if not param.bundle and not param.lookupFunction %}
|
|
82
|
+
|
|
83
|
+
// swiftlint:disable convenience_type
|
|
84
|
+
private final class BundleToken {
|
|
85
|
+
static let bundle: Bundle = {
|
|
86
|
+
#if SWIFT_PACKAGE
|
|
87
|
+
return Bundle.module
|
|
88
|
+
#else
|
|
89
|
+
return Bundle(for: BundleToken.self)
|
|
90
|
+
#endif
|
|
91
|
+
}()
|
|
92
|
+
}
|
|
93
|
+
// swiftlint:enable convenience_type
|
|
94
|
+
{% endif %}
|
|
95
|
+
{% else %}
|
|
96
|
+
// No string found
|
|
97
|
+
{% endif %}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
|
2
|
+
|
|
3
|
+
{% if tables.count > 0 %}
|
|
4
|
+
#import <Foundation/Foundation.h>
|
|
5
|
+
|
|
6
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
7
|
+
|
|
8
|
+
{% macro parametersBlock types %}{% filter removeNewlines:"leading" %}
|
|
9
|
+
{% for type in types %}
|
|
10
|
+
({% call paramTranslate type %})p{{ forloop.counter }}{{ " :" if not forloop.last }}
|
|
11
|
+
{% endfor %}
|
|
12
|
+
{% endfilter %}{% endmacro %}
|
|
13
|
+
{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %}
|
|
14
|
+
{% for type in types %}
|
|
15
|
+
p{{forloop.counter}}{{ ", " if not forloop.last }}
|
|
16
|
+
{% endfor %}
|
|
17
|
+
{% endfilter %}{% endmacro %}
|
|
18
|
+
{% macro paramTranslate swiftType %}
|
|
19
|
+
{% if swiftType == "Any" %}
|
|
20
|
+
id
|
|
21
|
+
{% elif swiftType == "CChar" %}
|
|
22
|
+
char
|
|
23
|
+
{% elif swiftType == "Float" %}
|
|
24
|
+
float
|
|
25
|
+
{% elif swiftType == "Int" %}
|
|
26
|
+
NSInteger
|
|
27
|
+
{% elif swiftType == "String" %}
|
|
28
|
+
id
|
|
29
|
+
{% elif swiftType == "UnsafePointer<CChar>" %}
|
|
30
|
+
char*
|
|
31
|
+
{% elif swiftType == "UnsafeRawPointer" %}
|
|
32
|
+
void*
|
|
33
|
+
{% else %}
|
|
34
|
+
objc-h.stencil is missing '{{swiftType}}'
|
|
35
|
+
{% endif %}
|
|
36
|
+
{% endmacro %}
|
|
37
|
+
{% macro emitOneMethod table item %}
|
|
38
|
+
{% for string in item.strings %}
|
|
39
|
+
{% if not param.noComments %}
|
|
40
|
+
// {{string.key}} --> "{{string.translation}}"
|
|
41
|
+
{% endif %}
|
|
42
|
+
{% if string.types %}
|
|
43
|
+
{% if string.types.count == 1 %}
|
|
44
|
+
+ (NSString*){{string.key|swiftIdentifier:"pretty"|lowerFirstWord}}WithValue:{% call parametersBlock string.types %};
|
|
45
|
+
{% else %}
|
|
46
|
+
+ (NSString*){{string.key|swiftIdentifier:"pretty"|lowerFirstWord}}WithValues:{% call parametersBlock string.types %};
|
|
47
|
+
{% endif %}
|
|
48
|
+
{% else %}
|
|
49
|
+
+ (NSString*){{string.key|swiftIdentifier:"pretty"|lowerFirstWord}};
|
|
50
|
+
{% endif %}
|
|
51
|
+
{% endfor %}
|
|
52
|
+
{% for child in item.children %}
|
|
53
|
+
{% call emitOneMethod table child %}
|
|
54
|
+
{% endfor %}
|
|
55
|
+
{% endmacro %}
|
|
56
|
+
{% for table in tables %}
|
|
57
|
+
@interface {{ table.name }} : NSObject
|
|
58
|
+
{% call emitOneMethod table.name table.levels %}
|
|
59
|
+
@end
|
|
60
|
+
|
|
61
|
+
{% endfor %}
|
|
62
|
+
|
|
63
|
+
NS_ASSUME_NONNULL_END
|
|
64
|
+
{% else %}
|
|
65
|
+
// No strings found
|
|
66
|
+
{% endif %}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
|
2
|
+
|
|
3
|
+
{% if tables.count > 0 %}
|
|
4
|
+
#import "{{ param.headerName|default:"Localizable.h" }}"
|
|
5
|
+
{% if not param.bundle %}
|
|
6
|
+
|
|
7
|
+
@interface BundleToken : NSObject
|
|
8
|
+
@end
|
|
9
|
+
|
|
10
|
+
@implementation BundleToken
|
|
11
|
+
@end
|
|
12
|
+
{% endif %}
|
|
13
|
+
|
|
14
|
+
#pragma clang diagnostic push
|
|
15
|
+
#pragma clang diagnostic ignored "-Wformat-security"
|
|
16
|
+
|
|
17
|
+
static NSString* tr(NSString *tableName, NSString *key, ...) {
|
|
18
|
+
NSBundle *bundle = {{param.bundle|default:"[NSBundle bundleForClass:BundleToken.class]"}};
|
|
19
|
+
NSString *format = [bundle localizedStringForKey:key value:nil table:tableName];
|
|
20
|
+
NSLocale *locale = [NSLocale currentLocale];
|
|
21
|
+
|
|
22
|
+
va_list args;
|
|
23
|
+
va_start(args, key);
|
|
24
|
+
NSString *result = [[NSString alloc] initWithFormat:format locale:locale arguments:args];
|
|
25
|
+
va_end(args);
|
|
26
|
+
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
#pragma clang diagnostic pop
|
|
30
|
+
|
|
31
|
+
{% macro parametersBlock types %}{% filter removeNewlines:"leading" %}
|
|
32
|
+
{% for type in types %}
|
|
33
|
+
({% call paramTranslate type %})p{{ forloop.counter }}{{ " :" if not forloop.last }}
|
|
34
|
+
{% endfor %}
|
|
35
|
+
{% endfilter %}{% endmacro %}
|
|
36
|
+
{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %}
|
|
37
|
+
{% for type in types %}
|
|
38
|
+
p{{forloop.counter}}{{ ", " if not forloop.last }}
|
|
39
|
+
{% endfor %}
|
|
40
|
+
{% endfilter %}{% endmacro %}
|
|
41
|
+
{% macro paramTranslate swiftType %}
|
|
42
|
+
{% if swiftType == "Any" %}
|
|
43
|
+
id
|
|
44
|
+
{% elif swiftType == "CChar" %}
|
|
45
|
+
char
|
|
46
|
+
{% elif swiftType == "Float" %}
|
|
47
|
+
float
|
|
48
|
+
{% elif swiftType == "Int" %}
|
|
49
|
+
NSInteger
|
|
50
|
+
{% elif swiftType == "String" %}
|
|
51
|
+
id
|
|
52
|
+
{% elif swiftType == "UnsafePointer<CChar>" %}
|
|
53
|
+
char*
|
|
54
|
+
{% elif swiftType == "UnsafeRawPointer" %}
|
|
55
|
+
void*
|
|
56
|
+
{% else %}
|
|
57
|
+
objc-m.stencil is missing '{{swiftType}}'
|
|
58
|
+
{% endif %}
|
|
59
|
+
{% endmacro %}
|
|
60
|
+
{% macro tableContents table item %}
|
|
61
|
+
{% for string in item.strings %}
|
|
62
|
+
{% if string.types %}
|
|
63
|
+
{% if string.types.count == 1 %}
|
|
64
|
+
+ (NSString*){{string.key|swiftIdentifier:"pretty"|lowerFirstWord}}WithValue:{% call parametersBlock string.types %}
|
|
65
|
+
{% else %}
|
|
66
|
+
+ (NSString*){{string.key|swiftIdentifier:"pretty"|lowerFirstWord}}WithValues:{% call parametersBlock string.types %}
|
|
67
|
+
{% endif %}
|
|
68
|
+
{
|
|
69
|
+
return tr(@"{{table}}", @"{{string.key}}", {% call argumentsBlock string.types %});
|
|
70
|
+
}
|
|
71
|
+
{% else %}
|
|
72
|
+
+ (NSString*){{string.key|swiftIdentifier:"pretty"|lowerFirstWord}} {
|
|
73
|
+
return tr(@"{{table}}", @"{{string.key}}");
|
|
74
|
+
}
|
|
75
|
+
{% endif %}
|
|
76
|
+
{% endfor %}
|
|
77
|
+
{% for child in item.children %}
|
|
78
|
+
{% call tableContents table child %}
|
|
79
|
+
{% endfor %}
|
|
80
|
+
{% endmacro %}
|
|
81
|
+
{% for table in tables %}
|
|
82
|
+
{% set tableName %}{{table.name|default:"Localized"}}{% endset %}
|
|
83
|
+
@implementation {{ tableName }} : NSObject
|
|
84
|
+
{% call tableContents table.name table.levels %}
|
|
85
|
+
@end
|
|
86
|
+
|
|
87
|
+
{% endfor %}
|
|
88
|
+
{% else %}
|
|
89
|
+
// No strings found
|
|
90
|
+
{% endif %}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// swiftlint:disable all
|
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
|
3
|
+
|
|
4
|
+
{% if tables.count > 0 %}
|
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
|
6
|
+
import Foundation
|
|
7
|
+
|
|
8
|
+
// swiftlint:disable superfluous_disable_command file_length implicit_return
|
|
9
|
+
|
|
10
|
+
// MARK: - Strings
|
|
11
|
+
|
|
12
|
+
{% macro parametersBlock types %}{% filter removeNewlines:"leading" %}
|
|
13
|
+
{% for type in types %}
|
|
14
|
+
{% if type == "String" %}
|
|
15
|
+
_ p{{forloop.counter}}: Any
|
|
16
|
+
{% else %}
|
|
17
|
+
_ p{{forloop.counter}}: {{type}}
|
|
18
|
+
{% endif %}
|
|
19
|
+
{{ ", " if not forloop.last }}
|
|
20
|
+
{% endfor %}
|
|
21
|
+
{% endfilter %}{% endmacro %}
|
|
22
|
+
{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %}
|
|
23
|
+
{% for type in types %}
|
|
24
|
+
{% if type == "String" %}
|
|
25
|
+
String(describing: p{{forloop.counter}})
|
|
26
|
+
{% elif type == "UnsafeRawPointer" %}
|
|
27
|
+
Int(bitPattern: p{{forloop.counter}})
|
|
28
|
+
{% else %}
|
|
29
|
+
p{{forloop.counter}}
|
|
30
|
+
{% endif %}
|
|
31
|
+
{{ ", " if not forloop.last }}
|
|
32
|
+
{% endfor %}
|
|
33
|
+
{% endfilter %}{% endmacro %}
|
|
34
|
+
{% macro recursiveBlock table item %}
|
|
35
|
+
{% for string in item.strings %}
|
|
36
|
+
{% if not param.noComments %}
|
|
37
|
+
/// {{string.translation}}
|
|
38
|
+
{% endif %}
|
|
39
|
+
{% if string.types %}
|
|
40
|
+
{{accessModifier}} static func {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String {
|
|
41
|
+
return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %})
|
|
42
|
+
}
|
|
43
|
+
{% elif param.lookupFunction %}
|
|
44
|
+
{# custom localization function is mostly used for in-app lang selection, so we want the loc to be recomputed at each call for those (hence the computed var) #}
|
|
45
|
+
{{accessModifier}} static var {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}: String { return {{enumName}}.tr("{{table}}", "{{string.key}}") }
|
|
46
|
+
{% else %}
|
|
47
|
+
{{accessModifier}} static let {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}")
|
|
48
|
+
{% endif %}
|
|
49
|
+
{% endfor %}
|
|
50
|
+
{% for child in item.children %}
|
|
51
|
+
|
|
52
|
+
{{accessModifier}} enum {{child.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
|
53
|
+
{% filter indent:2 %}{% call recursiveBlock table child %}{% endfilter %}
|
|
54
|
+
}
|
|
55
|
+
{% endfor %}
|
|
56
|
+
{% endmacro %}
|
|
57
|
+
// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
|
|
58
|
+
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
|
|
59
|
+
{% set enumName %}{{param.enumName|default:"L10n"}}{% endset %}
|
|
60
|
+
{{accessModifier}} enum {{enumName}} {
|
|
61
|
+
{% if tables.count > 1 or param.forceFileNameEnum %}
|
|
62
|
+
{% for table in tables %}
|
|
63
|
+
{{accessModifier}} enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
|
64
|
+
{% filter indent:2 %}{% call recursiveBlock table.name table.levels %}{% endfilter %}
|
|
65
|
+
}
|
|
66
|
+
{% endfor %}
|
|
67
|
+
{% else %}
|
|
68
|
+
{% call recursiveBlock tables.first.name tables.first.levels %}
|
|
69
|
+
{% endif %}
|
|
70
|
+
}
|
|
71
|
+
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
|
|
72
|
+
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces
|
|
73
|
+
|
|
74
|
+
// MARK: - Implementation Details
|
|
75
|
+
|
|
76
|
+
extension {{enumName}} {
|
|
77
|
+
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
|
|
78
|
+
{% if param.lookupFunction %}
|
|
79
|
+
let format = {{ param.lookupFunction }}(key, table)
|
|
80
|
+
{% else %}
|
|
81
|
+
let format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: nil, table: table)
|
|
82
|
+
{% endif %}
|
|
83
|
+
return String(format: format, locale: Locale.current, arguments: args)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
{% if not param.bundle and not param.lookupFunction %}
|
|
87
|
+
|
|
88
|
+
// swiftlint:disable convenience_type
|
|
89
|
+
private final class BundleToken {
|
|
90
|
+
static let bundle: Bundle = {
|
|
91
|
+
#if SWIFT_PACKAGE
|
|
92
|
+
return Bundle.module
|
|
93
|
+
#else
|
|
94
|
+
return Bundle(for: BundleToken.self)
|
|
95
|
+
#endif
|
|
96
|
+
}()
|
|
97
|
+
}
|
|
98
|
+
// swiftlint:enable convenience_type
|
|
99
|
+
{% endif %}
|
|
100
|
+
{% else %}
|
|
101
|
+
// No string found
|
|
102
|
+
{% endif %}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// swiftlint:disable all
|
|
2
|
+
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
|
|
3
|
+
|
|
4
|
+
{% if tables.count > 0 %}
|
|
5
|
+
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
|
|
6
|
+
import Foundation
|
|
7
|
+
|
|
8
|
+
// swiftlint:disable superfluous_disable_command file_length implicit_return
|
|
9
|
+
|
|
10
|
+
// MARK: - Strings
|
|
11
|
+
|
|
12
|
+
{% macro parametersBlock types %}{% filter removeNewlines:"leading" %}
|
|
13
|
+
{% for type in types %}
|
|
14
|
+
{% if type == "String" %}
|
|
15
|
+
_ p{{forloop.counter}}: Any
|
|
16
|
+
{% else %}
|
|
17
|
+
_ p{{forloop.counter}}: {{type}}
|
|
18
|
+
{% endif %}
|
|
19
|
+
{{ ", " if not forloop.last }}
|
|
20
|
+
{% endfor %}
|
|
21
|
+
{% endfilter %}{% endmacro %}
|
|
22
|
+
{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %}
|
|
23
|
+
{% for type in types %}
|
|
24
|
+
{% if type == "String" %}
|
|
25
|
+
String(describing: p{{forloop.counter}})
|
|
26
|
+
{% elif type == "UnsafeRawPointer" %}
|
|
27
|
+
Int(bitPattern: p{{forloop.counter}})
|
|
28
|
+
{% else %}
|
|
29
|
+
p{{forloop.counter}}
|
|
30
|
+
{% endif %}
|
|
31
|
+
{{ ", " if not forloop.last }}
|
|
32
|
+
{% endfor %}
|
|
33
|
+
{% endfilter %}{% endmacro %}
|
|
34
|
+
{% macro recursiveBlock table item %}
|
|
35
|
+
{% for string in item.strings %}
|
|
36
|
+
{% if not param.noComments %}
|
|
37
|
+
/// {{string.translation}}
|
|
38
|
+
{% endif %}
|
|
39
|
+
{% if string.types %}
|
|
40
|
+
{{accessModifier}} static func {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String {
|
|
41
|
+
return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %})
|
|
42
|
+
}
|
|
43
|
+
{% elif param.lookupFunction %}
|
|
44
|
+
{# custom localization function is mostly used for in-app lang selection, so we want the loc to be recomputed at each call for those (hence the computed var) #}
|
|
45
|
+
{{accessModifier}} static var {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}: String { return {{enumName}}.tr("{{table}}", "{{string.key}}") }
|
|
46
|
+
{% else %}
|
|
47
|
+
{{accessModifier}} static let {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}")
|
|
48
|
+
{% endif %}
|
|
49
|
+
{% endfor %}
|
|
50
|
+
{% for child in item.children %}
|
|
51
|
+
|
|
52
|
+
{{accessModifier}} enum {{child.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
|
53
|
+
{% filter indent:2 %}{% call recursiveBlock table child %}{% endfilter %}
|
|
54
|
+
}
|
|
55
|
+
{% endfor %}
|
|
56
|
+
{% endmacro %}
|
|
57
|
+
// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
|
|
58
|
+
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
|
|
59
|
+
{% set enumName %}{{param.enumName|default:"L10n"}}{% endset %}
|
|
60
|
+
{{accessModifier}} enum {{enumName}} {
|
|
61
|
+
{% if tables.count > 1 or param.forceFileNameEnum %}
|
|
62
|
+
{% for table in tables %}
|
|
63
|
+
{{accessModifier}} enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} {
|
|
64
|
+
{% filter indent:2 %}{% call recursiveBlock table.name table.levels %}{% endfilter %}
|
|
65
|
+
}
|
|
66
|
+
{% endfor %}
|
|
67
|
+
{% else %}
|
|
68
|
+
{% call recursiveBlock tables.first.name tables.first.levels %}
|
|
69
|
+
{% endif %}
|
|
70
|
+
}
|
|
71
|
+
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
|
|
72
|
+
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces
|
|
73
|
+
|
|
74
|
+
// MARK: - Implementation Details
|
|
75
|
+
|
|
76
|
+
extension {{enumName}} {
|
|
77
|
+
private static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
|
|
78
|
+
{% if param.lookupFunction %}
|
|
79
|
+
let format = {{ param.lookupFunction }}(key, table)
|
|
80
|
+
{% else %}
|
|
81
|
+
let format = {{param.bundle|default:"BundleToken.bundle"}}.localizedString(forKey: key, value: nil, table: table)
|
|
82
|
+
{% endif %}
|
|
83
|
+
return String(format: format, locale: Locale.current, arguments: args)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
{% if not param.bundle and not param.lookupFunction %}
|
|
87
|
+
|
|
88
|
+
// swiftlint:disable convenience_type
|
|
89
|
+
private final class BundleToken {
|
|
90
|
+
static let bundle: Bundle = {
|
|
91
|
+
#if SWIFT_PACKAGE
|
|
92
|
+
return Bundle.module
|
|
93
|
+
#else
|
|
94
|
+
return Bundle(for: BundleToken.self)
|
|
95
|
+
#endif
|
|
96
|
+
}()
|
|
97
|
+
}
|
|
98
|
+
// swiftlint:enable convenience_type
|
|
99
|
+
{% endif %}
|
|
100
|
+
{% else %}
|
|
101
|
+
// No string found
|
|
102
|
+
{% endif %}
|