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.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +56 -46
  4. data/README.textile +6 -0
  5. data/Rakefile +2 -2
  6. data/VERSION +1 -1
  7. data/lib/cldr/download.rb +1 -1
  8. data/lib/cldr/export.rb +70 -16
  9. data/lib/cldr/export/data.rb +31 -21
  10. data/lib/cldr/export/data/aliases.rb +47 -0
  11. data/lib/cldr/export/data/base.rb +4 -0
  12. data/lib/cldr/export/data/characters.rb +30 -0
  13. data/lib/cldr/export/data/fields.rb +60 -0
  14. data/lib/cldr/export/data/languages.rb +1 -1
  15. data/lib/cldr/export/data/likely_subtags.rb +29 -0
  16. data/lib/cldr/export/data/numbers.rb +48 -6
  17. data/lib/cldr/export/data/parent_locales.rb +23 -0
  18. data/lib/cldr/export/data/plural_rules.rb +70 -0
  19. data/lib/cldr/export/data/rbnf.rb +12 -4
  20. data/lib/cldr/export/data/region_currencies.rb +45 -0
  21. data/lib/cldr/export/data/segments_root.rb +13 -3
  22. data/lib/cldr/export/data/territories.rb +1 -1
  23. data/lib/cldr/export/data/territories_containment.rb +30 -0
  24. data/lib/cldr/export/data/timezones.rb +18 -2
  25. data/lib/cldr/export/data/transforms.rb +76 -0
  26. data/lib/cldr/export/data/variables.rb +42 -0
  27. data/lib/cldr/export/yaml.rb +5 -21
  28. data/lib/cldr/thor.rb +2 -2
  29. data/test/export/data/calendars_test.rb +85 -51
  30. data/test/export/data/currencies_test.rb +29 -25
  31. data/test/export/data/languages_test.rb +69 -51
  32. data/test/export/data/numbers_test.rb +61 -62
  33. data/test/export/data/plurals_test.rb +4 -3
  34. data/test/export/data/territories_containment_test.rb +10 -0
  35. data/test/export/data/territories_test.rb +12 -5
  36. data/test/export/data/timezones_test.rb +5 -8
  37. data/test/export_test.rb +57 -5
  38. data/test/format/time_test.rb +5 -5
  39. metadata +40 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: af120af07a9dd0cfa1b2a718088d8c2587047ea6
4
- data.tar.gz: ec6fecc2e0250efa4a5cebe8dc51dd3c3179eb90
2
+ SHA256:
3
+ metadata.gz: 1ac65fa730274ef7d70f6dde1a20a4a6ed4a36f1407d65e12ba220539d6a0424
4
+ data.tar.gz: 900156546c3603e66501d527714a8b9ac3c66287ebde5672f699da68d5cbbfc8
5
5
  SHA512:
6
- metadata.gz: 2669e246eb3a7e6a465d55036c99c32bc6d88c77fecf536270cfdc8c5d46c091c0d7c1574e466f6962033a791e92c7e02682905b3f41113065c86e41464156eb
7
- data.tar.gz: 328fb66d4fa4e45de8d8268ca0270c40ef008b6aaaedb6dd2764668493cb53204cb7e4bd191a569baac03950ced613fc52895690d43131181f0aa8f1fba61fd2
6
+ metadata.gz: '0589799c818cf86570883c73bcb095889496bc158026d51557829ba3c9eda8f13c1879823689c1263eee20931b77bd0a01de4e6680cfb5064ccb807a36fb0e69'
7
+ data.tar.gz: 642f18b73738a815314e6c0ee39ceac70c0f5d26c89027f4936f9089b577943481a8422980674bf725dd6243cce449af96d13ba5567f499564b9f42420ab40f2
data/Gemfile CHANGED
@@ -2,7 +2,6 @@ source "http://rubygems.org"
2
2
 
3
3
  gem 'thor'
4
4
  gem 'i18n'
5
- gem 'ya2yaml'
6
5
  gem 'nokogiri'
7
6
 
8
7
  group :development do
@@ -10,4 +9,5 @@ group :development do
10
9
  gem 'jeweler'
11
10
  gem 'pry'
12
11
  gem 'pry-nav'
12
+ gem 'test-unit'
13
13
  end
