ruby-cldr 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +1 -1
- data/Gemfile.lock +56 -46
- data/README.textile +6 -0
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/cldr/download.rb +1 -1
- data/lib/cldr/export.rb +70 -16
- data/lib/cldr/export/data.rb +31 -21
- data/lib/cldr/export/data/aliases.rb +47 -0
- data/lib/cldr/export/data/base.rb +4 -0
- data/lib/cldr/export/data/characters.rb +30 -0
- data/lib/cldr/export/data/fields.rb +60 -0
- data/lib/cldr/export/data/languages.rb +1 -1
- data/lib/cldr/export/data/likely_subtags.rb +29 -0
- data/lib/cldr/export/data/numbers.rb +48 -6
- data/lib/cldr/export/data/parent_locales.rb +23 -0
- data/lib/cldr/export/data/plural_rules.rb +70 -0
- data/lib/cldr/export/data/rbnf.rb +12 -4
- data/lib/cldr/export/data/region_currencies.rb +45 -0
- data/lib/cldr/export/data/segments_root.rb +13 -3
- data/lib/cldr/export/data/territories.rb +1 -1
- data/lib/cldr/export/data/territories_containment.rb +30 -0
- data/lib/cldr/export/data/timezones.rb +18 -2
- data/lib/cldr/export/data/transforms.rb +76 -0
- data/lib/cldr/export/data/variables.rb +42 -0
- data/lib/cldr/export/yaml.rb +5 -21
- data/lib/cldr/thor.rb +2 -2
- data/test/export/data/calendars_test.rb +85 -51
- data/test/export/data/currencies_test.rb +29 -25
- data/test/export/data/languages_test.rb +69 -51
- data/test/export/data/numbers_test.rb +61 -62
- data/test/export/data/plurals_test.rb +4 -3
- data/test/export/data/territories_containment_test.rb +10 -0
- data/test/export/data/territories_test.rb +12 -5
- data/test/export/data/timezones_test.rb +5 -8
- data/test/export_test.rb +57 -5
- data/test/format/time_test.rb +5 -5
- metadata +40 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1ac65fa730274ef7d70f6dde1a20a4a6ed4a36f1407d65e12ba220539d6a0424
|
4
|
+
data.tar.gz: 900156546c3603e66501d527714a8b9ac3c66287ebde5672f699da68d5cbbfc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0589799c818cf86570883c73bcb095889496bc158026d51557829ba3c9eda8f13c1879823689c1263eee20931b77bd0a01de4e6680cfb5064ccb807a36fb0e69'
|
7
|
+
data.tar.gz: 642f18b73738a815314e6c0ee39ceac70c0f5d26c89027f4936f9089b577943481a8422980674bf725dd6243cce449af96d13ba5567f499564b9f42420ab40f2
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,63 +1,70 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.
|
5
|
-
builder (3.2.
|
6
|
-
coderay (1.
|
7
|
-
|
8
|
-
|
4
|
+
addressable (2.4.0)
|
5
|
+
builder (3.2.3)
|
6
|
+
coderay (1.1.2)
|
7
|
+
concurrent-ruby (1.1.4)
|
8
|
+
descendants_tracker (0.0.4)
|
9
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
10
|
+
faraday (0.9.2)
|
9
11
|
multipart-post (>= 1.2, < 3)
|
10
|
-
git (1.
|
11
|
-
github_api (0.
|
12
|
-
addressable (~> 2.
|
13
|
-
descendants_tracker (~> 0.0.
|
12
|
+
git (1.5.0)
|
13
|
+
github_api (0.16.0)
|
14
|
+
addressable (~> 2.4.0)
|
15
|
+
descendants_tracker (~> 0.0.4)
|
14
16
|
faraday (~> 0.8, < 0.10)
|
15
|
-
hashie (>=
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
jeweler (2.
|
17
|
+
hashie (>= 3.4)
|
18
|
+
mime-types (>= 1.16, < 3.0)
|
19
|
+
oauth2 (~> 1.0)
|
20
|
+
hashie (3.6.0)
|
21
|
+
highline (2.0.1)
|
22
|
+
i18n (1.5.3)
|
23
|
+
concurrent-ruby (~> 1.0)
|
24
|
+
jeweler (2.3.9)
|
23
25
|
builder
|
24
|
-
bundler
|
26
|
+
bundler
|
25
27
|
git (>= 1.2.5)
|
26
|
-
github_api
|
28
|
+
github_api (~> 0.16.0)
|
27
29
|
highline (>= 1.6.15)
|
28
30
|
nokogiri (>= 1.5.10)
|
31
|
+
psych
|
29
32
|
rake
|
30
33
|
rdoc
|
31
|
-
|
32
|
-
jwt (
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
multi_json (1.
|
37
|
-
multi_xml (0.
|
34
|
+
semver2
|
35
|
+
jwt (2.1.0)
|
36
|
+
method_source (0.8.2)
|
37
|
+
mime-types (2.99.3)
|
38
|
+
mini_portile2 (2.4.0)
|
39
|
+
multi_json (1.13.1)
|
40
|
+
multi_xml (0.6.0)
|
38
41
|
multipart-post (2.0.0)
|
39
|
-
nokogiri (1.
|
40
|
-
|
41
|
-
oauth2 (
|
42
|
-
faraday (>= 0.8, < 0.
|
43
|
-
jwt (
|
42
|
+
nokogiri (1.10.1)
|
43
|
+
mini_portile2 (~> 2.4.0)
|
44
|
+
oauth2 (1.4.1)
|
45
|
+
faraday (>= 0.8, < 0.16.0)
|
46
|
+
jwt (>= 1.0, < 3.0)
|
44
47
|
multi_json (~> 1.3)
|
45
48
|
multi_xml (~> 0.5)
|
46
|
-
rack (
|
47
|
-
|
48
|
-
|
49
|
-
|
49
|
+
rack (>= 1.2, < 3)
|
50
|
+
power_assert (1.1.3)
|
51
|
+
pry (0.10.4)
|
52
|
+
coderay (~> 1.1.0)
|
53
|
+
method_source (~> 0.8.1)
|
50
54
|
slop (~> 3.4)
|
51
|
-
pry-nav (0.2.
|
52
|
-
pry (
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
rubyzip (1.
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
pry-nav (0.2.4)
|
56
|
+
pry (>= 0.9.10, < 0.11.0)
|
57
|
+
psych (3.1.0)
|
58
|
+
rack (2.0.6)
|
59
|
+
rake (12.3.2)
|
60
|
+
rdoc (6.1.1)
|
61
|
+
rubyzip (1.2.2)
|
62
|
+
semver2 (3.4.2)
|
63
|
+
slop (3.6.0)
|
64
|
+
test-unit (3.3.0)
|
65
|
+
power_assert
|
66
|
+
thor (0.20.3)
|
67
|
+
thread_safe (0.3.6)
|
61
68
|
|
62
69
|
PLATFORMS
|
63
70
|
ruby
|
@@ -69,5 +76,8 @@ DEPENDENCIES
|
|
69
76
|
pry
|
70
77
|
pry-nav
|
71
78
|
rubyzip
|
79
|
+
test-unit
|
72
80
|
thor
|
73
|
-
|
81
|
+
|
82
|
+
BUNDLED WITH
|
83
|
+
2.0.1
|
data/README.textile
CHANGED
data/Rakefile
CHANGED
@@ -8,11 +8,11 @@ begin
|
|
8
8
|
gem.summary = %Q{Ruby library for exporting and using data from CLDR }
|
9
9
|
gem.description = %Q{Ruby library for exporting and using data from CLDR, see http://cldr.unicode.org}
|
10
10
|
gem.email = "svenfuchs@artweb-design.de"
|
11
|
-
gem.homepage = "http://github.com/
|
11
|
+
gem.homepage = "http://github.com/ruby-i18n/ruby-cldr"
|
12
12
|
gem.authors = ["Sven Fuchs"]
|
13
13
|
gem.files = FileList["*.thor", "[A-Z]*", "{lib,test}/**/*"]
|
14
14
|
end
|
15
15
|
Jeweler::GemcutterTasks.new
|
16
16
|
rescue LoadError
|
17
17
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
-
end
|
18
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/cldr/download.rb
CHANGED
@@ -5,7 +5,7 @@ require 'zip'
|
|
5
5
|
module Cldr
|
6
6
|
class << self
|
7
7
|
def download(source = nil, target = nil)
|
8
|
-
source ||= 'http://unicode.org/Public/cldr/
|
8
|
+
source ||= 'http://unicode.org/Public/cldr/34/core.zip'
|
9
9
|
target ||= File.expand_path('./vendor/cldr')
|
10
10
|
|
11
11
|
URI.parse(source).open do |tempfile|
|
data/lib/cldr/export.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'i18n'
|
2
|
-
require '
|
2
|
+
require 'fileutils'
|
3
|
+
require 'i18n/locale/tag'
|
3
4
|
require 'core_ext/string/camelize'
|
4
5
|
require 'core_ext/string/underscore'
|
5
6
|
require 'core_ext/hash/deep_stringify_keys'
|
@@ -12,13 +13,19 @@ module Cldr
|
|
12
13
|
autoload :Ruby, 'cldr/export/ruby'
|
13
14
|
autoload :Yaml, 'cldr/export/yaml'
|
14
15
|
|
15
|
-
SHARED_COMPONENTS = [
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
SHARED_COMPONENTS = %w[
|
17
|
+
CurrencyDigitsAndRounding
|
18
|
+
Metazones
|
19
|
+
NumberingSystems
|
20
|
+
RbnfRoot
|
21
|
+
SegmentsRoot
|
22
|
+
TerritoriesContainment
|
23
|
+
WindowsZones
|
24
|
+
Transforms
|
25
|
+
LikelySubtags
|
26
|
+
Variables
|
27
|
+
Aliases
|
28
|
+
RegionCurrencies
|
22
29
|
]
|
23
30
|
|
24
31
|
class << self
|
@@ -40,8 +47,23 @@ module Cldr
|
|
40
47
|
end
|
41
48
|
|
42
49
|
shared_components.each do |component|
|
43
|
-
|
44
|
-
|
50
|
+
case component
|
51
|
+
when "Transforms"
|
52
|
+
yaml_exporter = Cldr::Export::Yaml.new
|
53
|
+
Dir.glob("#{Cldr::Export::Data.dir}/transforms/**.xml").each do |transform_file|
|
54
|
+
data = Data::Transforms.new(transform_file)
|
55
|
+
source = data[:transforms].first[:source]
|
56
|
+
target = data[:transforms].first[:target]
|
57
|
+
variant = data[:transforms].first[:variant]
|
58
|
+
file_name = [source, target, variant].compact.join('-')
|
59
|
+
output_path = File.join(base_path, "transforms", "#{file_name}.yml")
|
60
|
+
write(output_path, yaml_exporter.yaml(data))
|
61
|
+
yield component, nil, output_path if block_given?
|
62
|
+
end
|
63
|
+
else
|
64
|
+
ex = exporter(component, options[:format])
|
65
|
+
ex.export('', component, options, &block)
|
66
|
+
end
|
45
67
|
end
|
46
68
|
|
47
69
|
locales.each do |locale|
|
@@ -89,13 +111,45 @@ module Cldr
|
|
89
111
|
end
|
90
112
|
|
91
113
|
def shared_data(component, options = {})
|
92
|
-
|
114
|
+
case component.to_s
|
115
|
+
when 'Transforms'
|
116
|
+
# do nothing, this has to be handled separately
|
117
|
+
else
|
118
|
+
Data.const_get(component.to_s.camelize).new
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_i18n(locale)
|
123
|
+
return locale.to_s.gsub('_', '-').to_sym
|
124
|
+
end
|
125
|
+
|
126
|
+
def from_i18n(locale)
|
127
|
+
return locale.to_s.gsub('-', '_')
|
93
128
|
end
|
94
129
|
|
95
130
|
def locales(locale, component, options)
|
96
|
-
locale = locale
|
97
|
-
|
98
|
-
locales
|
131
|
+
locale = to_i18n(locale)
|
132
|
+
|
133
|
+
locales = if options[:merge]
|
134
|
+
defined_parents = Cldr::Export::Data::ParentLocales.new
|
135
|
+
|
136
|
+
ancestry = [locale]
|
137
|
+
loop do
|
138
|
+
if defined_parents[from_i18n(ancestry.last)]
|
139
|
+
ancestry << to_i18n(defined_parents[from_i18n(ancestry.last)])
|
140
|
+
elsif I18n::Locale::Tag.tag(ancestry.last).self_and_parents.count > 1
|
141
|
+
ancestry << I18n::Locale::Tag.tag(ancestry.last).self_and_parents.last.to_sym
|
142
|
+
else
|
143
|
+
break
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
ancestry << :root if component_should_merge_root?(component)
|
148
|
+
ancestry
|
149
|
+
else
|
150
|
+
[locale]
|
151
|
+
end
|
152
|
+
|
99
153
|
locales
|
100
154
|
end
|
101
155
|
|
@@ -117,8 +171,8 @@ module Cldr
|
|
117
171
|
end
|
118
172
|
|
119
173
|
def component_should_merge_root?(component)
|
120
|
-
component
|
174
|
+
!%w(Rbnf Fields).include?(component)
|
121
175
|
end
|
122
176
|
end
|
123
177
|
end
|
124
|
-
end
|
178
|
+
end
|
data/lib/cldr/export/data.rb
CHANGED
@@ -3,31 +3,41 @@ require 'core_ext/string/camelize'
|
|
3
3
|
module Cldr
|
4
4
|
module Export
|
5
5
|
module Data
|
6
|
-
autoload :
|
7
|
-
autoload :
|
8
|
-
autoload :
|
9
|
-
autoload :
|
10
|
-
autoload :
|
11
|
-
autoload :
|
12
|
-
autoload :
|
13
|
-
autoload :
|
14
|
-
autoload :
|
15
|
-
autoload :
|
16
|
-
autoload :
|
17
|
-
autoload :
|
18
|
-
autoload :
|
19
|
-
autoload :
|
20
|
-
autoload :
|
21
|
-
autoload :
|
22
|
-
autoload :
|
23
|
-
autoload :
|
24
|
-
autoload :
|
6
|
+
autoload :Aliases, 'cldr/export/data/aliases'
|
7
|
+
autoload :Base, 'cldr/export/data/base'
|
8
|
+
autoload :Calendars, 'cldr/export/data/calendars'
|
9
|
+
autoload :Characters, 'cldr/export/data/characters'
|
10
|
+
autoload :Currencies, 'cldr/export/data/currencies'
|
11
|
+
autoload :CurrencyDigitsAndRounding, 'cldr/export/data/currency_digits_and_rounding'
|
12
|
+
autoload :Delimiters, 'cldr/export/data/delimiters'
|
13
|
+
autoload :Fields, 'cldr/export/data/fields'
|
14
|
+
autoload :Languages, 'cldr/export/data/languages'
|
15
|
+
autoload :Layout, 'cldr/export/data/layout'
|
16
|
+
autoload :LikelySubtags, 'cldr/export/data/likely_subtags'
|
17
|
+
autoload :Lists, 'cldr/export/data/lists'
|
18
|
+
autoload :Metazones, 'cldr/export/data/metazones'
|
19
|
+
autoload :NumberingSystems, 'cldr/export/data/numbering_systems'
|
20
|
+
autoload :Numbers, 'cldr/export/data/numbers'
|
21
|
+
autoload :ParentLocales, 'cldr/export/data/parent_locales'
|
22
|
+
autoload :Plurals, 'cldr/export/data/plurals'
|
23
|
+
autoload :PluralRules, 'cldr/export/data/plural_rules'
|
24
|
+
autoload :Rbnf, 'cldr/export/data/rbnf'
|
25
|
+
autoload :RbnfRoot, 'cldr/export/data/rbnf_root'
|
26
|
+
autoload :RegionCurrencies, 'cldr/export/data/region_currencies'
|
27
|
+
autoload :SegmentsRoot, 'cldr/export/data/segments_root'
|
28
|
+
autoload :Territories, 'cldr/export/data/territories'
|
29
|
+
autoload :TerritoriesContainment, 'cldr/export/data/territories_containment'
|
30
|
+
autoload :Timezones, 'cldr/export/data/timezones'
|
31
|
+
autoload :Units, 'cldr/export/data/units'
|
32
|
+
autoload :Variables, 'cldr/export/data/variables'
|
33
|
+
autoload :WindowsZones, 'cldr/export/data/windows_zones'
|
34
|
+
autoload :Transforms, 'cldr/export/data/transforms'
|
25
35
|
|
26
36
|
class << self
|
27
37
|
def dir
|
28
38
|
@dir ||= File.expand_path('./vendor/cldr/common')
|
29
39
|
end
|
30
|
-
|
40
|
+
|
31
41
|
def dir=(dir)
|
32
42
|
@dir = dir
|
33
43
|
end
|
@@ -42,4 +52,4 @@ module Cldr
|
|
42
52
|
end
|
43
53
|
end
|
44
54
|
end
|
45
|
-
end
|
55
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Cldr
|
2
|
+
module Export
|
3
|
+
module Data
|
4
|
+
class Aliases < Base
|
5
|
+
|
6
|
+
# only these aliases will be exported
|
7
|
+
ALIAS_TAGS = %w(languageAlias territoryAlias)
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super(nil)
|
11
|
+
update(:aliases => aliases)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def aliases
|
17
|
+
ALIAS_TAGS.inject({}) do |ret, alias_tag|
|
18
|
+
ret[alias_tag.sub('Alias', '')] = alias_for(alias_tag)
|
19
|
+
ret
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def alias_for(alias_tag)
|
24
|
+
doc.xpath("//alias/#{alias_tag}").inject({}) do |ret, alias_data|
|
25
|
+
if replacement_attr = alias_data.attribute('replacement')
|
26
|
+
replacement = replacement_attr.value
|
27
|
+
|
28
|
+
if replacement.include?(' ')
|
29
|
+
replacement = replacement.split(' ')
|
30
|
+
end
|
31
|
+
|
32
|
+
type = alias_data.attribute('type').value
|
33
|
+
ret[type] = replacement
|
34
|
+
end
|
35
|
+
|
36
|
+
ret
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def path
|
41
|
+
@path ||= "#{Cldr::Export::Data.dir}/supplemental/supplementalMetadata.xml"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Cldr
|
2
|
+
module Export
|
3
|
+
module Data
|
4
|
+
class Characters < Base
|
5
|
+
def initialize(locale)
|
6
|
+
super
|
7
|
+
update(:characters => { :exemplars => exemplars })
|
8
|
+
end
|
9
|
+
|
10
|
+
def exemplars
|
11
|
+
select('/ldml/characters/exemplarCharacters').map do |node|
|
12
|
+
{
|
13
|
+
# remove enclosing brackets
|
14
|
+
characters: node.content[1..-2],
|
15
|
+
type: type_from(node)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def type_from(node)
|
23
|
+
if attrib = node.attribute('type')
|
24
|
+
attrib.value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|