ad_localize 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +15 -3
- data/lib/ad_localize/constant.rb +2 -0
- data/lib/ad_localize/csv_parser.rb +13 -3
- data/lib/ad_localize/platform/ios_formatter.rb +23 -4
- data/lib/ad_localize/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9510eed71bfba2c01f047d80707eaaeffbe24d6fefc4f65927b1afe8e44c2a49
|
4
|
+
data.tar.gz: 3aba4a56d7f7b5fd0da6056471c55cf025a9133dd3d5a815fe06ac89a662d645
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b87614c092bd2c6fcee5deeba77add9035f01c4861d526081e91606e6613827f4199d2fccb1f69aa7149f6c7a2755536d7e7a2b5d50901455b519fc20a98d695
|
7
|
+
data.tar.gz: 22b0cc2b7b3a6290017b7cdd9e8bb0a7bb30b662bdeada9669d9fd10a670af0f3d4e99919fca9023b0cd289d0ad254d45e14dc7d7fdc20f0b6fac25f92017eca
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@ 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.1.0] - 2019-09-30
|
8
|
+
### Added
|
9
|
+
- [iOS only] Info.plist generation support by [@felginep](https://github.com/felginep)
|
10
|
+
### Changed
|
11
|
+
- No more warning log for empty lines by [@felginep](https://github.com/felginep)
|
12
|
+
|
7
13
|
## [3.0.0] - 2019-02-19
|
8
14
|
TODO
|
9
15
|
|
data/README.md
CHANGED
@@ -97,10 +97,12 @@ exports/
|
|
97
97
|
├── ios
|
98
98
|
│ ├── en.lproj
|
99
99
|
│ │ ├── Localizable.strings
|
100
|
-
│ │
|
101
|
-
|
100
|
+
│ │ ├── Localizable.stringsdict
|
101
|
+
| | └── InfoPlist.strings
|
102
|
+
│ └── fr.lproj
|
102
103
|
│ ├── Localizable.strings
|
103
|
-
│
|
104
|
+
│ ├── Localizable.stringsdict
|
105
|
+
| └── InfoPlist.strings
|
104
106
|
├── json
|
105
107
|
│ ├── en.json
|
106
108
|
│ └── fr.json
|
@@ -165,6 +167,16 @@ Sample of iOS output in .stringsdict
|
|
165
167
|
</plist>
|
166
168
|
```
|
167
169
|
|
170
|
+
## InfoPlist.strings
|
171
|
+
|
172
|
+
_Only for iOS._
|
173
|
+
|
174
|
+
Every key that matches the following formats will be added to the `InfoPlist.strings` file instead of `Localizable.strings`:
|
175
|
+
* `NS...UsageDescription`
|
176
|
+
* `CF...Name`
|
177
|
+
|
178
|
+
Source: https://developer.apple.com/documentation/bundleresources/information_property_list
|
179
|
+
|
168
180
|
## Development
|
169
181
|
|
170
182
|
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/lib/ad_localize/constant.rb
CHANGED
@@ -4,6 +4,7 @@ module AdLocalize
|
|
4
4
|
PLURAL_KEY_SYMBOL = :plural
|
5
5
|
SINGULAR_KEY_SYMBOL = :singular
|
6
6
|
COMMENT_KEY_SYMBOL = :comment
|
7
|
+
INFO_PLIST_KEY_SYMBOL = :info_plist
|
7
8
|
COMMENT_KEY_COLUMN_IDENTIFIER = "comment"
|
8
9
|
DEFAULT_CONFIG = {
|
9
10
|
platforms: {
|
@@ -16,6 +17,7 @@ module AdLocalize
|
|
16
17
|
CONFIG = YAML.load_file(Pathname::pwd + 'config.yml').deep_symbolize_keys rescue DEFAULT_CONFIG
|
17
18
|
EXPORT_FOLDER = 'exports'
|
18
19
|
IOS_SINGULAR_EXPORT_FILENAME = "Localizable.strings"
|
20
|
+
IOS_INFO_PLIST_EXPORT_FILENAME = "InfoPlist.strings"
|
19
21
|
IOS_PLURAL_EXPORT_FILENAME = "Localizable.stringsdict"
|
20
22
|
ANDROID_EXPORT_FILENAME = "strings.xml"
|
21
23
|
end
|
@@ -2,6 +2,7 @@ module AdLocalize
|
|
2
2
|
class CsvParser
|
3
3
|
CSV_WORDING_KEYS_COLUMN = "key"
|
4
4
|
PLURAL_KEY_REGEXP = /\#\#\{(\w+)\}/
|
5
|
+
INFO_PLIST_KEY_REGEXP = /(NS.+UsageDescription)|(CF.+Name)/ # see https://developer.apple.com/documentation/bundleresources/information_property_list
|
5
6
|
|
6
7
|
attr_accessor :locales
|
7
8
|
|
@@ -15,8 +16,12 @@ module AdLocalize
|
|
15
16
|
CSV.foreach(file_name, headers: true, skip_blanks: true) do |row|
|
16
17
|
validity_status = check_row(row)
|
17
18
|
if validity_status.zero?
|
19
|
+
keys_column_index = row.index(CSV_WORDING_KEYS_COLUMN)
|
20
|
+
fields = row.fields
|
21
|
+
LOGGER.log(:warn, :yellow, "Missing key in line #{$.}") unless fields[keys_column_index...fields.count].all?(&:nil?)
|
18
22
|
next
|
19
23
|
elsif validity_status == -1
|
24
|
+
LOGGER.log(:error, :red, "[CSV FORMAT] #{file_name} is not a valid file")
|
20
25
|
exit
|
21
26
|
else
|
22
27
|
find_locales(row) if locales.empty?
|
@@ -35,10 +40,8 @@ module AdLocalize
|
|
35
40
|
valid_row = 1
|
36
41
|
# Check non empty row
|
37
42
|
if row.field(CSV_WORDING_KEYS_COLUMN).nil?
|
38
|
-
LOGGER.log(:error, :red, "Missing key in line #{$.}") unless row.fields.all?(&:nil?)
|
39
43
|
valid_row = 0
|
40
44
|
elsif not row.headers.include?(CSV_WORDING_KEYS_COLUMN)
|
41
|
-
LOGGER.log(:error, :red, "[CSV FORMAT] #{file_name} is not a valid file")
|
42
45
|
valid_row = -1
|
43
46
|
end
|
44
47
|
return valid_row
|
@@ -75,6 +78,9 @@ module AdLocalize
|
|
75
78
|
"[#{locale.upcase}] Plural key ---> plural_identifier : #{key_infos.dig(:plural_identifier)}, key : #{current_key}",
|
76
79
|
"[#{locale.upcase}] Missing translation for #{current_key} (#{key_infos.dig(:plural_identifier)})")
|
77
80
|
value = { key_infos.dig(:plural_identifier) => row[locale] || default_wording(locale, "#{current_key} (#{key_infos.dig(:plural_identifier)})") }
|
81
|
+
elsif key_infos.dig(:numeral_key) == Constant::INFO_PLIST_KEY_SYMBOL
|
82
|
+
trace_wording(row[locale], "[#{locale.upcase}] Info.plist key ---> #{current_key}", "[#{locale.upcase}] Missing translation for #{current_key}")
|
83
|
+
value = row[locale] || default_wording(locale, current_key)
|
78
84
|
else
|
79
85
|
raise "Unknown numeral key #{key_infos.dig(:numeral_key)}"
|
80
86
|
end
|
@@ -93,7 +99,11 @@ module AdLocalize
|
|
93
99
|
invalid_plural = false
|
94
100
|
|
95
101
|
if plural_prefix.nil?
|
96
|
-
|
102
|
+
if key.match(INFO_PLIST_KEY_REGEXP).nil?
|
103
|
+
numeral_key = Constant::SINGULAR_KEY_SYMBOL
|
104
|
+
else
|
105
|
+
numeral_key = Constant::INFO_PLIST_KEY_SYMBOL
|
106
|
+
end
|
97
107
|
else
|
98
108
|
numeral_key = Constant::PLURAL_KEY_SYMBOL
|
99
109
|
key = plural_prefix.pre_match
|
@@ -6,7 +6,7 @@ module AdLocalize::Platform
|
|
6
6
|
|
7
7
|
def export(locale, data, export_extension = nil, substitution_format = nil)
|
8
8
|
create_locale_dir(locale)
|
9
|
-
[AdLocalize::Constant::PLURAL_KEY_SYMBOL, AdLocalize::Constant::SINGULAR_KEY_SYMBOL].each do |numeral_key|
|
9
|
+
[AdLocalize::Constant::PLURAL_KEY_SYMBOL, AdLocalize::Constant::SINGULAR_KEY_SYMBOL, AdLocalize::Constant::INFO_PLIST_KEY_SYMBOL].each do |numeral_key|
|
10
10
|
numeral_data = data.select {|key, wording| wording.dig(locale.to_sym)&.key? numeral_key}
|
11
11
|
if numeral_data.empty?
|
12
12
|
AdLocalize::LOGGER.log(:info, :black, "[#{locale.upcase}] no #{numeral_key.to_s} keys were found to generate the file")
|
@@ -17,20 +17,39 @@ module AdLocalize::Platform
|
|
17
17
|
end
|
18
18
|
|
19
19
|
protected
|
20
|
+
|
20
21
|
def write_singular(locale, singulars)
|
22
|
+
write_localizable(
|
23
|
+
locale: locale,
|
24
|
+
singulars: singulars,
|
25
|
+
wording_type: AdLocalize::Constant::SINGULAR_KEY_SYMBOL,
|
26
|
+
filename: AdLocalize::Constant::IOS_SINGULAR_EXPORT_FILENAME
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def write_info_plist(locale, singulars)
|
31
|
+
write_localizable(
|
32
|
+
locale: locale,
|
33
|
+
singulars: singulars,
|
34
|
+
wording_type: AdLocalize::Constant::INFO_PLIST_KEY_SYMBOL,
|
35
|
+
filename: AdLocalize::Constant::IOS_INFO_PLIST_EXPORT_FILENAME
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def write_localizable(locale:, singulars:, wording_type:, filename:)
|
21
40
|
locale = locale.to_sym
|
22
41
|
|
23
42
|
singulars.each do |key, locales_wording|
|
24
|
-
value = locales_wording.dig(locale,
|
43
|
+
value = locales_wording.dig(locale, wording_type)
|
25
44
|
comment = locales_wording.dig(locale, AdLocalize::Constant::COMMENT_KEY_SYMBOL)
|
26
|
-
export_dir(locale).join(
|
45
|
+
export_dir(locale).join(filename).open("a") do |file|
|
27
46
|
line = "\"#{key}\" = \"#{value}\";"
|
28
47
|
line << " // #{comment}" unless comment.nil?
|
29
48
|
line << "\n"
|
30
49
|
file.puts line
|
31
50
|
end
|
32
51
|
end
|
33
|
-
AdLocalize::LOGGER.log(:debug, :black, "iOS
|
52
|
+
AdLocalize::LOGGER.log(:debug, :black, "iOS #{wording_type} [#{locale}] ---> DONE!")
|
34
53
|
end
|
35
54
|
|
36
55
|
def write_plural(locale, plurals)
|
data/lib/ad_localize/version.rb
CHANGED