twitter_cldr 6.6.0 → 6.6.1
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/Gemfile +1 -1
- data/README.md +13 -13
- data/Rakefile +6 -1
- data/lib/twitter_cldr/resources.rb +2 -0
- data/lib/twitter_cldr/resources/list_formats_importer.rb +108 -0
- data/lib/twitter_cldr/resources/locales_resources_importer.rb +0 -1
- data/lib/twitter_cldr/version.rb +1 -1
- data/resources/locales/af/lists.yml +3 -3
- data/resources/locales/be/lists.yml +3 -3
- data/resources/locales/bg/lists.yml +2 -2
- data/resources/locales/bn/lists.yml +2 -2
- data/resources/locales/bo/lists.yml +7 -7
- data/resources/locales/bs/lists.yml +3 -3
- data/resources/locales/ca/lists.yml +2 -2
- data/resources/locales/cy/lists.yml +2 -2
- data/resources/locales/da/lists.yml +1 -1
- data/resources/locales/de-AT/lists.yml +3 -3
- data/resources/locales/de-CH/lists.yml +3 -3
- data/resources/locales/de/lists.yml +3 -3
- data/resources/locales/el/lists.yml +2 -2
- data/resources/locales/en-US/lists.yml +2 -2
- data/resources/locales/en/lists.yml +2 -2
- data/resources/locales/eo/lists.yml +7 -7
- data/resources/locales/es-419/lists.yml +3 -3
- data/resources/locales/es-AR/lists.yml +3 -3
- data/resources/locales/es-CO/lists.yml +3 -3
- data/resources/locales/es-MX/lists.yml +3 -3
- data/resources/locales/es-US/lists.yml +3 -3
- data/resources/locales/es/lists.yml +3 -3
- data/resources/locales/et/lists.yml +2 -2
- data/resources/locales/eu/lists.yml +3 -3
- data/resources/locales/fi/lists.yml +3 -3
- data/resources/locales/fil/lists.yml +2 -2
- data/resources/locales/fr-BE/lists.yml +2 -2
- data/resources/locales/fr-CA/lists.yml +2 -2
- data/resources/locales/fr-CH/lists.yml +2 -2
- data/resources/locales/fr/lists.yml +2 -2
- data/resources/locales/gl/lists.yml +2 -2
- data/resources/locales/gu/lists.yml +1 -1
- data/resources/locales/he/lists.yml +1 -1
- data/resources/locales/hi/lists.yml +3 -3
- data/resources/locales/hr/lists.yml +3 -3
- data/resources/locales/hu/lists.yml +3 -3
- data/resources/locales/hy/lists.yml +2 -2
- data/resources/locales/id/lists.yml +2 -2
- data/resources/locales/is/lists.yml +2 -2
- data/resources/locales/it-CH/lists.yml +3 -3
- data/resources/locales/it/lists.yml +3 -3
- data/resources/locales/ja/lists.yml +3 -3
- data/resources/locales/ka/lists.yml +3 -3
- data/resources/locales/kk/lists.yml +3 -3
- data/resources/locales/km/lists.yml +2 -2
- data/resources/locales/kn/lists.yml +2 -2
- data/resources/locales/ko/lists.yml +3 -3
- data/resources/locales/lo/lists.yml +2 -2
- data/resources/locales/lt/lists.yml +3 -3
- data/resources/locales/lv/lists.yml +3 -3
- data/resources/locales/mk/lists.yml +2 -2
- data/resources/locales/mr/lists.yml +2 -2
- data/resources/locales/ms/lists.yml +2 -2
- data/resources/locales/mt/lists.yml +4 -4
- data/resources/locales/nb/lists.yml +3 -3
- data/resources/locales/nl-BE/lists.yml +3 -3
- data/resources/locales/nl/lists.yml +3 -3
- data/resources/locales/pl/lists.yml +2 -2
- data/resources/locales/pt-PT/lists.yml +2 -2
- data/resources/locales/pt/lists.yml +2 -2
- data/resources/locales/ro/lists.yml +2 -2
- data/resources/locales/ru/lists.yml +2 -2
- data/resources/locales/sk/lists.yml +3 -3
- data/resources/locales/sl/lists.yml +3 -3
- data/resources/locales/sq/lists.yml +3 -3
- data/resources/locales/sr-Cyrl-ME/lists.yml +3 -3
- data/resources/locales/sr-Latn-ME/lists.yml +15 -15
- data/resources/locales/sr/lists.yml +3 -3
- data/resources/locales/sv/lists.yml +2 -2
- data/resources/locales/ta/lists.yml +2 -2
- data/resources/locales/tr/lists.yml +2 -2
- data/resources/locales/uk/lists.yml +2 -2
- data/resources/locales/ur/lists.yml +2 -2
- data/resources/locales/vi/lists.yml +3 -3
- data/resources/locales/xh/lists.yml +7 -7
- data/resources/locales/zh-Hant/lists.yml +3 -3
- data/resources/locales/zh/lists.yml +3 -3
- data/resources/locales/zu/lists.yml +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46779462152c01a424c966b9a2d8a4d7b3d50c41164fd054edc493f96ddef7f5
|
4
|
+
data.tar.gz: 20689d92c66c2a42b1bb9545495b789460a4b892f8fd6b187f9967a459467a00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc9567be97d3604bfcef46520704ce3d05e2a5f2916e857791cc76de2f67a45a9aa014c6b63327a34caf89e4681696664741037ccf57b5988a30ff5891173a7f
|
7
|
+
data.tar.gz: 99a1b37964339e2d77c9fb295a7269025d6ef6ab81f9514190d55644d96262b848e21f48e84746c7ccb05f138bf0ef611e132de5ad896c67fdfe3091a1ece924
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
## twitter-cldr-rb
|
1
|
+
## twitter-cldr-rb  [](https://codeclimate.com/github/twitter/twitter-cldr-rb) [](https://coveralls.io/r/twitter/twitter-cldr-rb?branch=master)
|
2
2
|
|
3
3
|
TwitterCldr uses Unicode's Common Locale Data Repository (CLDR) to format certain types of text into their
|
4
4
|
localized equivalents. Currently supported types of text include dates, times, currencies, decimals, percentages, and symbols.
|
@@ -558,20 +558,20 @@ The CLDR contains postal code validation regexes for a number of countries.
|
|
558
558
|
|
559
559
|
```ruby
|
560
560
|
# United States
|
561
|
-
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:us)
|
561
|
+
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:us)
|
562
562
|
postal_code.valid?("94103") # true
|
563
563
|
postal_code.valid?("9410") # false
|
564
564
|
|
565
565
|
# England (Great Britain)
|
566
|
-
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:gb)
|
566
|
+
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:gb)
|
567
567
|
postal_code.valid?("BS98 1TL") # true
|
568
568
|
|
569
569
|
# Sweden
|
570
|
-
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:se)
|
570
|
+
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:se)
|
571
571
|
postal_code.valid?("280 12") # true
|
572
572
|
|
573
573
|
# Canada
|
574
|
-
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:ca)
|
574
|
+
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:ca)
|
575
575
|
postal_code.valid?("V3H 1Z7") # true
|
576
576
|
```
|
577
577
|
|
@@ -579,7 +579,7 @@ Match all valid postal codes in a string with the `#find_all` method:
|
|
579
579
|
|
580
580
|
```ruby
|
581
581
|
# United States
|
582
|
-
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:us)
|
582
|
+
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:us)
|
583
583
|
postal_code.find_all("12345 23456") # ["12345", "23456"]
|
584
584
|
```
|
585
585
|
|
@@ -592,7 +592,7 @@ TwitterCldr::Shared::PostalCodes.territories # [:ac, :ad, :af, :ai, :al, ... ]
|
|
592
592
|
Just want the regex? No problem:
|
593
593
|
|
594
594
|
```ruby
|
595
|
-
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:us)
|
595
|
+
postal_code = TwitterCldr::Shared::PostalCodes.for_territory(:us)
|
596
596
|
postal_code.regexp # /(\d{5})(?:[ \-](\d{4}))?/
|
597
597
|
```
|
598
598
|
|
@@ -1014,17 +1014,17 @@ The Psych gem that is the default YAML engine in Ruby 1.9 doesn't handle Unicode
|
|
1014
1014
|
You can make use of TwitterCLDR's YAML dumper by calling `localize` and then `to_yaml` on an `Array`, `Hash`, or `String`:
|
1015
1015
|
|
1016
1016
|
```ruby
|
1017
|
-
{ :hello => "world" }.localize.to_yaml
|
1018
|
-
["hello", "world"].localize.to_yaml
|
1019
|
-
"hello, world".localize.to_yaml
|
1017
|
+
{ :hello => "world" }.localize.to_yaml
|
1018
|
+
["hello", "world"].localize.to_yaml
|
1019
|
+
"hello, world".localize.to_yaml
|
1020
1020
|
```
|
1021
1021
|
|
1022
1022
|
Behind the scenes, these convenience methods are using the `TwitterCldr::Shared::YAML` class. You can do the same thing if you're feeling adventurous:
|
1023
1023
|
|
1024
1024
|
```ruby
|
1025
|
-
TwitterCldr::Shared::YAML.dump({ :hello => "world" })
|
1026
|
-
TwitterCldr::Shared::YAML.dump(["hello", "world"])
|
1027
|
-
TwitterCldr::Shared::YAML.dump("hello, world")
|
1025
|
+
TwitterCldr::Shared::YAML.dump({ :hello => "world" })
|
1026
|
+
TwitterCldr::Shared::YAML.dump(["hello", "world"])
|
1027
|
+
TwitterCldr::Shared::YAML.dump("hello, world")
|
1028
1028
|
```
|
1029
1029
|
|
1030
1030
|
## Adding New Locales
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ require 'rubygems/package_task'
|
|
13
13
|
|
14
14
|
require './lib/twitter_cldr'
|
15
15
|
|
16
|
-
require 'pry-
|
16
|
+
require 'pry-byebug'
|
17
17
|
|
18
18
|
Bundler::GemHelper.install_tasks
|
19
19
|
|
@@ -89,6 +89,11 @@ namespace :update do
|
|
89
89
|
TwitterCldr::Resources::NumberFormatsImporter.new.import
|
90
90
|
end
|
91
91
|
|
92
|
+
desc 'Import list formats'
|
93
|
+
task :list_formats do
|
94
|
+
TwitterCldr::Resources::ListFormatsImporter.new.import
|
95
|
+
end
|
96
|
+
|
92
97
|
desc 'Import currency symbols'
|
93
98
|
task :currency_symbols do
|
94
99
|
TwitterCldr::Resources::CurrencySymbolsImporter.new.import
|
@@ -17,6 +17,7 @@ module TwitterCldr
|
|
17
17
|
autoload :Importer, 'twitter_cldr/resources/importer'
|
18
18
|
autoload :ImportResolver, 'twitter_cldr/resources/import_resolver'
|
19
19
|
autoload :LanguageCodesImporter, 'twitter_cldr/resources/language_codes_importer'
|
20
|
+
autoload :ListFormatsImporter, 'twitter_cldr/resources/list_formats_importer'
|
20
21
|
autoload :Loader, 'twitter_cldr/resources/loader'
|
21
22
|
autoload :LocalesResourcesImporter, 'twitter_cldr/resources/locales_resources_importer'
|
22
23
|
autoload :NumberFormatsImporter, 'twitter_cldr/resources/number_formats_importer'
|
@@ -58,6 +59,7 @@ module TwitterCldr
|
|
58
59
|
DayPeriodRulesImporter,
|
59
60
|
HyphenationImporter,
|
60
61
|
LanguageCodesImporter,
|
62
|
+
ListFormatsImporter,
|
61
63
|
LocalesResourcesImporter,
|
62
64
|
NumberFormatsImporter,
|
63
65
|
ParentLocalesImporter,
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'nokogiri'
|
7
|
+
require 'parallel'
|
8
|
+
require 'etc'
|
9
|
+
require 'set'
|
10
|
+
|
11
|
+
module TwitterCldr
|
12
|
+
module Resources
|
13
|
+
|
14
|
+
class ListFormatsImporter < Importer
|
15
|
+
|
16
|
+
requirement :cldr, Versions.cldr_version
|
17
|
+
output_path 'locales'
|
18
|
+
locales TwitterCldr.supported_locales
|
19
|
+
ruby_engine :mri
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def execute
|
24
|
+
locales = Set.new
|
25
|
+
|
26
|
+
finish = -> (locale, *) do
|
27
|
+
locales.add(locale)
|
28
|
+
STDOUT.write "\rImported #{locale}, #{locales.size} of #{params[:locales].size} total"
|
29
|
+
end
|
30
|
+
|
31
|
+
Parallel.each(params[:locales], in_processes: Etc.nprocessors, finish: finish) do |locale|
|
32
|
+
import_locale(locale)
|
33
|
+
locales << locale
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def import_locale(locale)
|
38
|
+
data = requirements[:cldr].merge_each_ancestor(locale) do |ancestor_locale|
|
39
|
+
ListFormats.new(ancestor_locale, requirements[:cldr]).to_h
|
40
|
+
end
|
41
|
+
|
42
|
+
output_file = File.join(output_path, locale.to_s, 'lists.yml')
|
43
|
+
|
44
|
+
File.open(output_file, 'w:utf-8') do |output|
|
45
|
+
output.write(
|
46
|
+
TwitterCldr::Utils::YAML.dump(
|
47
|
+
TwitterCldr::Utils.deep_symbolize_keys(locale => data),
|
48
|
+
use_natural_symbols: true
|
49
|
+
)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def output_path
|
55
|
+
params.fetch(:output_path)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
class ListFormats
|
62
|
+
|
63
|
+
attr_reader :locale, :cldr_req
|
64
|
+
|
65
|
+
def initialize(locale, cldr_req)
|
66
|
+
@locale = locale
|
67
|
+
@cldr_req = cldr_req
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_h
|
71
|
+
{ lists: lists }
|
72
|
+
end
|
73
|
+
|
74
|
+
def lists
|
75
|
+
doc.xpath('//ldml/listPatterns/listPattern').each_with_object({}) do |pattern_node, pattern_result|
|
76
|
+
pattern_type = if attribute = pattern_node.attribute('type')
|
77
|
+
attribute.value.to_sym
|
78
|
+
else
|
79
|
+
:default
|
80
|
+
end
|
81
|
+
|
82
|
+
if aliased = pattern_node.xpath('alias').first
|
83
|
+
alias_type = aliased.attribute('path').value[/@type='([\w-]+)'/, 1]
|
84
|
+
pattern_result[pattern_type] = :"lists.#{alias_type || 'default'}"
|
85
|
+
next
|
86
|
+
end
|
87
|
+
|
88
|
+
pattern_result[pattern_type] = pattern_node.xpath('listPatternPart').each_with_object({}) do |type_node, type_result|
|
89
|
+
type_result[type_node.attribute('type').value.to_sym] = type_node.content
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def doc
|
95
|
+
@doc ||= begin
|
96
|
+
locale_fs = locale.to_s.gsub('-', '_')
|
97
|
+
Nokogiri.XML(File.read(File.join(cldr_main_path, "#{locale_fs}.xml")))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def cldr_main_path
|
102
|
+
@cldr_main_path ||= File.join(cldr_req.common_path, 'main')
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
data/lib/twitter_cldr/version.rb
CHANGED
@@ -13,9 +13,9 @@
|
|
13
13
|
:end: "{0} of {1}"
|
14
14
|
:middle: "{0}, {1}"
|
15
15
|
:start: "{0}, {1}"
|
16
|
-
:or-narrow:
|
17
|
-
:or-short:
|
18
|
-
:standard-narrow:
|
16
|
+
:or-narrow: :lists.or-short
|
17
|
+
:or-short: :lists.or
|
18
|
+
:standard-narrow: :lists.standard-short
|
19
19
|
:standard-short:
|
20
20
|
? !ruby/symbol "2"
|
21
21
|
: "{0} en {1}"
|
@@ -13,9 +13,9 @@
|
|
13
13
|
:end: "{0} ці {1}"
|
14
14
|
:middle: "{0}, {1}"
|
15
15
|
:start: "{0}, {1}"
|
16
|
-
:or-narrow:
|
17
|
-
:or-short:
|
18
|
-
:standard-narrow:
|
16
|
+
:or-narrow: :lists.or-short
|
17
|
+
:or-short: :lists.or
|
18
|
+
:standard-narrow: :lists.standard-short
|
19
19
|
:standard-short:
|
20
20
|
? !ruby/symbol "2"
|
21
21
|
: "{0} і {1}"
|
@@ -13,10 +13,10 @@
|
|
13
13
|
:end: "{0}, or {1}"
|
14
14
|
:middle: "{0}, {1}"
|
15
15
|
:start: "{0}, {1}"
|
16
|
-
:or-narrow:
|
17
|
-
:or-short:
|
18
|
-
:standard-narrow:
|
19
|
-
:standard-short:
|
20
|
-
:unit:
|
21
|
-
:unit-narrow:
|
22
|
-
:unit-short:
|
16
|
+
:or-narrow: :lists.or-short
|
17
|
+
:or-short: :lists.or
|
18
|
+
:standard-narrow: :lists.standard-short
|
19
|
+
:standard-short: :lists.default
|
20
|
+
:unit: :lists.unit-short
|
21
|
+
:unit-narrow: :lists.unit-short
|
22
|
+
:unit-short: :lists.default
|
@@ -13,9 +13,9 @@
|
|
13
13
|
:end: "{0} ili {1}"
|
14
14
|
:middle: "{0}, {1}"
|
15
15
|
:start: "{0}, {1}"
|
16
|
-
:or-narrow:
|
17
|
-
:or-short:
|
18
|
-
:standard-narrow:
|
16
|
+
:or-narrow: :lists.or-short
|
17
|
+
:or-short: :lists.or
|
18
|
+
:standard-narrow: :lists.standard-short
|
19
19
|
:standard-short:
|
20
20
|
? !ruby/symbol "2"
|
21
21
|
: "{0} i {1}"
|
@@ -13,9 +13,9 @@
|
|
13
13
|
:end: "{0} oder {1}"
|
14
14
|
:middle: "{0}, {1}"
|
15
15
|
:start: "{0}, {1}"
|
16
|
-
:or-narrow:
|
17
|
-
:or-short:
|
18
|
-
:standard-narrow:
|
16
|
+
:or-narrow: :lists.or-short
|
17
|
+
:or-short: :lists.or
|
18
|
+
:standard-narrow: :lists.standard-short
|
19
19
|
:standard-short:
|
20
20
|
? !ruby/symbol "2"
|
21
21
|
: "{0} und {1}"
|
@@ -13,9 +13,9 @@
|
|
13
13
|
:end: "{0} oder {1}"
|
14
14
|
:middle: "{0}, {1}"
|
15
15
|
:start: "{0}, {1}"
|
16
|
-
:or-narrow:
|
17
|
-
:or-short:
|
18
|
-
:standard-narrow:
|
16
|
+
:or-narrow: :lists.or-short
|
17
|
+
:or-short: :lists.or
|
18
|
+
:standard-narrow: :lists.standard-short
|
19
19
|
:standard-short:
|
20
20
|
? !ruby/symbol "2"
|
21
21
|
: "{0} und {1}"
|
@@ -13,9 +13,9 @@
|
|
13
13
|
:end: "{0} oder {1}"
|
14
14
|
:middle: "{0}, {1}"
|
15
15
|
:start: "{0}, {1}"
|
16
|
-
:or-narrow:
|
17
|
-
:or-short:
|
18
|
-
:standard-narrow:
|
16
|
+
:or-narrow: :lists.or-short
|
17
|
+
:or-short: :lists.or
|
18
|
+
:standard-narrow: :lists.standard-short
|
19
19
|
:standard-short:
|
20
20
|
? !ruby/symbol "2"
|
21
21
|
: "{0} und {1}"
|