twitter_cldr 6.0.2 → 6.1.0

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: e16faa9cf2e7fda6f36008b520e7f18cc1cd64c9e5c0a9c01cc3c787cfddf38d
4
- data.tar.gz: 0750c3375803f85d1c126b473d15b11e91429af41ca6940da670732ebe57ce8d
3
+ metadata.gz: 72981bad7d4ed54141a4e9dd7dc94cb49035766eed724834916ac772c48f7eed
4
+ data.tar.gz: 96889477a704251878f8f863caef717a7e371831cb909a4724ebc32aedcc447b
5
5
  SHA512:
6
- metadata.gz: ffa52ad4c2ae417fca4e1d87c23272845dbfd7069f14984b4c123ebdf770410cef4ae38c552d1fe225727897f926fb671a3b7624a48a3429e6ba8518722ba412
7
- data.tar.gz: f839fa10c1623407fa95a8f7e044376b3f139ba2bd602d0d57c6982899455c046f0e947d9f047a6f7150bbbc4b75bf1010562c720656afec25fde2ebe2b55853
6
+ metadata.gz: 64876d8266dbe0e629b21bd8e62a49aea758046e14a74f31afc4e751e7c93d9081ac1f73e4a1ff64899a2c9dda519e14fab83d8ed017e953ebeb42967f3040cf
7
+ data.tar.gz: e953e933a7a0c6a1a45167613591e5a2e93653ef64aff35066474bc3f371511ae5f1d06f06ab6683500960d01aaebea7714dbb8d1d535a5724fe8122b309a95c
data/Rakefile CHANGED
@@ -141,6 +141,11 @@ namespace :update do
141
141
  TwitterCldr::Resources::CasefolderClassGenerator.new.import
142
142
  end
143
143
 
144
+ desc 'Import parent locale data'
145
+ task :parent_locales do
146
+ TwitterCldr::Resources::ParentLocalesImporter.new.import
147
+ end
148
+
144
149
  desc 'Import postal codes resource'
145
150
  task :postal_codes do
146
151
  TwitterCldr::Resources::PostalCodesImporter.new.import
@@ -112,9 +112,28 @@ module TwitterCldr
112
112
  end
113
113
 
114
114
  def convert_locale(locale)
115
- locale = locale.to_sym if locale.respond_to?(:to_sym)
115
+ locale = normalize_locale(locale)
116
+
117
+ unless supported_locale?(locale)
118
+ loc = TwitterCldr::Shared::Locale.parse(locale)
119
+ max_supported = loc.max_supported
120
+
121
+ if loc.dasherized == 'und' || !max_supported
122
+ return locale
123
+ end
124
+
125
+ locale = normalize_locale(max_supported.dasherized)
126
+ end
127
+
128
+ locale
129
+ end
130
+
131
+ def normalize_locale(locale)
132
+ return locale unless (locale.is_a?(String) || locale.is_a?(Symbol))
133
+
134
+ locale = locale.to_sym
116
135
  locale = lowercase_locales_map.fetch(locale, locale)
117
- TWITTER_LOCALE_MAP.fetch(locale, locale)
136
+ TWITTER_LOCALE_MAP.fetch(locale.downcase, locale)
118
137
  end
119
138
 
120
139
  def twitter_locale(locale)
@@ -127,7 +146,7 @@ module TwitterCldr
127
146
  end
128
147
 
129
148
  def supported_locale?(locale)
130
- !!locale && supported_locales.include?(convert_locale(locale))
149
+ !!locale && supported_locales.include?(normalize_locale(locale))
131
150
  end
132
151
 
133
152
  protected
@@ -20,6 +20,7 @@ module TwitterCldr
20
20
  autoload :Loader, 'twitter_cldr/resources/loader'
21
21
  autoload :LocalesResourcesImporter, 'twitter_cldr/resources/locales_resources_importer'
22
22
  autoload :NumberFormatsImporter, 'twitter_cldr/resources/number_formats_importer'
23
+ autoload :ParentLocalesImporter, 'twitter_cldr/resources/parent_locales_importer'
23
24
  autoload :PostalCodesImporter, 'twitter_cldr/resources/postal_codes_importer'
