flutter_polyglot_cli 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2677efcaed8b5c731998d960ad6b25f8ac26dfdc654b510d52bb44f57b31b97
4
- data.tar.gz: b41e5447f2cd83df7ae743a1e95458fb745be38caa956be4e61263225be14400
3
+ metadata.gz: '085f1f15e8e51d53a5a95e0d2f30a4e962e084a5a80620e5bfcd7fc16a286750'
4
+ data.tar.gz: 60d1ad3bb0faa8755453f0dbe3d7c894a91bf7b8223304f8ddf65a5b9b4a1b6d
5
5
  SHA512:
6
- metadata.gz: d1804575384e29434dfe41b0fdaeef2693eeb804f35a293b9307c7186ce76999c638aafef11e2b8e84191c54b3652d9c45f534046aed6d19ae3137e2dd317c13
7
- data.tar.gz: e084e1fbfa913eef571fd1234baea1acca3f0ab8e75bcad9926ce63e382291aee656dd701ee2b5938c3451fa4703b09d755ba2f64e8810fc3a2fe61d05040b33
6
+ metadata.gz: '0984d36f5bcb523a73589fedf7e296e49f5c491438224b4340fa8beb96cf1c313787d1b30e9044b478a70cf78278f9f65e9df746f2c220d503fbe2c1b804130a'
7
+ data.tar.gz: f4607e31c62590440ac7688fedcd2f6e75ad86536bb9f94151773204c8da847304a2cc887a41be32727541c452f7ee8d542e52e8e09a42d6fcbd3f70ccdfffbc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flutter_polyglot_cli (1.0.2)
4
+ flutter_polyglot_cli (1.1.0)
5
5
  activesupport
6
6
  commander
7
7
  json_api_client
@@ -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(project[:sourceFilesPath])
27
- write_localization_delegate(languages, project[:sourceFilesPath])
28
- write_localization_keys(translation_keys, languages, project[:sourceFilesPath], mandatory_language)
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 "#{project[:sourceFilesPath]}initialize_i18n"
31
- script = "flutter pub pub run intl_translation:generate_from_arb --output-dir=#{project[:sourceFilesPath]}initialize_i18n --no-use-deferred-loading #{project[:sourceFilesPath]}localization_keys.dart #{project[:path]}intl_*.arb"
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
- # josonaj command
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 = nil
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
@@ -17,7 +17,7 @@ module PolyglotFlutter
17
17
  import 'package:intl/intl.dart';
18
18
  import 'initialize_i18n/messages_all.dart';
19
19
 
20
- part 'localization_keys.dart';
20
+ part 'localization_strings.dart';
21
21
 
22
22
  // AUTO GENERATED FILE. DO NOT CHANGE.
23
23
  class Localization {
@@ -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
@@ -1,3 +1,3 @@
1
1
  module PolyglotFlutter
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  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.2
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-03-10 00:00:00.000000000 Z
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