flutter_polyglot_cli 1.0.2 → 1.1.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/flutter_polyglot_cli.rb +1 -0
- data/lib/flutter_polyglot_cli/commands/pull.rb +17 -7
- data/lib/flutter_polyglot_cli/helpers/general.rb +24 -6
- 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 +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '085f1f15e8e51d53a5a95e0d2f30a4e962e084a5a80620e5bfcd7fc16a286750'
|
4
|
+
data.tar.gz: 60d1ad3bb0faa8755453f0dbe3d7c894a91bf7b8223304f8ddf65a5b9b4a1b6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0984d36f5bcb523a73589fedf7e296e49f5c491438224b4340fa8beb96cf1c313787d1b30e9044b478a70cf78278f9f65e9df746f2c220d503fbe2c1b804130a'
|
7
|
+
data.tar.gz: f4607e31c62590440ac7688fedcd2f6e75ad86536bb9f94151773204c8da847304a2cc887a41be32727541c452f7ee8d542e52e8e09a42d6fcbd3f70ccdfffbc
|
data/Gemfile.lock
CHANGED
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'
|
@@ -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)
|
@@ -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
|
@@ -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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maroje Marcelic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -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
|