24
25
  autoload :Properties, 'twitter_cldr/resources/properties'
25
26
  autoload :SegmentDictionariesImporter, 'twitter_cldr/resources/segment_dictionaries_importer'
@@ -59,6 +60,7 @@ module TwitterCldr
59
60
  LanguageCodesImporter,
60
61
  LocalesResourcesImporter,
61
62
  NumberFormatsImporter,
63
+ ParentLocalesImporter,
62
64
  PostalCodesImporter,
63
65
  RbnfTestImporter,
64
66
  SegmentDictionariesImporter,
@@ -0,0 +1,54 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'nokogiri'
7
+
8
+ module TwitterCldr
9
+ module Resources
10
+
11
+ class ParentLocalesImporter < Importer
12
+
13
+ requirement :cldr, Versions.cldr_version
14
+ output_path 'shared'
15
+ ruby_engine :mri
16
+
17
+ private
18
+
19
+ def execute
20
+ output_file = File.join(output_path, 'parent_locales.yml')
21
+ File.write(output_file, YAML.dump(parent_locales))
22
+ end
23
+
24
+ def parent_locales
25
+ @parent_locales ||= supplemental_data.xpath('//parentLocales/parentLocale').each_with_object({}) do |node, ret|
26
+ parent = node.attr('parent')
27
+ locales = node.attr('locales').split(' ')
28
+
29
+ locales.each do |locale|
30
+ ret[locale] = parent
31
+ end
32
+ end
33
+ end
34
+
35
+ def output_path
36
+ params.fetch(:output_path)
37
+ end
38
+
39
+ def supplemental_data
40
+ @supplemental_data ||= Nokogiri.XML(
41
+ File.read(
42
+ File.join(
43
+ requirements[:cldr].common_path,
44
+ 'supplemental',
45
+ 'supplementalData.xml'
46
+ )
47
+ )
48
+ )
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
@@ -209,6 +209,10 @@ module TwitterCldr
209
209
  @validity_resource ||=
210
210
  TwitterCldr.get_resource('shared', 'validity_data')[:validity_data]
211
211
  end
212
+
213
+ def parent_locales
214
+ @parent_locales ||= TwitterCldr.get_resource('shared', 'parent_locales')
215
+ end
212
216
  end
213
217
 
214
218
  attr_accessor :language, :script, :region, :variants
@@ -239,11 +243,9 @@ module TwitterCldr
239
243
 
240
244
  def supported
241
245
  @supported ||= begin
242
- found = permutations('-').find do |perm|
243
- TwitterCldr.supported_locale?(perm)
246
+ ancestor_chain.sort.find do |loc|
247
+ TwitterCldr.supported_locale?(loc.dasherized)
244
248
  end
245
-
246
- self.class.new(found) if found
247
249
  end
248
250
  end
249
251
 
@@ -273,6 +275,52 @@ module TwitterCldr
273
275
  perms.uniq
274
276
  end
275
277
 
278
+ def ==(other)
279
+ language == other.language &&
280
+ script == other.script &&
281
+ region == other.region &&
282
+ variants == other.variants
283
+ end
284
+
285
+ alias eql? ==
286
+
287
+ def hash
288
+ to_a.hash
289
+ end
290
+
291
+ def sort_key
292
+ k = 0
293
+ k += 3 if language
294
+ k += 2 if script
295
+ k += 1 if region
296
+ k
297
+ end
298
+
299
+ def <=>(other)
300
+ other.sort_key <=> sort_key
301
+ end
302
+
303
+ def ancestor_chain
304
+ ancestry = [self]
305
+ remaining = [self]
306
+
307
+ until remaining.empty?
308
+ locale = remaining.pop
309
+
310
+ if parent = self.class.send(:parent_locales)[locale.to_s]
311
+ parent = self.class.parse(parent)
312
+ ancestry << parent
313
+ remaining << parent
314
+ else
315
+ parents = locale.permutations.map { |p| self.class.parse(p) }
316
+ remaining += parents - ancestry
317
+ ancestry += parents - ancestry
318
+ end
319
+ end
320
+
321
+ ancestry
322
+ end
323
+
276
324
  end
277
325
  end
278
326
  end
