ruby-cldr 0.1.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +53 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +56 -46
  5. data/README.textile +8 -0
  6. data/Rakefile +2 -2
  7. data/VERSION +1 -1
  8. data/lib/cldr/download.rb +1 -1
  9. data/lib/cldr/export.rb +74 -16
  10. data/lib/cldr/export/data.rb +34 -21
  11. data/lib/cldr/export/data/aliases.rb +47 -0
  12. data/lib/cldr/export/data/base.rb +4 -0
  13. data/lib/cldr/export/data/characters.rb +30 -0
  14. data/lib/cldr/export/data/country_codes.rb +29 -0
  15. data/lib/cldr/export/data/currencies.rb +13 -3
  16. data/lib/cldr/export/data/fields.rb +60 -0
  17. data/lib/cldr/export/data/languages.rb +1 -1
  18. data/lib/cldr/export/data/likely_subtags.rb +29 -0
  19. data/lib/cldr/export/data/numbers.rb +48 -6
  20. data/lib/cldr/export/data/parent_locales.rb +23 -0
  21. data/lib/cldr/export/data/plural_rules.rb +70 -0
  22. data/lib/cldr/export/data/plurals/rules.rb +12 -1
  23. data/lib/cldr/export/data/rbnf.rb +12 -4
  24. data/lib/cldr/export/data/region_currencies.rb +45 -0
  25. data/lib/cldr/export/data/segments_root.rb +61 -0
  26. data/lib/cldr/export/data/subdivisions.rb +35 -0
  27. data/lib/cldr/export/data/territories.rb +1 -1
  28. data/lib/cldr/export/data/territories_containment.rb +30 -0
  29. data/lib/cldr/export/data/timezones.rb +18 -2
  30. data/lib/cldr/export/data/transforms.rb +76 -0
  31. data/lib/cldr/export/data/variables.rb +42 -0
  32. data/lib/cldr/export/yaml.rb +5 -21
  33. data/lib/cldr/thor.rb +2 -2
  34. data/ruby-cldr.gemspec +157 -0
  35. data/test/export/data/calendars_test.rb +102 -52
  36. data/test/export/data/country_codes_test.rb +21 -0
  37. data/test/export/data/currencies_test.rb +40 -26
  38. data/test/export/data/languages_test.rb +69 -51
  39. data/test/export/data/numbers_test.rb +61 -62
  40. data/test/export/data/plurals_test.rb +10 -3
  41. data/test/export/data/subdivisions_test.rb +33 -0
  42. data/test/export/data/territories_containment_test.rb +10 -0
  43. data/test/export/data/territories_test.rb +12 -5
  44. data/test/export/data/timezones_test.rb +5 -8
  45. data/test/export_test.rb +57 -5
  46. data/test/format/time_test.rb +5 -5
  47. metadata +51 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 81ab6a59909b72f15381d80ca49053ca46bc54fb
4
- data.tar.gz: 32e6c9fcd5291e54460abaeafc0f12189cc541e6
2
+ SHA256:
3
+ metadata.gz: '08d81c0b6ee1d96ffa243d2ebf097de3daf26cbfdaa017e461bf57019fa6f2c3'
4
+ data.tar.gz: 623a6819224e69f397169989b3aafe7e63a348d2a2f579f4e3375d6853f2b70d
5
5
  SHA512:
