ad_localize 3.1.0 → 3.2.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 +4 -4
- data/CHANGELOG.md +10 -1
- data/ad_localize.gemspec +1 -0
- data/lib/ad_localize/constant.rb +1 -0
- data/lib/ad_localize/csv_parser.rb +24 -9
- data/lib/ad_localize/platform/android_formatter.rb +1 -1
- data/lib/ad_localize/platform/ios_formatter.rb +79 -29
- data/lib/ad_localize/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b67ba9ff725d7fbf76fd0d680b07573648ee51966fdbb8429e6a26a764fc5563
|
4
|
+
data.tar.gz: 7ce5a08e27d50cbedd1ca1f4ffac9af1817ee8c38e97eb088d6dd7bc6d8ec5d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0eb0c873e0d27062cc4291baab1c330224997ef3085b7474424c50d0dff8f089c40ae9f668e91f5769ce6d7c69431892435ee65a5a3073815ddbbe9bcde539be
|
7
|
+
data.tar.gz: 7998404ef9a406c7421117d666fae0c3aa8bfa0f55a5fe4e5a207a7c6bc01d370de3158a47910d47205d73a266a35109ca819cf114b572fe848061454e5fad29
|
data/CHANGELOG.md
CHANGED
@@ -4,9 +4,19 @@ 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.2.0] - 2019-12-10
|
8
|
+
### Added
|
9
|
+
- Add tests to compare reference exports by [@felginep](https://github.com/felginep)
|
10
|
+
- [iOS only] Handle [adaptive strings](https://developer.apple.com/documentation/foundation/nsstring/1413104-variantfittingpresentationwidth) by [@felginep](https://github.com/felginep)
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- Fix issue with Info.plist format by [@felginep](https://github.com/felginep)
|
14
|
+
- Do not export plurals for android when there are no values by [@felginep](https://github.com/felginep)
|
15
|
+
|
7
16
|
## [3.1.0] - 2019-09-30
|
8
17
|
### Added
|
9
18
|
- [iOS only] Info.plist generation support by [@felginep](https://github.com/felginep)
|
19
|
+
|
10
20
|
### Changed
|
11
21
|
- No more warning log for empty lines by [@felginep](https://github.com/felginep)
|
12
22
|
|
@@ -27,4 +37,3 @@ TODO
|
|
27
37
|
|
28
38
|
## [0.1.0] - 2016-04-25
|
29
39
|
TODO
|
30
|
-
|
data/ad_localize.gemspec
CHANGED
@@ -42,6 +42,7 @@ Gem::Specification.new do |spec|
|
|
42
42
|
spec.add_development_dependency 'minitest', '~> 5.11'
|
43
43
|
spec.add_development_dependency 'byebug', '~> 11.0'
|
44
44
|
spec.add_development_dependency 'minitest-reporters', '~> 1.3'
|
45
|
+
spec.add_development_dependency 'diffy', '~> 3.3'
|
45
46
|
|
46
47
|
spec.add_dependency 'activesupport', '~> 4.2' ,'>= 4.2.10' # Fastlane does not support activesupport 5
|
47
48
|
spec.add_dependency 'nokogiri', '~> 1.8', '>= 1.8.2'
|
data/lib/ad_localize/constant.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module AdLocalize
|
2
2
|
class CsvParser
|
3
3
|
CSV_WORDING_KEYS_COLUMN = "key"
|
4
|
-
PLURAL_KEY_REGEXP = /\#\#\{(
|
4
|
+
PLURAL_KEY_REGEXP = /\#\#\{([A-Za-z]+)\}/
|
5
|
+
ADAPTIVE_KEY_REGEXP = /\#\#\{(\d+)\}/
|
5
6
|
INFO_PLIST_KEY_REGEXP = /(NS.+UsageDescription)|(CF.+Name)/ # see https://developer.apple.com/documentation/bundleresources/information_property_list
|
6
7
|
|
7
8
|
attr_accessor :locales
|
@@ -78,6 +79,11 @@ module AdLocalize
|
|
78
79
|
"[#{locale.upcase}] Plural key ---> plural_identifier : #{key_infos.dig(:plural_identifier)}, key : #{current_key}",
|
79
80
|
"[#{locale.upcase}] Missing translation for #{current_key} (#{key_infos.dig(:plural_identifier)})")
|
80
81
|
value = { key_infos.dig(:plural_identifier) => row[locale] || default_wording(locale, "#{current_key} (#{key_infos.dig(:plural_identifier)})") }
|
82
|
+
elsif key_infos.dig(:numeral_key) == Constant::ADAPTIVE_KEY_SYMBOL
|
83
|
+
trace_wording(row[locale],
|
84
|
+
"[#{locale.upcase}] Adaptive key ---> adaptive_identifier : #{key_infos.dig(:adaptive_identifier)}, key : #{current_key}",
|
85
|
+
"[#{locale.upcase}] Missing translation for #{current_key} (#{key_infos.dig(:adaptive_identifier)})")
|
86
|
+
value = { key_infos.dig(:adaptive_identifier) => row[locale] || default_wording(locale, "#{current_key} (#{key_infos.dig(:adaptive_identifier)})") }
|
81
87
|
elsif key_infos.dig(:numeral_key) == Constant::INFO_PLIST_KEY_SYMBOL
|
82
88
|
trace_wording(row[locale], "[#{locale.upcase}] Info.plist key ---> #{current_key}", "[#{locale.upcase}] Missing translation for #{current_key}")
|
83
89
|
value = row[locale] || default_wording(locale, current_key)
|
@@ -98,22 +104,31 @@ module AdLocalize
|
|
98
104
|
plural_identifier = nil
|
99
105
|
invalid_plural = false
|
100
106
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
107
|
-
else
|
107
|
+
adaptive_prefix = key.match(ADAPTIVE_KEY_REGEXP)
|
108
|
+
adaptive_identifier = nil
|
109
|
+
invalid_adaptive = false
|
110
|
+
|
111
|
+
if plural_prefix != nil
|
108
112
|
numeral_key = Constant::PLURAL_KEY_SYMBOL
|
109
113
|
key = plural_prefix.pre_match
|
110
114
|
plural_identifier = plural_prefix.captures&.first
|
111
115
|
LOGGER.log(:debug, :red, "Invalid key #{key}") if key.nil?
|
112
116
|
LOGGER.log(:debug, :red, "Empty plural prefix!") if plural_identifier.nil?
|
113
117
|
invalid_plural = plural_identifier.nil?
|
118
|
+
elsif adaptive_prefix != nil
|
119
|
+
numeral_key = Constant::ADAPTIVE_KEY_SYMBOL
|
120
|
+
key = adaptive_prefix.pre_match
|
121
|
+
adaptive_identifier = adaptive_prefix.captures&.first
|
122
|
+
LOGGER.log(:debug, :red, "Invalid key #{key}") if key.nil?
|
123
|
+
LOGGER.log(:debug, :red, "Empty adaptive prefix!") if adaptive_identifier.nil?
|
124
|
+
invalid_adaptive = adaptive_identifier.nil?
|
125
|
+
elsif key.match(INFO_PLIST_KEY_REGEXP) != nil
|
126
|
+
numeral_key = Constant::INFO_PLIST_KEY_SYMBOL
|
127
|
+
else
|
128
|
+
numeral_key = Constant::SINGULAR_KEY_SYMBOL
|
114
129
|
end
|
115
130
|
|
116
|
-
(key.nil? or invalid_plural) ? nil : { key: key.to_sym, numeral_key: numeral_key, plural_identifier: plural_identifier&.to_sym }
|
131
|
+
(key.nil? or invalid_plural or invalid_adaptive) ? nil : { key: key.to_sym, numeral_key: numeral_key, plural_identifier: plural_identifier&.to_sym, adaptive_identifier: adaptive_identifier&.to_sym }
|
117
132
|
end
|
118
133
|
|
119
134
|
def default_wording(locale, key)
|
@@ -6,7 +6,13 @@ module AdLocalize::Platform
|
|
6
6
|
|
7
7
|
def export(locale, data, export_extension = nil, substitution_format = nil)
|
8
8
|
create_locale_dir(locale)
|
9
|
-
|
9
|
+
all_symbols = [
|
10
|
+
AdLocalize::Constant::PLURAL_KEY_SYMBOL,
|
11
|
+
AdLocalize::Constant::ADAPTIVE_KEY_SYMBOL,
|
12
|
+
AdLocalize::Constant::SINGULAR_KEY_SYMBOL,
|
13
|
+
AdLocalize::Constant::INFO_PLIST_KEY_SYMBOL
|
14
|
+
]
|
15
|
+
all_symbols.each do |numeral_key|
|
10
16
|
numeral_data = data.select {|key, wording| wording.dig(locale.to_sym)&.key? numeral_key}
|
11
17
|
if numeral_data.empty?
|
12
18
|
AdLocalize::LOGGER.log(:info, :black, "[#{locale.upcase}] no #{numeral_key.to_s} keys were found to generate the file")
|
@@ -36,6 +42,54 @@ module AdLocalize::Platform
|
|
36
42
|
)
|
37
43
|
end
|
38
44
|
|
45
|
+
def write_plural(locale, plurals)
|
46
|
+
locale = locale.to_sym
|
47
|
+
|
48
|
+
append_to_localizable_plist(locale) do |xml|
|
49
|
+
plurals.each do |wording_key, translations|
|
50
|
+
xml.key wording_key
|
51
|
+
xml.dict {
|
52
|
+
xml.key "NSStringLocalizedFormatKey"
|
53
|
+
xml.string "%\#@key@"
|
54
|
+
xml.key "key"
|
55
|
+
xml.dict {
|
56
|
+
xml.key "NSStringFormatSpecTypeKey"
|
57
|
+
xml.string "NSStringPluralRuleType"
|
58
|
+
xml.key "NSStringFormatValueTypeKey"
|
59
|
+
xml.string "d"
|
60
|
+
translations[locale][AdLocalize::Constant::PLURAL_KEY_SYMBOL].each do |wording_type, wording_value|
|
61
|
+
xml.key wording_type
|
62
|
+
xml.string wording_value
|
63
|
+
end
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
AdLocalize::LOGGER.log(:debug, :black, "iOS plural [#{locale}] ---> DONE!")
|
69
|
+
end
|
70
|
+
|
71
|
+
def write_adaptive(locale, adaptives)
|
72
|
+
locale = locale.to_sym
|
73
|
+
|
74
|
+
append_to_localizable_plist(locale) do |xml|
|
75
|
+
adaptives.each do |wording_key, translations|
|
76
|
+
xml.key wording_key
|
77
|
+
xml.dict {
|
78
|
+
xml.key "NSStringVariableWidthRuleType"
|
79
|
+
xml.dict {
|
80
|
+
translations[locale][AdLocalize::Constant::ADAPTIVE_KEY_SYMBOL].each do |wording_type, wording_value|
|
81
|
+
xml.key wording_type
|
82
|
+
xml.string wording_value
|
83
|
+
end
|
84
|
+
}
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
AdLocalize::LOGGER.log(:debug, :black, "iOS adaptive [#{locale}] ---> DONE!")
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
39
93
|
def write_localizable(locale:, singulars:, wording_type:, filename:)
|
40
94
|
locale = locale.to_sym
|
41
95
|
|
@@ -43,7 +97,12 @@ module AdLocalize::Platform
|
|
43
97
|
value = locales_wording.dig(locale, wording_type)
|
44
98
|
comment = locales_wording.dig(locale, AdLocalize::Constant::COMMENT_KEY_SYMBOL)
|
45
99
|
export_dir(locale).join(filename).open("a") do |file|
|
46
|
-
line =
|
100
|
+
line = ""
|
101
|
+
if wording_type == AdLocalize::Constant::INFO_PLIST_KEY_SYMBOL
|
102
|
+
line = %(#{key} = "#{value}";)
|
103
|
+
else
|
104
|
+
line = %("#{key}" = "#{value}";)
|
105
|
+
end
|
47
106
|
line << " // #{comment}" unless comment.nil?
|
48
107
|
line << "\n"
|
49
108
|
file.puts line
|
@@ -52,37 +111,28 @@ module AdLocalize::Platform
|
|
52
111
|
AdLocalize::LOGGER.log(:debug, :black, "iOS #{wording_type} [#{locale}] ---> DONE!")
|
53
112
|
end
|
54
113
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
xml.string "d"
|
72
|
-
translations[locale][AdLocalize::Constant::PLURAL_KEY_SYMBOL].each do |wording_type, wording_value|
|
73
|
-
xml.key wording_type
|
74
|
-
xml.string wording_value
|
75
|
-
end
|
76
|
-
}
|
77
|
-
}
|
78
|
-
end
|
114
|
+
def append_to_localizable_plist(locale)
|
115
|
+
filename = export_dir(locale).join(AdLocalize::Constant::IOS_PLURAL_EXPORT_FILENAME)
|
116
|
+
xml_doc = nil
|
117
|
+
if File.exist?(filename)
|
118
|
+
xml_content = Nokogiri::XML(open(filename)) do |config|
|
119
|
+
config.default_xml.noblanks # minimify xml
|
120
|
+
end
|
121
|
+
xml_doc = Nokogiri::XML::Builder.with(xml_content.css('plist>dict').first) do |xml|
|
122
|
+
yield(xml)
|
123
|
+
end
|
124
|
+
else
|
125
|
+
xml_doc = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
126
|
+
xml.plist {
|
127
|
+
xml.dict {
|
128
|
+
yield(xml)
|
129
|
+
}
|
79
130
|
}
|
80
|
-
|
131
|
+
end
|
81
132
|
end
|
82
|
-
|
133
|
+
filename.open("w") do |file|
|
83
134
|
file.puts xml_doc.to_xml(indent: 4)
|
84
135
|
end
|
85
|
-
AdLocalize::LOGGER.log(:debug, :black, "iOS plural [#{locale}] ---> DONE!")
|
86
136
|
end
|
87
137
|
end
|
88
138
|
end
|
data/lib/ad_localize/version.rb
CHANGED
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.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edouard Siegel
|
@@ -96,6 +96,20 @@ dependencies:
|
|
96
96
|
- - "~>"
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '1.3'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: diffy
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '3.3'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '3.3'
|
99
113
|
- !ruby/object:Gem::Dependency
|
100
114
|
name: activesupport
|
101
115
|
requirement: !ruby/object:Gem::Requirement
|