@@ -4,5 +4,5 @@
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  module TwitterCldr
7
- VERSION = '6.0.2'
7
+ VERSION = '6.1.0'
8
8
  end
@@ -0,0 +1,172 @@
1
+ ---
2
+ az_Arab: root
3
+ az_Cyrl: root
4
+ blt_Latn: root
5
+ bm_Nkoo: root
6
+ bs_Cyrl: root
7
+ byn_Latn: root
8
+ cu_Glag: root
9
+ dje_Arab: root
10
+ dyo_Arab: root
11
+ en_Dsrt: root
12
+ en_Shaw: root
13
+ ff_Adlm: root
14
+ ff_Arab: root
15
+ ha_Arab: root
16
+ hi_Latn: root
17
+ iu_Latn: root
18
+ kk_Arab: root
19
+ ks_Deva: root
20
+ ku_Arab: root
21
+ ky_Arab: root
22
+ ky_Latn: root
23
+ ml_Arab: root
24
+ mn_Mong: root
25
+ mni_Mtei: root
26
+ ms_Arab: root
27
+ pa_Arab: root
28
+ sat_Deva: root
29
+ sd_Deva: root
30
+ sd_Khoj: root
31
+ sd_Sind: root
32
+ shi_Latn: root
33
+ so_Arab: root
34
+ sr_Latn: root
35
+ sw_Arab: root
36
+ tg_Arab: root
37
+ ug_Cyrl: root
38
+ uz_Arab: root
39
+ uz_Cyrl: root
40
+ vai_Latn: root
41
+ wo_Arab: root
42
+ yo_Arab: root
43
+ yue_Hans: root
44
+ zh_Hant: root
45
+ en_150: en_001
46
+ en_AG: en_001
47
+ en_AI: en_001
48
+ en_AU: en_001
49
+ en_BB: en_001
50
+ en_BM: en_001
51
+ en_BS: en_001
52
+ en_BW: en_001
53
+ en_BZ: en_001
54
+ en_CA: en_001
55
+ en_CC: en_001
56
+ en_CK: en_001
57
+ en_CM: en_001
58
+ en_CX: en_001
59
+ en_CY: en_001
60
+ en_DG: en_001
61
+ en_DM: en_001
62
+ en_ER: en_001
63
+ en_FJ: en_001
64
+ en_FK: en_001
65
+ en_FM: en_001
66
+ en_GB: en_001
67
+ en_GD: en_001
68
+ en_GG: en_001
69
+ en_GH: en_001
70
+ en_GI: en_001
71
+ en_GM: en_001
72
+ en_GY: en_001
73
+ en_HK: en_001
74
+ en_IE: en_001
75
+ en_IL: en_001
76
+ en_IM: en_001
77
+ en_IN: en_001
78
+ en_IO: en_001
79
+ en_JE: en_001
80
+ en_JM: en_001
81
+ en_KE: en_001
82
+ en_KI: en_001
83
+ en_KN: en_001
84
+ en_KY: en_001
85
+ en_LC: en_001
86
+ en_LR: en_001
87
+ en_LS: en_001
88
+ en_MG: en_001
89
+ en_MO: en_001
90
+ en_MS: en_001
91
+ en_MT: en_001
92
+ en_MU: en_001
93
+ en_MW: en_001
94
+ en_MY: en_001
95
+ en_NA: en_001
96
+ en_NF: en_001
97
+ en_NG: en_001
98
+ en_NR: en_001
99
+ en_NU: en_001
100
+ en_NZ: en_001
101
+ en_PG: en_001
102
+ en_PH: en_001
103
+ en_PK: en_001
104
+ en_PN: en_001
105
+ en_PW: en_001
106
+ en_RW: en_001
107
+ en_SB: en_001
108
+ en_SC: en_001
109
+ en_SD: en_001
110
+ en_SG: en_001
111
+ en_SH: en_001
112
+ en_SL: en_001
113
+ en_SS: en_001
114
+ en_SX: en_001
115
+ en_SZ: en_001
116
+ en_TC: en_001
117
+ en_TK: en_001
118
+ en_TO: en_001
119
+ en_TT: en_001
120
+ en_TV: en_001
121
+ en_TZ: en_001
122
+ en_UG: en_001
123
+ en_VC: en_001
124
+ en_VG: en_001
125
+ en_VU: en_001
126
+ en_WS: en_001
127
+ en_ZA: en_001
128
+ en_ZM: en_001
129
+ en_ZW: en_001
130
+ en_AT: en_150
131
+ en_BE: en_150
132
+ en_CH: en_150
133
+ en_DE: en_150
134
+ en_DK: en_150
135
+ en_FI: en_150
136
+ en_NL: en_150
137
+ en_SE: en_150
138
+ en_SI: en_150
139
+ es_AR: es_419
140
+ es_BO: es_419
141
+ es_BR: es_419
142
+ es_BZ: es_419
143
+ es_CL: es_419
144
+ es_CO: es_419
145
+ es_CR: es_419
146
+ es_CU: es_419
147
+ es_DO: es_419
148
+ es_EC: es_419
149
+ es_GT: es_419
150
+ es_HN: es_419
151
+ es_MX: es_419
152
+ es_NI: es_419
153
+ es_PA: es_419
154
+ es_PE: es_419
155
+ es_PR: es_419
156
+ es_PY: es_419
157
+ es_SV: es_419
158
+ es_US: es_419
159
+ es_UY: es_419
160
+ es_VE: es_419
161
+ pt_AO: pt_PT
162
+ pt_CH: pt_PT
163
+ pt_CV: pt_PT
164
+ pt_FR: pt_PT
165
+ pt_GQ: pt_PT
166
+ pt_GW: pt_PT
167
+ pt_LU: pt_PT
168
+ pt_MO: pt_PT
169
+ pt_MZ: pt_PT
170
+ pt_ST: pt_PT
171
+ pt_TL: pt_PT
172
+ zh_Hant_MO: zh_Hant_HK
@@ -195,7 +195,7 @@ describe TwitterCldr::Formatters::PluralFormatter do
195
195
 