6
- metadata.gz: fd2828beca0c9f5828cfcf9b25c5e973d8183ab17b7b93e5dfab4d6b1e92002fa5706d52f8a8ada8b840b18043bdb5bfb4a14379993753b4c536abd411f2139a
7
- data.tar.gz: e51615436d0dfb6718627014defbdeff88093345aa00467e325cad301ac6a5b9c868a85ad8d4c72eacf872f898a4dacfae7e71e81fbf0f2608c47d10e82b3af7
6
+ metadata.gz: b3e3a11bbf75be01de319dfe8a5941ac0c4cfe2f7d8526484de7b7ce9b4449d9bbc0edc4d857b442047f8b57e2e6c198f19532f13b1ef2b17fe3cabf84a908bb
7
+ data.tar.gz: 4c1f2d8503207ae9fdc5ec626b7441f89d98ccd505acb9ba43f536522ea9a392bd5cca2ba7ab964ee6d5dad88429571f8a97612eff83423b0ecc17da00743d5c
@@ -0,0 +1,53 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
+
6
+ ## How do I make a good changelog?
7
+ ### Guiding Principles
8
+ - Changelogs are for humans, not machines.
9
+ - There should be an entry for every single version.
10
+ - The same types of changes should be grouped.
11
+ - Versions and sections should be linkable.
12
+ - The latest version comes first.
13
+ - The release date of each version is displayed.
14
+ - Mention whether you follow Semantic Versioning.
15
+
16
+ ### Types of changes
17
+ - Added for new features.
18
+ - Changed for changes in existing functionality.
19
+ - Deprecated for soon-to-be removed features.
20
+ - Removed for now removed features.
21
+ - Fixed for any bug fixes.
22
+ - Security in case of vulnerabilities.
23
+
24
+ ## [Unreleased]
25
+
26
+ ---
27
+
28
+ ## [0.2.0] - 2019-03-26
29
+
30
+ - Updated to CLDR 34 [#43](https://github.com/ruby-i18n/ruby-cldr/pull/43)
31
+ - Lots of [other changes](https://github.com/ruby-i18n/ruby-cldr/compare/v0.1.1...v0.2.0)
32
+
33
+ ## [0.3.0] - 2019-06-16
34
+
35
+ - Export currency names [#51](https://github.com/ruby-i18n/ruby-cldr/pull/51)
36
+ - Bring back root fallback for english [#47](https://github.com/ruby-i18n/ruby-cldr/pull/47)
37
+ - Export subdivisions [#46](https://github.com/ruby-i18n/ruby-cldr/pull/46)
38
+
39
+ ## [0.4.0] - 2020-09-01
40
+
41
+ - Support pluralization codes with missing spaces [#53](https://github.com/ruby-i18n/ruby-cldr/pull/53)
42
+ - Add in functionality to export country codes [#61](https://github.com/ruby-i18n/ruby-cldr/pull/61)
43
+
44
+ ## [0.5.0] - 2020-11-20
45
+
46
+ - Added a changelog, [#49](https://github.com/ruby-i18n/ruby-cldr/pull/49)
47
+ - Added Travis CI for testing, [#48](https://github.com/ruby-i18n/ruby-cldr/pull/48)
48
+ - Added root fallback to en language, [#47](https://github.com/ruby-i18n/ruby-cldr/pull/47)
49
+ - Added subdivisions to the list of exportable components, [#46](https://github.com/ruby-i18n/ruby-cldr/pull/46)
50
+ - Added country codes as an exportable component, [#61](https://github.com/ruby-i18n/ruby-cldr/pull/61)
51
+ - Added narrow symbols to exported currency data, [#64](https://github.com/ruby-i18n/ruby-cldr/pull/64)
52
+
53
+ [Unreleased]: https://github.com/ruby-i18n/ruby-cldr/compare/v0.5.0...HEAD
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
@@ -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.8)
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.2.3)
59
+ rake (13.0.1)
60
+ rdoc (6.1.1)
61
+ rubyzip (1.3.0)
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.1.4
@@ -1,5 +1,7 @@
1
1
  h1. Ruby library for exporting and using data from CLDR
2
2
 
3
+ !https://travis-ci.com/ruby-i18n/ruby-cldr.svg?branch=master!:https://travis-ci.com/ruby-i18n/ruby-cldr
4
+
3
5
  CLDR ("Common Locale Data Repository":http://cldr.unicode.org) contains tons of high-quality locale data such as formatting rules for dates, times, numbers, currencies as well as language, country, calendar-specific names etc.
4
6
 
5
7
  For localizing applications in Ruby we'll obviously be able to use this incredibly comprehensive and well-maintained resource.
@@ -98,6 +100,12 @@ E.g.:
98
100
  # => "12. November 2010 13:14"
99
101
  </pre>
100
102
 
103
+ h2. Tests
104
+
105
+ <pre>
106
+ bundle exec ruby test/all.rb
107
+ </pre>
108
+
101
109
  h2. Resources
102
110
 
103
111
  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.0
1
+ 0.5.0
@@ -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|
@@ -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,12 +13,20 @@ 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'
16
+ SHARED_COMPONENTS = %w[
17
+ CountryCodes
18
+ CurrencyDigitsAndRounding
19
+ Metazones
20
+ NumberingSystems
21
+ RbnfRoot
22
+ SegmentsRoot
23
+ TerritoriesContainment
24
+ WindowsZones
25
+ Transforms
26
+ LikelySubtags
27
+ Variables
28
+ Aliases
29
+ RegionCurrencies
21
30
  ]
22
31
 
23
32
  class << self
@@ -39,8 +48,23 @@ module Cldr
39
48
  end
40
49
 
41
50
  shared_components.each do |component|
42
- ex = exporter(component, options[:format])
43
- ex.export('', component, options, &block)
51
+ case component
52
+ when "Transforms"
53
+ yaml_exporter = Cldr::Export::Yaml.new
54
+ Dir.glob("#{Cldr::Export::Data.dir}/transforms/**.xml").each do |transform_file|
55
+ data = Data::Transforms.new(transform_file)
56
+ source = data[:transforms].first[:source]
57
+ target = data[:transforms].first[:target]
58
+ variant = data[:transforms].first[:variant]
59
+ file_name = [source, target, variant].compact.join('-')
60
+ output_path = File.join(base_path, "transforms", "#{file_name}.yml")
61
+ write(output_path, yaml_exporter.yaml(data))
62
+ yield component, nil, output_path if block_given?
63
+ end
64
+ else
65
+ ex = exporter(component, options[:format])
66
+ ex.export('', component, options, &block)
67
+ end
44
68
  end
45
69
 
46
70
  locales.each do |locale|
@@ -88,13 +112,45 @@ module Cldr
88
112
  end
89
113
 
90
114
  def shared_data(component, options = {})
91
- Data.const_get(component.to_s.camelize).new
115
+ case component.to_s
116
+ when 'Transforms'
117
+ # do nothing, this has to be handled separately
118
+ else
119
+ Data.const_get(component.to_s.camelize).new
120
+ end
121
+ end
122
+
123
+ def to_i18n(locale)
124
+ return locale.to_s.gsub('_', '-').to_sym
125
+ end
126
+
127
+ def from_i18n(locale)
128
+ return locale.to_s.gsub('-', '_')
92
129
  end
93
130
 
94
131
  def locales(locale, component, options)
95
- locale = locale.to_s.gsub('_', '-')
96
- locales = options[:merge] ? I18n::Locale::Fallbacks.new[locale.to_sym] : [locale.to_sym]
97
- locales << :root if component_should_merge_root?(component)
132
+ locale = to_i18n(locale)
133
+
134
+ locales = if options[:merge]
135
+ defined_parents = Cldr::Export::Data::ParentLocales.new
136
+
137
+ ancestry = [locale]
138
+ loop do
139
+ if defined_parents[from_i18n(ancestry.last)]
140
+ ancestry << to_i18n(defined_parents[from_i18n(ancestry.last)])
141
+ elsif I18n::Locale::Tag.tag(ancestry.last).self_and_parents.count > 1
142
+ ancestry << I18n::Locale::Tag.tag(ancestry.last).self_and_parents.last.to_sym
143
+ else
144
+ break
145
+ end
146
+ end
147
+
148
+ ancestry
149
+ else
150
+ [locale]
151
+ end
152
+
153
+ locales << :root if should_merge_root?(locale, component, options)
98
154
  locales
99
155
  end
100
156
 
@@ -115,9 +171,11 @@ module Cldr
115
171
  SHARED_COMPONENTS.include?(component)
116
172
  end
117
173
 
118
- def component_should_merge_root?(component)
119
- component != "Rbnf"
174
+ def should_merge_root?(locale, component, options)
175
+ return false if %w(Rbnf Fields).include?(component)
176
+ return true if options[:merge]
177
+ locale == :en
120
178
  end
121
179
  end
122
180
  end
123
- end
181
+ end
@@ -3,30 +3,43 @@ 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'
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 :CountryCodes, 'cldr/export/data/country_codes'
11
+ autoload :Currencies, 'cldr/export/data/currencies'
12
+ autoload :CurrencyDigitsAndRounding, 'cldr/export/data/currency_digits_and_rounding'
13
+ autoload :Delimiters, 'cldr/export/data/delimiters'
14
+ autoload :Fields, 'cldr/export/data/fields'
15
+ autoload :Languages, 'cldr/export/data/languages'
16
+ autoload :Layout, 'cldr/export/data/layout'
17
+ autoload :LikelySubtags, 'cldr/export/data/likely_subtags'
18
+ autoload :Lists, 'cldr/export/data/lists'
19
+ autoload :Metazones, 'cldr/export/data/metazones'
20
+ autoload :NumberingSystems, 'cldr/export/data/numbering_systems'
21
+ autoload :Numbers, 'cldr/export/data/numbers'
22
+ autoload :ParentLocales, 'cldr/export/data/parent_locales'
23
+ autoload :Plurals, 'cldr/export/data/plurals'
24
+ autoload :PluralRules, 'cldr/export/data/plural_rules'
25
+ autoload :Rbnf, 'cldr/export/data/rbnf'
26
+ autoload :RbnfRoot, 'cldr/export/data/rbnf_root'
27
+ autoload :RegionCurrencies, 'cldr/export/data/region_currencies'
28
+ autoload :SegmentsRoot, 'cldr/export/data/segments_root'
29
+ autoload :Subdivisions, 'cldr/export/data/subdivisions'
30
+ autoload :Territories, 'cldr/export/data/territories'
31
+ autoload :TerritoriesContainment, 'cldr/export/data/territories_containment'
32
+ autoload :Timezones, 'cldr/export/data/timezones'
33
+ autoload :Units, 'cldr/export/data/units'
34
+ autoload :Variables, 'cldr/export/data/variables'
35
+ autoload :WindowsZones, 'cldr/export/data/windows_zones'
36
+ autoload :Transforms, 'cldr/export/data/transforms'
24
37
 
25
38
  class << self
26
39
  def dir
27
40
  @dir ||= File.expand_path('./vendor/cldr/common')
28
41
  end
29
-
42
+
30
43
  def dir=(dir)
31
44
  @dir = dir
32
45
  end
@@ -36,9 +49,9 @@ module Cldr
36
49
  end
37
50
 
38
51
  def components
39
- self.constants.sort - [:Base, :Export]
52
+ self.constants.sort - [:Base, :Export, :ParentLocales]
40
53
  end
41
54
  end
42
55
  end
43
56
  end
44
- end
57
+ end