flutter_polyglot_cli 1.0.1 → 1.1.3

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: fe67c3d215e3779b58be999c98160fd773e6cbdf096f64ba527b748cf00583cb
4
- data.tar.gz: 4228ba3ec5274785a205e5f2001a03a6096791bb4de21a1fd27db6aecef3044d
3
+ metadata.gz: ac7e7883a3c621ff867380522e0e9bb4199668caa84e46e79542c9399d0074b7
4
+ data.tar.gz: '00480177804db8de7604c7b930c51a114eb43b0147e7c66e1c53582d41b1df26'
5
5
  SHA512:
6
- metadata.gz: 7340d7ce57278b8fe76c894262ec7cacca2e684d6d1ced5909ef294129b7b2be7ce864b5a1580405ba4ac77f467aee811deafcf08c3b76129171a0c7ce329033
7
- data.tar.gz: 04f45e84f4ec7c28900475937a9b7b20ffffebddb91fa83bd9de6223a92ad3546a549aac0635426402bab1189ff8a6d721d888dfa0a7b9d22fe445f39b12c615
6
+ metadata.gz: 8d0c722a8e2805723af09afc7ec052e26bec49fc507ccc80a2dd73973afc9a3bb0428d5b2916226cf99555ba0b00dab32b1dd37d84f88241ba5a03a2f6622659
7
+ data.tar.gz: 8b35b592a2a744a3674a2c226c4326a2664a1f8d8517bcfbd208b1b883a62a29b00d416f66c22390d4c8b50ffdf647a7ebc367da7dbf67d67c6cd131747fbfc4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flutter_polyglot_cli (1.0.1)
4
+ flutter_polyglot_cli (1.1.3)
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.5)
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.12.2)
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.5)
77
+ tzinfo (1.2.7)
78
78
  thread_safe (~> 0.1)
79
79
  wisper (2.0.1)
80
- zeitwerk (2.2.0)
80
+ zeitwerk (2.3.1)
81
81
 
82
82
  PLATFORMS
83
83
  ruby
@@ -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://polyglot.infinum.co/api/v2/'
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*)/).each_with_index do |match, index|
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(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)
@@ -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
- 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 _].freeze
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
- "`#{name}`"
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 = 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.1'
2
+ VERSION = '1.1.3'
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.1
4
+ version: 1.1.3
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: 2020-03-03 00:00:00.000000000 Z
11
+ date: 2020-09-23 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: []