ad_localize 3.3.0 → 3.4.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: 7b8f651b78afaf45c264c489854182f16644ce5e6b633f65a0f35ea5c3b51782
4
- data.tar.gz: 32760e7c15e78ebe5f874e1a763023ec315effb651b5e07bc1144314d1fe3a9a
3
+ metadata.gz: a4a46683de0e489838b53aae0ddd3a4e7e52a0089013fac5b49a07a558bfd322
4
+ data.tar.gz: 11523ebff556f015ae9e0a7ec76bf50f75d9317b9fd272e2f0b28e84ae0a070d
5
5
  SHA512:
6
- metadata.gz: b67bcb815f92a4e17ad8ebc88dbf2f65115a43e43fa2e6fbe83755b409167c24201d06d4cacccc5ff7c2be42366a21abca3603f07f50fef5c4af92cbab5b17a6
7
- data.tar.gz: 7ea60174aabe27f2146396cf573d1ac0dd90f09b26dc7b8fb5c3158d88d178df0be7bf283438b7ac8b5870c81a30950d985ad724f1a8a71b63421400d9189875
6
+ metadata.gz: 7432f6a5dd72d4635b3c07215ffb2d7afe357a5f93aca0d04635c20c15494571d580af9572ce38b0805afb1762d714dc73ef71ae8f5bd855ebfdfb8dbe9eef0d
7
+ data.tar.gz: 5e726801cb6f26bf2c58787297a1e0639cd403f7d9d22c3a8ce82d04fb65a8e3d8cd3b6a94cf1057f9d0b32ebcab9d79ba00867f50d3add3815cd450b945b097
data/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [3.4.0] - 2019-02-10
8
+ ### Added
9
+ - Rails folks, [@epaillous](https://github.com/epaillous) has improved the YAML support. You can now have multi-level wording.
10
+
11
+ ## [3.3.0] - 2019-02-10
12
+ ### Added
13
+ - improve React support using keys with dots to generate nested JSON files by [@epaillous](https://github.com/epaillous)
14
+
7
15
  ## [3.2.0] - 2019-12-10
8
16
  ### Added
9
17
  - Add tests to compare reference exports by [@felginep](https://github.com/felginep)
@@ -6,43 +6,12 @@ module AdLocalize::Platform
6
6
 
7
7
  def export(locale, data, export_extension = "json", substitution_format = "react")
8
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
-
9
+ json_data = build_platform_data_splitting_on_dots(locale, data)
25
10
  platform_dir.join("#{locale.to_s}.#{export_extension}").open("w") do |file|
26
11
  file.puts json_data.to_json
27
12
  end
28
13
 
29
14
  AdLocalize::LOGGER.log(:debug, :green, "JSON [#{locale}] ---> DONE!")
30
15
  end
31
-
32
- protected
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
46
- end
47
16
  end
48
17
  end
@@ -72,5 +72,37 @@ module AdLocalize::Platform
72
72
  export_dir(locale).mkdir
73
73
  end
74
74
  end
75
+
76
+ def build_platform_data_splitting_on_dots(locale, data)
77
+ data.each_with_object({}) do |(key, wording), hash_acc|
78
+ hash_acc[locale.to_s] = {} unless hash_acc.key? locale.to_s
79
+ keys = key.to_s.split('.')
80
+ hash = hash_acc[locale.to_s]
81
+ keys.each_with_index do |inner_key, index|
82
+ if index === keys.count - 1
83
+ fill_hash(wording, locale, hash, inner_key)
84
+ else
85
+ if hash[inner_key].nil?
86
+ hash[inner_key] = {}
87
+ end
88
+ hash = hash[inner_key]
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ def fill_hash(wording, locale, hash, key)
95
+ if wording.dig(locale)&.key? :singular
96
+ value = wording.dig(locale, :singular)
97
+ hash[key.to_s] = value
98
+ end
99
+ if wording.dig(locale)&.key? :plural
100
+ hash[key.to_s] = {}
101
+ wording.dig(locale, :plural).each do |plural_type, plural_text|
102
+ value = plural_text
103
+ hash[key.to_s][plural_type.to_s] = value
104
+ end
105
+ end
106
+ end
75
107
  end
76
108
  end
@@ -5,14 +5,15 @@ module AdLocalize::Platform
5
5
  end
6
6
 
7
7
  def export(locale, data, export_extension = "yml", substitution_format = "yml")
8
- super(locale, data, export_extension, substitution_format) do |yml_data, file|
8
+ locale = locale.to_sym
9
+ yml_data = build_platform_data_splitting_on_dots(locale, data)
10
+
11
+ platform_dir.join("#{locale.to_s}.#{export_extension}").open("w") do |file|
9
12
  file.puts yml_data.to_yaml
10
13
  end
11
- end
12
14
 
13
- protected
14
- def ios_converter(value)
15
- value.gsub(/(%(?!)?(\d+\$)?[@isd])/, "VARIABLE_TO_SET")
15
+ AdLocalize::LOGGER.log(:debug, :green, "YAML [#{locale}] ---> DONE!")
16
16
  end
17
+
17
18
  end
18
19
  end
@@ -1,3 +1,3 @@
1
1
  module AdLocalize
2
- VERSION = "3.3.0"
2
+ VERSION = "3.4.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.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Siegel