196
196
  describe '#pluralization_rule' do
197
197
  it 'delegates pluralization rule fetching to Rules.rule_for method' do
198
- expect(TwitterCldr::Formatters::Plurals::Rules).to receive(:rule_for).with(42, :jp).and_return('result')
198
+ expect(TwitterCldr::Formatters::Plurals::Rules).to receive(:rule_for).with(42, :ja).and_return('result')
199
199
  expect(described_class.new(:jp).send(:pluralization_rule, 42)).to eq('result')
200
200
  end
201
201
  end
@@ -28,7 +28,7 @@ describe TwitterCldr::Shared::Calendar do
28
28
  end
29
29
 
30
30
  it 'returns calendar for a specific locale' do
31
- expect(described_class.new(:jp).locale).to eq(:jp)
31
+ expect(described_class.new(:jp).locale).to eq(:ja)
32
32
  end
33
33
 
34
34
  it 'uses TwitterCldr.convert_locale' do
@@ -136,7 +136,25 @@ describe TwitterCldr::Shared::Locale do
136
136
  end
137
137
  end
138
138
 
139
- context 'with a locale instance' do
139
+ context 'with a locale with interesting ancestry' do
140
+ let(:locale) { described_class.new('es', nil, 'CR') }
141
+
142
+ describe '#ancestor_chain' do
143
+ it 'identifies the correct ancestors' do
144
+ expect(locale.ancestor_chain.map(&:dasherized)).to eq(
145
+ ['es-CR', 'es-419', 'es']
146
+ )
147
+ end
148
+ end
149
+
150
+ describe '#max_supported' do
151
+ it 'identifies the correct supported parent locale' do
152
+ expect(locale.max_supported.dasherized).to eq('es-419')
153
+ end
154
+ end
155
+ end
156
+
157
+ context 'with a locale instance (Korean)' do
140
158
  let(:locale) { described_class.new('ko', nil, 'KR') }
141
159
 
142
160
  describe '#full_script' do
@@ -212,5 +230,19 @@ describe TwitterCldr::Shared::Locale do
212
230
  )
213
231
  end
214
232
  end
