ios_polyglot_cli 2.6.3 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +44 -53
- data/README.md +21 -0
- data/lib/ios_polyglot_cli/commands/pull.rb +98 -5
- data/lib/ios_polyglot_cli/serializers/sources/sources_serializer_swift.rb +5 -3
- data/lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_case.rb +10 -1
- data/lib/ios_polyglot_cli/serializers/sources/swift_helpers/translation_enum.rb +4 -2
- data/lib/ios_polyglot_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4be5207295850180cb1f52a18f3506470d04835c814f149785521ddc00e1b6e0
|
4
|
+
data.tar.gz: 5b4b4b0747330f635752b940098d914929185e5980c3b38e0b785b7bfa819596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c103fce180c3bc47dd740b54e09eff019ee3a1fe5323bb89b8231e5f4c02350dc50a7f631f0b8bcee0d1e5c6e420a975f8988b03abcb04957a02b5e18ed10a9
|
7
|
+
data.tar.gz: 9cc61da2a0e77ebaaede23ed13599673ce96c59385de3cf80f5644ac8de6f87efae589208f51cc68b5ac46759333fd34fec5641c7496877501afb7bc7adf8a10
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ios_polyglot_cli (2.
|
4
|
+
ios_polyglot_cli (2.7.0)
|
5
5
|
activesupport
|
6
6
|
commander
|
7
7
|
json_api_client
|
@@ -11,69 +11,58 @@ PATH
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
activemodel (7.
|
15
|
-
activesupport (= 7.
|
16
|
-
activesupport (7.
|
14
|
+
activemodel (7.2.2)
|
15
|
+
activesupport (= 7.2.2)
|
16
|
+
activesupport (7.2.2)
|
17
17
|
base64
|
18
|
+
benchmark (>= 0.3)
|
18
19
|
bigdecimal
|
19
|
-
concurrent-ruby (~> 1.0, >= 1.
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
20
21
|
connection_pool (>= 2.2.5)
|
21
22
|
drb
|
22
23
|
i18n (>= 1.6, < 2)
|
24
|
+
logger (>= 1.4.2)
|
23
25
|
minitest (>= 5.1)
|
24
|
-
|
25
|
-
tzinfo (~> 2.0)
|
26
|
-
addressable (2.8.
|
27
|
-
public_suffix (>= 2.0.2, <
|
26
|
+
securerandom (>= 0.3)
|
27
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
28
|
+
addressable (2.8.7)
|
29
|
+
public_suffix (>= 2.0.2, < 7.0)
|
28
30
|
base64 (0.2.0)
|
29
|
-
|
31
|
+
benchmark (0.4.0)
|
32
|
+
bigdecimal (3.1.8)
|
30
33
|
byebug (11.1.3)
|
31
34
|
coderay (1.1.3)
|
32
35
|
commander (5.0.0)
|
33
36
|
highline (~> 3.0.0)
|
34
|
-
concurrent-ruby (1.
|
37
|
+
concurrent-ruby (1.3.4)
|
35
38
|
connection_pool (2.4.1)
|
36
39
|
drb (2.2.1)
|
37
|
-
faraday (
|
38
|
-
faraday-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
faraday
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
faraday-rack (~> 1.0)
|
47
|
-
faraday-retry (~> 1.0)
|
48
|
-
ruby2_keywords (>= 0.0.4)
|
49
|
-
faraday-em_http (1.0.0)
|
50
|
-
faraday-em_synchrony (1.0.0)
|
51
|
-
faraday-excon (1.1.0)
|
52
|
-
faraday-httpclient (1.0.1)
|
53
|
-
faraday-multipart (1.0.4)
|
54
|
-
multipart-post (~> 2)
|
55
|
-
faraday-net_http (1.0.1)
|
56
|
-
faraday-net_http_persistent (1.2.0)
|
57
|
-
faraday-patron (1.0.0)
|
58
|
-
faraday-rack (1.0.0)
|
59
|
-
faraday-retry (1.0.3)
|
60
|
-
faraday_middleware (1.2.0)
|
61
|
-
faraday (~> 1.0)
|
40
|
+
faraday (2.12.1)
|
41
|
+
faraday-net_http (>= 2.0, < 3.5)
|
42
|
+
json
|
43
|
+
logger
|
44
|
+
faraday-gzip (2.0.1)
|
45
|
+
faraday (>= 1.0)
|
46
|
+
zlib (~> 3.0)
|
47
|
+
faraday-net_http (3.4.0)
|
48
|
+
net-http (>= 0.5.0)
|
62
49
|
highline (3.0.1)
|
63
|
-
i18n (1.14.
|
50
|
+
i18n (1.14.6)
|
64
51
|
concurrent-ruby (~> 1.0)
|
65
|
-
|
66
|
-
|
67
|
-
|
52
|
+
json (2.8.2)
|
53
|
+
json_api_client (1.23.0)
|
54
|
+
activemodel (>= 6.0.0)
|
55
|
+
activesupport (>= 6.0.0)
|
68
56
|
addressable (~> 2.2)
|
69
|
-
faraday (>=
|
70
|
-
|
57
|
+
faraday (>= 1.10, < 3.0)
|
58
|
+
faraday-gzip (>= 1.0, < 3.0)
|
71
59
|
rack (>= 0.2)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
60
|
+
logger (1.6.1)
|
61
|
+
method_source (1.1.0)
|
62
|
+
minitest (5.25.2)
|
63
|
+
net-http (0.5.0)
|
64
|
+
uri
|
65
|
+
parallel (1.26.3)
|
77
66
|
pastel (0.8.0)
|
78
67
|
tty-color (~> 0.5)
|
79
68
|
pry (0.14.2)
|
@@ -82,10 +71,10 @@ GEM
|
|
82
71
|
pry-byebug (3.10.1)
|
83
72
|
byebug (~> 11.0)
|
84
73
|
pry (>= 0.13, < 0.15)
|
85
|
-
public_suffix (
|
86
|
-
rack (3.
|
87
|
-
rake (13.1
|
88
|
-
|
74
|
+
public_suffix (6.0.1)
|
75
|
+
rack (3.1.8)
|
76
|
+
rake (13.2.1)
|
77
|
+
securerandom (0.3.2)
|
89
78
|
tty-color (0.6.0)
|
90
79
|
tty-cursor (0.7.1)
|
91
80
|
tty-prompt (0.23.1)
|
@@ -98,10 +87,12 @@ GEM
|
|
98
87
|
tty-screen (0.8.2)
|
99
88
|
tzinfo (2.0.6)
|
100
89
|
concurrent-ruby (~> 1.0)
|
90
|
+
uri (1.0.2)
|
101
91
|
wisper (2.0.1)
|
92
|
+
zlib (3.2.0)
|
102
93
|
|
103
94
|
PLATFORMS
|
104
|
-
arm64-darwin-
|
95
|
+
arm64-darwin-24
|
105
96
|
|
106
97
|
DEPENDENCIES
|
107
98
|
bundler
|
@@ -110,4 +101,4 @@ DEPENDENCIES
|
|
110
101
|
rake
|
111
102
|
|
112
103
|
BUNDLED WITH
|
113
|
-
2.3.
|
104
|
+
2.3.3
|
data/README.md
CHANGED
@@ -84,6 +84,27 @@ projects:
|
|
84
84
|
sourceFilesPath: ./ProjectTwo/Sources/Translations/
|
85
85
|
```
|
86
86
|
|
87
|
+
### Documentation Language Configuration
|
88
|
+
|
89
|
+
To enable `polyglot` to document translations in a specific language, add a new flag called `documentationLanguage` to your `polyglot.yaml` file under the project requiring documentation. The `documentationLanguage` value should follow a locale format (e.g., `en_GB` for `en`).
|
90
|
+
|
91
|
+
When running `polyglot`, it will attempt to find an exact match for the specified locale. If no match is found, `polyglot` will **abort the pull operation** and output a list of all supported language variations to the console for reference.
|
92
|
+
|
93
|
+
If the `documentationLanguage` flag is not set in the `polyglot.yaml` file, `polyglot` will default to using the `defaultLanguage`. If the `defaultLanguage` is also unavailable, `polyglot` will default to the first language listed among the available languages for documentation.
|
94
|
+
|
95
|
+
|
96
|
+
#### Example:
|
97
|
+
```yaml
|
98
|
+
# polyglot.yaml
|
99
|
+
...
|
100
|
+
:projects:
|
101
|
+
- :id: '[projectId]'
|
102
|
+
:path: "[translationPath]"
|
103
|
+
:sourceFilesPath: "[sourceFilePath]"
|
104
|
+
:documentationLanguage: "en_GB"
|
105
|
+
...
|
106
|
+
```
|
107
|
+
|
87
108
|
### Legacy projects
|
88
109
|
|
89
110
|
New style translations will create file names `en_US.strings` for example, and some old projects still use old naming in the style of `en.strings`. To get around this issue, you either need to migrate your project to use the new naming (be mindful of the existing app's settings), or add this line under your path value:
|
@@ -16,8 +16,9 @@ module PolyglotIos
|
|
16
16
|
|
17
17
|
def call
|
18
18
|
prompt.say("Fetching translations...")
|
19
|
-
generate_translations(project_configs, programming_language, skip_writing_language_struct)
|
20
|
-
|
19
|
+
if generate_translations(project_configs, programming_language, skip_writing_language_struct)
|
20
|
+
success("Translations successfully generated!")
|
21
|
+
end
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
@@ -25,17 +26,98 @@ module PolyglotIos
|
|
25
26
|
def generate_translations(projects, programming_language, skip_writing_language_struct)
|
26
27
|
projects.each do |project|
|
27
28
|
project_id = project[:id]
|
29
|
+
project_fetched = pull_project(project_id)
|
28
30
|
languages = pull_languages(project_id)
|
29
31
|
translation_keys = pull_translation_keys(project_id)
|
32
|
+
documentation_language = project[:documentationLanguage]
|
33
|
+
default_language = project_fetched[0][:default_language_id]
|
34
|
+
|
35
|
+
translations = {}
|
36
|
+
|
37
|
+
if !documentation_language.nil?
|
38
|
+
language = find_documentation_language(documentation_language, languages)
|
39
|
+
if language.nil?
|
40
|
+
prompt.say("ABORTED with reason: DocumentationLanguage must be correctly defined in the project configuration")
|
41
|
+
return {}
|
42
|
+
end
|
43
|
+
|
44
|
+
prompt.say("Found DocumentationLanguage: #{language[:name]}, documenting...")
|
45
|
+
translations = extract_translations_for_language(translation_keys, language)
|
46
|
+
|
47
|
+
if translations.empty?
|
48
|
+
prompt.say("No translations found for DocumentationLanguage: #{language[:name]}, ABORTING!!!")
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
else
|
52
|
+
language = find_default_language(default_language, languages)
|
53
|
+
if !language.nil?
|
54
|
+
translations = extract_translations_for_language(translation_keys, language)
|
55
|
+
end
|
56
|
+
|
57
|
+
if translations.empty?
|
58
|
+
translations = {}
|
59
|
+
end
|
60
|
+
end
|
30
61
|
|
31
62
|
write_translations(translation_keys, languages, project[:path], project[:useOldNaming])
|
63
|
+
|
32
64
|
if !skip_writing_language_struct
|
33
65
|
write_languages(languages, project[:sourceFilesPath], programming_language)
|
34
66
|
end
|
35
|
-
|
67
|
+
|
68
|
+
write_translation_sources(translation_keys, project[:sourceFilesPath], programming_language, translations)
|
69
|
+
return true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def extract_translations_for_language(translation_keys, language)
|
74
|
+
return PolyglotIos::Serializer::Translation
|
75
|
+
.extract_translations(translation_keys, language)
|
76
|
+
end
|
77
|
+
|
78
|
+
def find_language_by_locale_prefix(languages, locale_prefix)
|
79
|
+
languages.find do |language|
|
80
|
+
language[:locale].start_with?(locale_prefix)
|
36
81
|
end
|
37
82
|
end
|
38
83
|
|
84
|
+
def find_documentation_language(documentation_language, languages)
|
85
|
+
|
86
|
+
#find documentation language
|
87
|
+
language = find_language_by_locale_prefix(languages, documentation_language)
|
88
|
+
|
89
|
+
if language.nil?
|
90
|
+
prompt.say("===========================")
|
91
|
+
prompt.say("ERROR: Documentation language not found with prefix: = #{documentation_language}")
|
92
|
+
prompt.say("Possible language locales are: \n")
|
93
|
+
|
94
|
+
languages.each do |language|
|
95
|
+
prompt.say("#{language[:name]} => #{language[:locale]}")
|
96
|
+
end
|
97
|
+
prompt.say("===========================")
|
98
|
+
return nil
|
99
|
+
end
|
100
|
+
|
101
|
+
return language
|
102
|
+
end
|
103
|
+
|
104
|
+
def find_default_language(default_language, languages)
|
105
|
+
#find default language
|
106
|
+
prompt.say("Find default_language with id: = #{default_language}")
|
107
|
+
language = languages.find { |language| language[:id] == default_language }
|
108
|
+
if language.nil?
|
109
|
+
prompt.say('Default language not found using first language')
|
110
|
+
# use first language
|
111
|
+
language = languages[0]
|
112
|
+
prompt.say('Using first language')
|
113
|
+
else
|
114
|
+
prompt.say('Using default language')
|
115
|
+
end
|
116
|
+
|
117
|
+
return language
|
118
|
+
end
|
119
|
+
|
120
|
+
|
39
121
|
# Serializing data
|
40
122
|
|
41
123
|
def write_translations(translation_keys, languages, translations_path, use_old_naming = false)
|
@@ -57,13 +139,16 @@ module PolyglotIos
|
|
57
139
|
serializer.new(languages).save(sources_path)
|
58
140
|
end
|
59
141
|
|
60
|
-
def write_translation_sources(translation_keys, sources_path, programming_language)
|
142
|
+
def write_translation_sources(translation_keys, sources_path, programming_language, translations)
|
61
143
|
return if sources_path.to_s.empty?
|
62
144
|
case programming_language.downcase
|
63
145
|
when "swift"
|
64
146
|
serializer = PolyglotIos::Serializer::Source::Swift
|
147
|
+
|
148
|
+
prompt.say("pull::write_translation_sources")
|
149
|
+
|
65
150
|
serializer
|
66
|
-
.new(translation_keys)
|
151
|
+
.new(translation_keys, translations)
|
67
152
|
.save(sources_path)
|
68
153
|
end
|
69
154
|
end
|
@@ -78,6 +163,14 @@ module PolyglotIos
|
|
78
163
|
@option_site_url = @options.__hash__.fetch(:url, nil) || url
|
79
164
|
end
|
80
165
|
|
166
|
+
def pull_project(project_id)
|
167
|
+
PolyglotIos::Resource::Project
|
168
|
+
.api_url(option_site_url)
|
169
|
+
.token(option_token)
|
170
|
+
.find(project_id)
|
171
|
+
|
172
|
+
end
|
173
|
+
|
81
174
|
def pull_languages(project_id)
|
82
175
|
PolyglotIos::Resource::Language
|
83
176
|
.api_url(option_site_url)
|
@@ -7,8 +7,9 @@ module PolyglotIos
|
|
7
7
|
class Swift
|
8
8
|
include ERB::Util
|
9
9
|
|
10
|
-
def initialize(translation_keys)
|
10
|
+
def initialize(translation_keys, translations)
|
11
11
|
@translation_keys = translation_keys
|
12
|
+
@translations = translations
|
12
13
|
end
|
13
14
|
|
14
15
|
def render()
|
@@ -58,8 +59,9 @@ TEMPLATE
|
|
58
59
|
@translation_keys.each do |translation_key|
|
59
60
|
key_name = translation_key.name
|
60
61
|
next if key_name.nil?
|
61
|
-
components = key_name.split(".")
|
62
|
-
|
62
|
+
components = key_name.split(".")
|
63
|
+
translation = @translations[key_name]
|
64
|
+
root_enum.insert(components, key_name, translation)
|
63
65
|
end
|
64
66
|
|
65
67
|
return root_enum
|
@@ -6,10 +6,12 @@ module PolyglotIos
|
|
6
6
|
|
7
7
|
attr_accessor :name
|
8
8
|
attr_accessor :value
|
9
|
+
attr_accessor :translation
|
9
10
|
|
10
|
-
def initialize(name, value)
|
11
|
+
def initialize(name, value, translation = nil)
|
11
12
|
@name = name
|
12
13
|
@value = value
|
14
|
+
@translation = translation
|
13
15
|
end
|
14
16
|
|
15
17
|
def serialized()
|
@@ -17,6 +19,13 @@ module PolyglotIos
|
|
17
19
|
"public static let #{clean_name}: Strings = \"#{value}\""
|
18
20
|
end
|
19
21
|
|
22
|
+
def serializedDefaultTranslation()
|
23
|
+
if !translation.nil?
|
24
|
+
return "/// Value: #{translation}"
|
25
|
+
end
|
26
|
+
return ""
|
27
|
+
end
|
28
|
+
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
@@ -15,11 +15,11 @@ module PolyglotIos
|
|
15
15
|
@child_enums = []
|
16
16
|
end
|
17
17
|
|
18
|
-
def insert(components, key_name)
|
18
|
+
def insert(components, key_name, translation)
|
19
19
|
if components.count > 1
|
20
20
|
insert_to_nested_enum(components, key_name)
|
21
21
|
elsif components.count == 1
|
22
|
-
translation_case = TranslationCase.new(components.first, key_name)
|
22
|
+
translation_case = TranslationCase.new(components.first, key_name, translation)
|
23
23
|
translations.push(translation_case)
|
24
24
|
end
|
25
25
|
end
|
@@ -39,6 +39,8 @@ module PolyglotIos
|
|
39
39
|
.sort_by { |translation| translation.name.downcase }
|
40
40
|
.each do |translation|
|
41
41
|
output
|
42
|
+
.concat(indent(indent_level + 1, translation.serializedDefaultTranslation()))
|
43
|
+
.concat("\n")
|
42
44
|
.concat(indent(indent_level + 1, translation.serialized()))
|
43
45
|
.concat("\n")
|
44
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ios_polyglot_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filip Gulan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|