data/Gemfile.lock CHANGED
@@ -1,63 +1,70 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.3.5)
5
- builder (3.2.2)
6
- coderay (1.0.9)
7
- descendants_tracker (0.0.3)
8
- faraday (0.9.0)
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.2.6)
11
- github_api (0.11.2)
12
- addressable (~> 2.3)
13
- descendants_tracker (~> 0.0.1)
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 (>= 1.2)
16
- multi_json (>= 1.7.5, < 2.0)
17
- nokogiri (~> 1.6.0)
18
- oauth2
19
- hashie (2.0.5)
20
- highline (1.6.20)
21
- i18n (0.6.0)
22
- jeweler (2.0.1)
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 (>= 1.0)
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
- json (1.8.1)
32
- jwt (0.1.11)
33
- multi_json (>= 1.5)
34
- method_source (0.8.1)
35
- mini_portile (0.5.2)
36
- multi_json (1.8.4)
37
- multi_xml (0.5.5)
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.6.1)
40
- mini_portile (~> 0.5.0)
41
- oauth2 (0.9.3)
42
- faraday (>= 0.8, < 0.10)
43
- jwt (~> 0.1.8)
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 (~> 1.2)
47
- pry (0.9.12)
48
- coderay (~> 1.0.5)
49
- method_source (~> 0.8)
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.3)
52
- pry (~> 0.9.10)
53
- rack (1.5.2)
54
- rake (10.1.1)
55
- rdoc (4.1.1)
56
- json (~> 1.4)
57
- rubyzip (1.1.0)
58
- slop (3.4.3)
59
- thor (0.14.6)
60
- ya2yaml (0.30)
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
- ya2yaml
81
+
82
+ BUNDLED WITH
83
+ 2.0.1
data/README.textile CHANGED
@@ -98,6 +98,12 @@ E.g.:
98
98
  # => "12. November 2010 13:14"
99
99
  </pre>
100
100
 
101
+ h2. Tests
102
+
103
+ <pre>
104
+ bundle exec ruby test/all.rb
105
+ </pre>
106
+
101
107
  h2. Resources
102
108
 
103
109
  For additional information on CLDR plural rules see:
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/svenfuchs/ruby-cldr"
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.1
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/24/core.zip'
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 'i18n/locale/fallbacks'
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
- 'CurrencyDigitsAndRounding',
17
- 'RbnfRoot',
18
- 'Metazones',
19
- 'WindowsZones',
20
- 'NumberingSystems',
21
- 'SegmentsRoot'
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
- ex = exporter(component, options[:format])
44
- ex.export('', component, options, &block)
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
- Data.const_get(component.to_s.camelize).new
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.to_s.gsub('_', '-')
97
- locales = options[:merge] ? I18n::Locale::Fallbacks.new[locale.to_sym] : [locale.to_sym]
98
- locales << :root if component_should_merge_root?(component)
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 != "Rbnf"
174
+ !%w(Rbnf Fields).include?(component)
121
175
  end
122
176
  end
123
177
  end
124
- end
178
+ end
@@ -3,31 +3,41 @@ require 'core_ext/string/camelize'
3
3
  module Cldr
4
4
  module Export
5
5
  module Data
6
- autoload :Base, 'cldr/export/data/base'
7
- autoload :Calendars, 'cldr/export/data/calendars'
8
- autoload :Currencies, 'cldr/export/data/currencies'
9
- autoload :CurrencyDigitsAndRounding, 'cldr/export/data/currency_digits_and_rounding'
10
- autoload :Delimiters, 'cldr/export/data/delimiters'
11
- autoload :Languages, 'cldr/export/data/languages'
12
- autoload :Numbers, 'cldr/export/data/numbers'
13
- autoload :Plurals, 'cldr/export/data/plurals'
14
- autoload :Territories, 'cldr/export/data/territories'
15
- autoload :Timezones, 'cldr/export/data/timezones'
16
- autoload :Metazones, 'cldr/export/data/metazones'
17
- autoload :WindowsZones, 'cldr/export/data/windows_zones'
18
- autoload :Units, 'cldr/export/data/units'
19
- autoload :Lists, 'cldr/export/data/lists'
20
- autoload :Layout, 'cldr/export/data/layout'
21
- autoload :Rbnf, 'cldr/export/data/rbnf'
22
- autoload :RbnfRoot, 'cldr/export/data/rbnf_root'
23
- autoload :NumberingSystems, 'cldr/export/data/numbering_systems'
24
- autoload :SegmentsRoot, 'cldr/export/data/segments_root'
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
@@ -31,6 +31,10 @@ module Cldr
31
31
  draft && draft.value == 'unconfirmed'
32
32
  end
33
33
 
34
+ def alt?(node)
35
+ !node.attribute('alt').nil?
36
+ end
37
+
34
38
  def name(node)
35
39
  node.name.underscore
36
40
  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