233
+
234
+ describe '#ancestor_chain' do
235
+ it 'identifies the correct ancestors' do
236
+ expect(locale.ancestor_chain.map(&:dasherized)).to eq(
237
+ ['ko-KR', 'ko']
238
+ )
239
+ end
240
+ end
241
+
242
+ describe '#max_supported' do
243
+ it 'identifies the correct supported locale' do
244
+ expect(locale.max_supported.dasherized).to eq('ko')
245
+ end
246
+ end
215
247
  end
216
248
  end
@@ -10,8 +10,8 @@ describe TwitterCldr::Shared::Numbers do
10
10
  let(:symbols) { { nan: 'NaN', minus_sign: '-' } }
11
11
 
12
12
  it 'returns numerical symbols for default locale' do
13
- allow(TwitterCldr).to receive(:locale).and_return(:jp)
14
- allow(TwitterCldr).to receive(:get_locale_resource).with(:jp, :numbers).and_return(jp: { numbers: { symbols: symbols } })
13
+ allow(TwitterCldr).to receive(:locale).and_return(:ja)
14
+ allow(TwitterCldr).to receive(:get_locale_resource).with(:ja, :numbers).and_return(ja: { numbers: { symbols: symbols } })
15
15
  expect(described_class.symbols).to eq(symbols)
16
16
  end
17
17
 
@@ -53,10 +53,31 @@ describe TwitterCldr do
53
53
  expect(TwitterCldr.convert_locale(:msa)).to eq(:ms)
54
54
  expect(TwitterCldr.convert_locale(:'zh-cn')).to eq(:zh)
55
55
  expect(TwitterCldr.convert_locale(:'zh-tw')).to eq(:'zh-Hant')
56
+ expect(TwitterCldr.convert_locale(:'zh-TW')).to eq(:'zh-Hant')
57
+ end
58
+
59
+ it "should fallback to language if locale is unsupported but language is" do
60
+ expect(TwitterCldr.convert_locale(:'pt-BR')).to eq(:pt)
61
+ expect(TwitterCldr.convert_locale(:'zh-Hans-CN')).to eq(:zh)
62
+ end
63
+
64
+ it "should leave known locales alone" do
65
+ expect(TwitterCldr.convert_locale(:fr)).to eq(:fr)
66
+ expect(TwitterCldr.convert_locale(:'fr-ca')).to eq(:'fr-CA')
67
+ expect(TwitterCldr.convert_locale(:'fr-CA')).to eq(:'fr-CA')
68
+ expect(TwitterCldr.convert_locale(:'es-419')).to eq(:'es-419')
56
69
  end
57
70
 
58
71
  it "should leave unknown locales alone" do
59
72
  expect(TwitterCldr.convert_locale(:blarg)).to eq(:blarg)
73
+ expect(TwitterCldr.convert_locale(:'zz-ZZ')).to eq(:'zz-ZZ')
74
+ end
75
+
76
+ it "shouldn't blowup on bad input" do
77
+ expect(TwitterCldr.convert_locale(5)).to eq(5)
78
+ expect(TwitterCldr.convert_locale([])).to eq([])
79
+ expect(TwitterCldr.convert_locale('')).to eq(:'')
80
+ expect(TwitterCldr.convert_locale(nil)).to eq(nil)
60
81
  end
61
82
  end
62
83
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_cldr
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.2
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: camertron-eprun
@@ -148,6 +148,7 @@ files:
148
148
  - lib/twitter_cldr/resources/loader.rb
149
149
  - lib/twitter_cldr/resources/locales_resources_importer.rb
150
150
  - lib/twitter_cldr/resources/number_formats_importer.rb
151
+ - lib/twitter_cldr/resources/parent_locales_importer.rb
151
152
  - lib/twitter_cldr/resources/postal_codes_importer.rb
152
153
  - lib/twitter_cldr/resources/properties.rb
153
154
  - lib/twitter_cldr/resources/properties/age_property_importer.rb
@@ -1833,6 +1834,7 @@ files:
1833
1834
  - resources/shared/likely_subtags.yml
1834
1835
  - resources/shared/metazones.yml
1835
1836
  - resources/shared/numbering_systems.yml
1837
+ - resources/shared/parent_locales.yml
1836
1838
  - resources/shared/postal_codes.yml
1837
1839
  - resources/shared/rbnf_root.yml
1838
1840
  - resources/shared/segments/dictionaries/burmesedict.dump