ad_localize 3.2.0 → 3.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b67ba9ff725d7fbf76fd0d680b07573648ee51966fdbb8429e6a26a764fc5563
4
- data.tar.gz: 7ce5a08e27d50cbedd1ca1f4ffac9af1817ee8c38e97eb088d6dd7bc6d8ec5d0
3
+ metadata.gz: 7b8f651b78afaf45c264c489854182f16644ce5e6b633f65a0f35ea5c3b51782
4
+ data.tar.gz: 32760e7c15e78ebe5f874e1a763023ec315effb651b5e07bc1144314d1fe3a9a
5
5
  SHA512:
6
- metadata.gz: 0eb0c873e0d27062cc4291baab1c330224997ef3085b7474424c50d0dff8f089c40ae9f668e91f5769ce6d7c69431892435ee65a5a3073815ddbbe9bcde539be
7
- data.tar.gz: 7998404ef9a406c7421117d666fae0c3aa8bfa0f55a5fe4e5a207a7c6bc01d370de3158a47910d47205d73a266a35109ca819cf114b572fe848061454e5fad29
6
+ metadata.gz: b67bcb815f92a4e17ad8ebc88dbf2f65115a43e43fa2e6fbe83755b409167c24201d06d4cacccc5ff7c2be42366a21abca3603f07f50fef5c4af92cbab5b17a6
7
+ data.tar.gz: 7ea60174aabe27f2146396cf573d1ac0dd90f09b26dc7b8fb5c3158d88d178df0be7bf283438b7ac8b5870c81a30950d985ad724f1a8a71b63421400d9189875
@@ -0,0 +1,20 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v1
12
+ - name: Set up Ruby 2.6
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6.x
16
+ - name: Build and test with Rake
17
+ run: |
18
+ gem install bundler
19
+ bundle install --jobs 4 --retry 3
20
+ bundle exec rake
data/README.md CHANGED
@@ -177,6 +177,41 @@ Every key that matches the following formats will be added to the `InfoPlist.str
177
177
 
178
178
  Source: https://developer.apple.com/documentation/bundleresources/information_property_list
179
179
 
180
+ ## Adaptive strings
181
+
182
+ _Only for iOS._
183
+
184
+ Syntax for adaptive keys in the CSV file:
185
+
186
+ key##{20}
187
+ key##{25}
188
+ key##{50}
189
+
190
+
191
+ Sample of iOS output in .stringsdict
192
+
193
+ ```xml
194
+ <?xml version="1.0" encoding="UTF-8"?>
195
+ <plist>
196
+ <dict>
197
+ <key>start_countdown</key>
198
+ <dict>
199
+ <key>NSStringVariableWidthRuleType</key>
200
+ <dict>
201
+ <key>20</key>
202
+ <string>Start</string>
203
+ <key>25</key>
204
+ <string>Start countdown</string>
205
+ <key>50</key>
206
+ <string>Start countdown</string>
207
+ </dict>
208
+ </dict>
209
+ </dict>
210
+ </plist>
211
+ ```
212
+
213
+ Source: https://developer.apple.com/documentation/foundation/nsstring/1413104-variantfittingpresentationwidth
214
+
180
215
  ## Development
181
216
 
182
217
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/ad_localize.gemspec CHANGED
@@ -44,7 +44,7 @@ Gem::Specification.new do |spec|
44
44
  spec.add_development_dependency 'minitest-reporters', '~> 1.3'
45
45
  spec.add_development_dependency 'diffy', '~> 3.3'
46
46
 
47
- spec.add_dependency 'activesupport', '~> 4.2' ,'>= 4.2.10' # Fastlane does not support activesupport 5
47
+ spec.add_dependency 'activesupport', '>= 4.2.10'
48
48
  spec.add_dependency 'nokogiri', '~> 1.8', '>= 1.8.2'
49
49
  spec.add_dependency 'colorize', '~> 0.8'
50
50
 
@@ -9,7 +9,7 @@ module AdLocalize
9
9
 
10
10
  # Returns the downloaded file name (it is located in the current directory)
11
11
  def download_from_drive(key, sheet)
12
- LOGGER.log(:info, :black, "Downloading file from google drive...")
12
+ LOGGER.log(:info, :green, "Downloading file from google drive...")
13
13
  download_string_path = "./#{key}.csv"
14
14
  begin
15
15
  File.open(download_string_path, "wb") do |saved_file|
@@ -58,7 +58,7 @@ module AdLocalize
58
58
  if locales.empty?
59
59
  raise 'NO DETECTED LOCALES'
60
60
  else
61
- LOGGER.log(:debug, :black, "DETECTED LOCALES : #{locales.join(', ')}")
61
+ LOGGER.log(:debug, :green, "DETECTED LOCALES : #{locales.join(', ')}")
62
62
  end
63
63
  end
64
64
 
@@ -137,7 +137,7 @@ module AdLocalize
137
137
 
138
138
  def trace_wording(wording, present_message, missing_message)
139
139
  if wording
140
- LOGGER.log(:debug, :black, present_message)
140
+ LOGGER.log(:debug, :green, present_message)
141
141
  else
142
142
  LOGGER.log(:debug, :yellow, missing_message)
143
143
  end
@@ -67,4 +67,4 @@ module AdLocalize::Platform
67
67
  )
68
68
  end
69
69
  end
70
- end
70
+ end
@@ -15,7 +15,7 @@ module AdLocalize::Platform
15
15
  all_symbols.each do |numeral_key|
16
16
  numeral_data = data.select {|key, wording| wording.dig(locale.to_sym)&.key? numeral_key}
17
17
  if numeral_data.empty?
18
- AdLocalize::LOGGER.log(:info, :black, "[#{locale.upcase}] no #{numeral_key.to_s} keys were found to generate the file")
18
+ AdLocalize::LOGGER.log(:info, :green, "[#{locale.upcase}] no #{numeral_key.to_s} keys were found to generate the file")
19
19
  else
20
20
  send("write_#{numeral_key}", locale, numeral_data)
21
21
  end
@@ -65,7 +65,7 @@ module AdLocalize::Platform
65
65
  }
66
66
  end
67
67
  end
68
- AdLocalize::LOGGER.log(:debug, :black, "iOS plural [#{locale}] ---> DONE!")
68
+ AdLocalize::LOGGER.log(:debug, :green, "iOS plural [#{locale}] ---> DONE!")
69
69
  end
70
70
 
71
71
  def write_adaptive(locale, adaptives)
@@ -108,7 +108,7 @@ module AdLocalize::Platform
108
108
  file.puts line
109
109
  end
110
110
  end
111
- AdLocalize::LOGGER.log(:debug, :black, "iOS #{wording_type} [#{locale}] ---> DONE!")
111
+ AdLocalize::LOGGER.log(:debug, :green, "iOS #{wording_type} [#{locale}] ---> DONE!")
112
112
  end
113
113
 
114
114
  def append_to_localizable_plist(locale)
@@ -135,4 +135,4 @@ module AdLocalize::Platform
135
135
  end
136
136
  end
137
137
  end
138
- end
138
+ end
@@ -4,15 +4,45 @@ module AdLocalize::Platform
4
4
  :json
5
5
  end
6
6
 
7
- def export(locale, data, export_extension = "json", substitution_format = "angular")
8
- super(locale, data, export_extension, substitution_format) do |json_data, file|
7
+ def export(locale, data, export_extension = "json", substitution_format = "react")
8
+ locale = locale.to_sym
9
+ json_data = data.each_with_object({}) do |(key, wording), hash_acc|
10
+ hash_acc[locale.to_s] = {} unless hash_acc.key? locale.to_s
11
+ keys = key.to_s.split('.')
12
+ hash = hash_acc[locale.to_s]
13
+ keys.each_with_index do |inner_key, index|
14
+ if index === keys.count - 1
15
+ fill_hash(wording, locale, hash, inner_key)
16
+ else
17
+ if hash[inner_key].nil?
18
+ hash[inner_key] = {}
19
+ end
20
+ hash = hash[inner_key]
21
+ end
22
+ end
23
+ end
24
+
25
+ platform_dir.join("#{locale.to_s}.#{export_extension}").open("w") do |file|
9
26
  file.puts json_data.to_json
10
27
  end
28
+
29
+ AdLocalize::LOGGER.log(:debug, :green, "JSON [#{locale}] ---> DONE!")
11
30
  end
12
31
 
13
32
  protected
14
- def ios_converter(value)
15
- value.gsub(/(%(?!)?(\d+\$)?[@isd])/, "VARIABLE_TO_SET")
33
+
34
+ def fill_hash(wording, locale, hash, key)
35
+ if wording.dig(locale)&.key? :singular
36
+ value = wording.dig(locale, :singular)
37
+ hash[key.to_s] = value
38
+ end
39
+ if wording.dig(locale)&.key? :plural
40
+ hash[key.to_s] = {}
41
+ wording.dig(locale, :plural).each do |plural_type, plural_text|
42
+ value = plural_text
43
+ hash[key.to_s][plural_type.to_s] = value
44
+ end
45
+ end
16
46
  end
17
47
  end
18
- end
48
+ end
@@ -39,7 +39,7 @@ module AdLocalize::Platform
39
39
  yield(formatted_data, file)
40
40
  end
41
41
 
42
- AdLocalize::LOGGER.log(:debug, :black, "#{platform.to_s.upcase} [#{locale}] ---> DONE!")
42
+ AdLocalize::LOGGER.log(:debug, :green, "#{platform.to_s.upcase} [#{locale}] ---> DONE!")
43
43
  end
44
44
 
45
45
  protected
@@ -7,7 +7,7 @@ module AdLocalize
7
7
  end
8
8
 
9
9
  def run(args = ARGV)
10
- LOGGER.log(:info, :black, "OPTIONS : #{options}")
10
+ LOGGER.log(:info, :green, "OPTIONS : #{options}")
11
11
  input_files = (args + [options.dig(:drive_key)]).compact # drive_key can be nil
12
12
  if input_files.length.zero?
13
13
  LOGGER.log(:error, :red, "No CSV to parse. Use option -h to see how to use this script")
@@ -24,9 +24,10 @@ module AdLocalize
24
24
  end
25
25
 
26
26
  private
27
+
27
28
  def export(file)
28
- LOGGER.log(:info, :black, "********* PARSING #{file} *********")
29
- LOGGER.log(:info, :black, "Extracting data from file...")
29
+ LOGGER.log(:info, :green, "********* PARSING #{file} *********")
30
+ LOGGER.log(:info, :green, "Extracting data from file...")
30
31
  parser = CsvParser.new
31
32
  data = parser.extract_data(file)
32
33
  if data.empty?
@@ -42,4 +43,4 @@ module AdLocalize
42
43
  end
43
44
  end
44
45
  end
45
- end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module AdLocalize
2
- VERSION = "3.2.0"
2
+ VERSION = "3.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ad_localize
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Siegel
@@ -114,9 +114,6 @@ dependencies:
114
114
  name: activesupport
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - "~>"
118
- - !ruby/object:Gem::Version
119
- version: '4.2'
120
117
  - - ">="
121
118
  - !ruby/object:Gem::Version
122
119
  version: 4.2.10
@@ -124,9 +121,6 @@ dependencies:
124
121
  prerelease: false
125
122
  version_requirements: !ruby/object:Gem::Requirement
126
123
  requirements:
127
- - - "~>"
128
- - !ruby/object:Gem::Version
129
- version: '4.2'
130
124
  - - ">="
131
125
  - !ruby/object:Gem::Version
132
126
  version: 4.2.10
@@ -176,6 +170,7 @@ executables:
176
170
  extensions: []
177
171
  extra_rdoc_files: []
178
172
  files:
173
+ - ".github/workflows/ruby.yml"
179
174
  - ".gitignore"
180
175
  - ".travis.yml"
181
176
  - CHANGELOG.md