flutter_polyglot_cli 1.0.2 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/lib/flutter_polyglot_cli.rb +1 -0
- data/lib/flutter_polyglot_cli/api/base.rb +1 -1
- data/lib/flutter_polyglot_cli/api/translation_key.rb +1 -1
- data/lib/flutter_polyglot_cli/commands/pull.rb +17 -7
- data/lib/flutter_polyglot_cli/helpers/general.rb +31 -13
- data/lib/flutter_polyglot_cli/serializers/localizations/localization_delegate_serializer.rb +1 -4
- data/lib/flutter_polyglot_cli/serializers/localizations/localization_serializer.rb +1 -1
- data/lib/flutter_polyglot_cli/serializers/localizations/localization_strings_serializer.rb +36 -0
- data/lib/flutter_polyglot_cli/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5dfe5a15d8facf1e7be9af01f8d40f3f8655af091c3bbcb25482ba99e98ed75
|
4
|
+
data.tar.gz: 00d9f1c459aba1ca954b96171a4e554143ec4f765d90cb666fa22879ffcd47e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '073791e15366cc13996725f540078b383fbfcb4d09c4c4f6e4657f8d35583a8632e756389e1974f4c144a7a18cc9a9f5d896c698a4943af1883541533567a31e'
|
7
|
+
data.tar.gz: 43773c358c1719f751b93b61f03a44ce1c4e589fb8060decfbe5a5e18fd02d1f596d6e1d4c5eb83d7ef0aaa1dfeb55b2adcef5eafa4193ea231266343ebbf843
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
flutter_polyglot_cli (1.
|
4
|
+
flutter_polyglot_cli (1.1.4)
|
5
5
|
activesupport
|
6
6
|
commander
|
7
7
|
json_api_client
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
coderay (1.1.2)
|
29
29
|
commander (4.4.7)
|
30
30
|
highline (~> 2.0.0)
|
31
|
-
concurrent-ruby (1.1.
|
31
|
+
concurrent-ruby (1.1.6)
|
32
32
|
equatable (0.6.1)
|
33
33
|
faraday (0.17.0)
|
34
34
|
multipart-post (>= 1.2, < 3)
|
@@ -45,7 +45,7 @@ GEM
|
|
45
45
|
faraday_middleware (~> 0.9)
|
46
46
|
rack (>= 0.2)
|
47
47
|
method_source (0.9.2)
|
48
|
-
minitest (5.
|
48
|
+
minitest (5.14.1)
|
49
49
|
multipart-post (2.1.1)
|
50
50
|
necromancer (0.5.0)
|
51
51
|
osx_keychain (1.0.2)
|
@@ -74,10 +74,10 @@ GEM
|
|
74
74
|
tty-screen (~> 0.7)
|
75
75
|
wisper (~> 2.0.0)
|
76
76
|
tty-screen (0.7.0)
|
77
|
-
tzinfo (1.2.
|
77
|
+
tzinfo (1.2.7)
|
78
78
|
thread_safe (~> 0.1)
|
79
79
|
wisper (2.0.1)
|
80
|
-
zeitwerk (2.
|
80
|
+
zeitwerk (2.3.1)
|
81
81
|
|
82
82
|
PLATFORMS
|
83
83
|
ruby
|
data/lib/flutter_polyglot_cli.rb
CHANGED
@@ -28,6 +28,7 @@ require 'flutter_polyglot_cli/serializers/localizations/loc_serializer'
|
|
28
28
|
require 'flutter_polyglot_cli/serializers/localizations/localization_serializer'
|
29
29
|
require 'flutter_polyglot_cli/serializers/localizations/localization_delegate_serializer'
|
30
30
|
require 'flutter_polyglot_cli/serializers/localizations/localization_keys_serializer'
|
31
|
+
require 'flutter_polyglot_cli/serializers/localizations/localization_strings_serializer'
|
31
32
|
|
32
33
|
# Commands
|
33
34
|
require 'flutter_polyglot_cli/commands/login'
|
@@ -3,7 +3,7 @@ module PolyglotFlutter
|
|
3
3
|
class Base < JsonApiClient::Resource
|
4
4
|
extend PolyglotFlutter::Helper::Depaginate
|
5
5
|
|
6
|
-
self.site = 'https://
|
6
|
+
self.site = 'https://infinum.polyglothq.com/api/v2/'
|
7
7
|
|
8
8
|
def self.token(token)
|
9
9
|
self.connection_options = { headers: { 'X-Auth-Token' => token } }
|
@@ -21,7 +21,7 @@ module PolyglotFlutter
|
|
21
21
|
|
22
22
|
def convert_aruments(translation)
|
23
23
|
new_translation = translation
|
24
|
-
translation.scan(/(%\w
|
24
|
+
translation.scan(/(%\w)/).each_with_index do |match, index|
|
25
25
|
new_translation = new_translation.sub(match[0], '{arg' + String(index) + '}')
|
26
26
|
end
|
27
27
|
|
@@ -22,16 +22,18 @@ module PolyglotFlutter
|
|
22
22
|
languages = pull_languages(project_id)
|
23
23
|
translation_keys = pull_translation_keys(project_id)
|
24
24
|
|
25
|
+
directory_path = project[:sourceFilesPath]
|
25
26
|
write_translations(translation_keys, languages, project[:path])
|
26
|
-
write_localization(
|
27
|
-
write_localization_delegate(languages,
|
28
|
-
write_localization_keys(translation_keys, languages,
|
27
|
+
write_localization(directory_path)
|
28
|
+
write_localization_delegate(languages, directory_path)
|
29
|
+
write_localization_keys(translation_keys, languages, directory_path, mandatory_language)
|
29
30
|
|
30
|
-
FileUtils.mkdir_p "#{
|
31
|
-
script = "flutter pub pub run intl_translation:generate_from_arb --output-dir=#{
|
31
|
+
FileUtils.mkdir_p "#{directory_path}initialize_i18n"
|
32
|
+
script = "flutter pub pub run intl_translation:generate_from_arb --output-dir=#{directory_path}initialize_i18n --no-use-deferred-loading #{project[:sourceFilesPath]}localization_keys.dart #{project[:path]}intl_*.arb"
|
32
33
|
`#{script}`
|
33
|
-
|
34
|
-
#
|
34
|
+
|
35
|
+
File.delete("#{directory_path}localization_keys.dart") if File.exist?("#{directory_path}localization_keys.dart")
|
36
|
+
write_localization_strings(translation_keys, languages, directory_path, mandatory_language)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -70,6 +72,14 @@ module PolyglotFlutter
|
|
70
72
|
.save(translations_path)
|
71
73
|
end
|
72
74
|
|
75
|
+
def write_localization_strings(translation_keys, languages, translations_path, mandatory_language)
|
76
|
+
return if translations_path.to_s.empty?
|
77
|
+
|
78
|
+
PolyglotFlutter::Serializer::Localization::LocalizationStrings
|
79
|
+
.new(languages: languages, translation_keys: translation_keys, mandatory_language: mandatory_language)
|
80
|
+
.save(translations_path)
|
81
|
+
end
|
82
|
+
|
73
83
|
# Pulling data
|
74
84
|
|
75
85
|
def pull_languages(project_id)
|
@@ -2,12 +2,12 @@ module PolyglotFlutter
|
|
2
2
|
module Helper
|
3
3
|
module General
|
4
4
|
ESCAPE_KEYWORDS = %w[abstract as assert async await break case
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
catch class const continue covariant default deferred do
|
6
|
+
else enum export extends external factory false final
|
7
|
+
finally for Function get hide if import in interface
|
8
|
+
is library mixin new null on operator part rethrow return
|
9
|
+
set static super switch sync this throw true try typedef var
|
10
|
+
void while with yield _]
|
11
11
|
def token
|
12
12
|
@token ||= PolyglotFlutter::IO::Token.read
|
13
13
|
if @token.to_s.empty?
|
@@ -74,7 +74,7 @@ module PolyglotFlutter
|
|
74
74
|
def escape_keyword_if_needed(name)
|
75
75
|
return name unless ESCAPE_KEYWORDS.include? name
|
76
76
|
|
77
|
-
"
|
77
|
+
"#{name}_"
|
78
78
|
end
|
79
79
|
|
80
80
|
def generate_locales(languages)
|
@@ -84,12 +84,7 @@ module PolyglotFlutter
|
|
84
84
|
|
85
85
|
def generate_localization_keys(languages, translation_keys, mandatory_language)
|
86
86
|
result_string = ''
|
87
|
-
language =
|
88
|
-
languages.each do |lang|
|
89
|
-
if lang['locale'].split('_').first == mandatory_language
|
90
|
-
language = lang
|
91
|
-
end
|
92
|
-
end
|
87
|
+
language = find_app_language(languages, mandatory_language)
|
93
88
|
|
94
89
|
dict = extract_translations(translation_keys, language)
|
95
90
|
dict.each do |key, value|
|
@@ -128,6 +123,29 @@ module PolyglotFlutter
|
|
128
123
|
locale_list = locale_names.each.map { |value| "AppLocales.#{value}" }.join(', ')
|
129
124
|
result_string += "\n\tstatic List<Locale> get values => <Locale>[#{locale_list}];"
|
130
125
|
end
|
126
|
+
|
127
|
+
def generate_strings(languages, translation_keys, mandatory_language)
|
128
|
+
result_string = ''
|
129
|
+
language = find_app_language(languages, mandatory_language)
|
130
|
+
|
131
|
+
dict = extract_translations(translation_keys, language)
|
132
|
+
dict.each do |key, value|
|
133
|
+
next if value.nil?
|
134
|
+
|
135
|
+
clean_var_name = clean_variable_name(key)
|
136
|
+
result_string += "\t#{clean_var_name},\n"
|
137
|
+
end
|
138
|
+
|
139
|
+
result_string
|
140
|
+
end
|
141
|
+
|
142
|
+
def find_app_language(languages, mandatory_language)
|
143
|
+
languages.each do |lang|
|
144
|
+
if lang['locale'].split('_').first == mandatory_language
|
145
|
+
return lang
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
131
149
|
end
|
132
150
|
end
|
133
151
|
end
|
@@ -26,10 +26,7 @@ class LocalizationDelegate extends LocalizationsDelegate<Localization> {
|
|
26
26
|
bool isSupported(Locale locale) => <String><%= generate_locales(languages) %>.contains(locale.languageCode);
|
27
27
|
|
28
28
|
@override
|
29
|
-
Future<Localization> load(Locale locale)
|
30
|
-
Localization.load(locale);
|
31
|
-
return SynchronousFuture<Localization>(Localization(locale.languageCode));
|
32
|
-
}
|
29
|
+
Future<Localization> load(Locale locale) async => SynchronousFuture<Localization>(await Localization.load(locale));
|
33
30
|
|
34
31
|
@override
|
35
32
|
bool shouldReload(LocalizationDelegate old) => false;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'loc_serializer'
|
2
|
+
|
3
|
+
module PolyglotFlutter
|
4
|
+
module Serializer
|
5
|
+
module Localization
|
6
|
+
class LocalizationStrings < Base
|
7
|
+
def save(sources_path)
|
8
|
+
FileUtils.mkdir_p sources_path unless File.exist? sources_path
|
9
|
+
output_path = File.join(sources_path, 'localization_strings.dart')
|
10
|
+
File.write(output_path, render)
|
11
|
+
end
|
12
|
+
|
13
|
+
def template
|
14
|
+
<<~TEMPLATE
|
15
|
+
part of 'localization.dart';
|
16
|
+
|
17
|
+
// AUTO GENERATED FILE. DO NOT CHANGE.
|
18
|
+
enum Strings {
|
19
|
+
<%= generate_strings(languages, translation_keys, mandatory_language) %>}
|
20
|
+
|
21
|
+
extension StringsValue on Strings {
|
22
|
+
String value() => toString().split('.').last;
|
23
|
+
|
24
|
+
String localized({BuildContext context, List<Object> args}) {
|
25
|
+
if (context != null) {
|
26
|
+
Localizations.of<Localization>(context, Localization);
|
27
|
+
}
|
28
|
+
return Intl.message('', name: value(), args: args);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
TEMPLATE
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flutter_polyglot_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maroje Marcelic
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
description:
|
125
|
+
description:
|
126
126
|
email:
|
127
127
|
- maroje.marcelic@infinum.com
|
128
128
|
executables:
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/flutter_polyglot_cli/serializers/localizations/localization_delegate_serializer.rb
|
162
162
|
- lib/flutter_polyglot_cli/serializers/localizations/localization_keys_serializer.rb
|
163
163
|
- lib/flutter_polyglot_cli/serializers/localizations/localization_serializer.rb
|
164
|
+
- lib/flutter_polyglot_cli/serializers/localizations/localization_strings_serializer.rb
|
164
165
|
- lib/flutter_polyglot_cli/serializers/translations/translations_serializer.rb
|
165
166
|
- lib/flutter_polyglot_cli/version.rb
|
166
167
|
homepage: https://github.com/infinum/flutter-polyglot-cli
|
@@ -168,7 +169,7 @@ licenses:
|
|
168
169
|
- MIT
|
169
170
|
metadata:
|
170
171
|
allowed_push_host: https://rubygems.org
|
171
|
-
post_install_message:
|
172
|
+
post_install_message:
|
172
173
|
rdoc_options: []
|
173
174
|
require_paths:
|
174
175
|
- lib
|
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
185
|
version: '0'
|
185
186
|
requirements: []
|
186
187
|
rubygems_version: 3.0.6
|
187
|
-
signing_key:
|
188
|
+
signing_key:
|
188
189
|
specification_version: 4
|
189
190
|
summary: A CLI for pulling polyglot translations and generating Flutter Source Files
|
190
191
|
test_files: []
|