Permalink
Browse files

Use currencies_importer from ruby-cldr

  • Loading branch information...
1 parent 710a007 commit 88f176ec274b04e5e9f2852160a2e8c8974f5c3b Tanin Na Nakorn committed Nov 2, 2012
Showing with 29,879 additions and 21,575 deletions.
  1. +0 −8 Rakefile
  2. +1 −1 lib/twitter_cldr.rb
  3. +0 −106 lib/twitter_cldr/resources/currencies_importer.rb
  4. +1 −1 lib/twitter_cldr/resources/locales_resources_importer.rb
  5. +4 −24 lib/twitter_cldr/shared/currencies.rb
  6. +350 −327 resources/locales/af/currencies.yml
  7. +1,462 −528 resources/locales/ar/currencies.yml
  8. +65 −31 resources/locales/be/currencies.yml
  9. +755 −526 resources/locales/bg/currencies.yml
  10. +560 −535 resources/locales/bn/currencies.yml
  11. +897 −583 resources/locales/ca/currencies.yml
  12. +1,052 −525 resources/locales/cs/currencies.yml
  13. +53 −34 resources/locales/cy/currencies.yml
  14. +809 −532 resources/locales/da/currencies.yml
  15. +834 −543 resources/locales/de/currencies.yml
  16. +862 −562 resources/locales/el/currencies.yml
  17. +904 −594 resources/locales/en/currencies.yml
  18. +816 −552 resources/locales/es/currencies.yml
  19. +335 −312 resources/locales/eu/currencies.yml
  20. +442 −419 resources/locales/fa/currencies.yml
  21. +899 −587 resources/locales/fi/currencies.yml
  22. +346 −323 resources/locales/fil/currencies.yml
  23. +902 −614 resources/locales/fr/currencies.yml
  24. +510 −489 resources/locales/ga/currencies.yml
  25. +466 −403 resources/locales/gl/currencies.yml
  26. +469 −445 resources/locales/he/currencies.yml
  27. +377 −354 resources/locales/hi/currencies.yml
  28. +636 −547 resources/locales/hu/currencies.yml
  29. +390 −368 resources/locales/id/currencies.yml
  30. +713 −538 resources/locales/it/currencies.yml
  31. +565 −546 resources/locales/ja/currencies.yml
  32. +561 −538 resources/locales/ko/currencies.yml
  33. +511 −407 resources/locales/lv/currencies.yml
  34. +334 −311 resources/locales/ms/currencies.yml
  35. +754 −549 resources/locales/nb/currencies.yml
  36. +582 −544 resources/locales/nl/currencies.yml
  37. +1,048 −519 resources/locales/pl/currencies.yml
  38. +900 −586 resources/locales/pt/currencies.yml
  39. +936 −487 resources/locales/ro/currencies.yml
  40. +0 −614 resources/locales/root/currencies.yml
  41. +1,043 −549 resources/locales/ru/currencies.yml
  42. +576 −500 resources/locales/sk/currencies.yml
  43. +55 −18 resources/locales/sq/currencies.yml
  44. +1,488 −590 resources/locales/sr/currencies.yml
  45. +902 −591 resources/locales/sv/currencies.yml
  46. +333 −310 resources/locales/ta/currencies.yml
  47. +565 −543 resources/locales/th/currencies.yml
  48. +568 −547 resources/locales/tr/currencies.yml
  49. +785 −553 resources/locales/uk/currencies.yml
  50. +348 −326 resources/locales/ur/currencies.yml
  51. +558 −0 resources/locales/zh-Hant/currencies.yml
  52. +557 −536 resources/locales/zh/currencies.yml
View
@@ -79,14 +79,6 @@ namespace :update do
).import
end
- desc 'Import currencies resource'
- task :currencies, :cldr_path do |_, args|
- TwitterCldr::Resources::CurrenciesImporter.new(
- args[:cldr_path] || './vendor/cldr',
- './resources/locales'
- ).import
- end
-
desc 'Import currency digits and rounding resource'
task :currency_digits_and_rounding, :cldr_path do |_, args|
TwitterCldr::Resources::CurrencyDigitsAndRoundingImporter.new(
View
@@ -80,7 +80,7 @@ def twitter_locale(locale)
end
def supported_locales
- @supported_locales ||= (Dir.glob(File.join(RESOURCES_DIR, 'locales', '*')).map { |f| File.basename(f).to_sym } - [:root])
+ @supported_locales ||= Dir.glob(File.join(RESOURCES_DIR, 'locales', '*')).map { |f| File.basename(f).to_sym }
end
def supported_locale?(locale)
@@ -1,106 +0,0 @@
-# encoding: UTF-8
-
-# Copyright 2012 Twitter, Inc
-# http://www.apache.org/licenses/LICENSE-2.0
-
-require 'nokogiri'
-require 'fileutils'
-
-require 'twitter_cldr/resources/download'
-
-module TwitterCldr
- module Resources
- class CurrenciesImporter
-
- LOCALES_PATH = File.join('common', 'main')
- CURRENCY_TYPES_PATH = File.join('common', 'bcp47', 'currency.xml')
- SUPPLEMENTAL_DATA_PATH = File.join('common', 'supplemental', 'supplementalData.xml')
-
- # Arguments:
- #
- # input_path - path to a directory containing CLDR data
- # output_path - output directory for generated YAML file
- #
- def initialize(input_path, output_path)
- @input_path = input_path
- @output_path = output_path
- end
-
- def import
- TwitterCldr::Resources.download_cldr_if_necessary(@input_path)
-
- @currencies = {:root => {}}
-
- # Get all types
- currency_types_doc = File.open(File.join(@input_path, CURRENCY_TYPES_PATH)) { |file| Nokogiri::XML(file) }
- currency_types_doc.xpath('//ldmlBCP47/keyword/key/type').each do |node|
- code = node.attr('name').upcase.to_sym
- name = node.attr('description')
- @currencies[:root][code] = {
- :name => name
- }
- end
-
- # Get default symbols
- root = File.open(File.join(@input_path, LOCALES_PATH, "root.xml")) { |file| Nokogiri::XML(file) }
- root.xpath('//currencies/currency').each do |node|
- code = node.attr('type').upcase.to_sym
- symbol = node.xpath("./symbol").inner_html
- @currencies[:root][code][:symbol] = symbol
- end
-
- Dir.foreach(File.join(@input_path, LOCALES_PATH)) do |filename|
- next if File.file?(File.join(@input_path, LOCALES_PATH, filename)) == false
- import_per_locale(File.basename(filename, ".xml"))
- end
- end
-
- def import_per_locale(current_locale)
- return if !File.exist?(File.join(@output_path, current_locale)) and current_locale != "root"
-
- this_currencies = {}
- get_currencies(current_locale).each_pair do |code, data|
- this_currencies[code] ||= {}
- data.each_pair do |k, v|
- this_currencies[code][k] ||= v
- end
- end
-
- return if this_currencies.size == 0
-
- FileUtils.mkdir_p(File.join(@output_path, current_locale))
-
- this_currencies = Hash[this_currencies.sort_by{|a,b| a.to_s <=> b.to_s}]
- File.open(File.join(@output_path, current_locale, 'currencies.yml'), 'w') do |output|
- output.write(YAML.dump(this_currencies))
- end
- end
-
- def get_currencies(locale)
- locale = locale.to_sym
- return @currencies[locale] if @currencies[locale]
-
- @currencies[locale] = {}
-
- root = File.open(File.join(@input_path, LOCALES_PATH, "#{locale}.xml")) { |file| Nokogiri::XML(file) }
- root.xpath('//currencies/currency').each do |node|
- code = node.attr('type').upcase.to_sym
-
- @currencies[locale][code] ||= {}
-
- symbol = node.xpath("./symbol")
- @currencies[locale][code][:symbol] = symbol.inner_html if symbol and symbol.inner_html != ""
-
- name = node.xpath("./displayName").first
- @currencies[locale][code][:name] = name.inner_html if name and name.inner_html != ""
-
- if @currencies[locale][code].size == 0
- @currencies[locale].delete(code)
- end
- end
-
- @currencies[locale]
- end
- end
- end
-end
@@ -12,7 +12,7 @@ module Resources
class LocalesResourcesImporter
- COMPONENTS = %w[calendars languages numbers units plurals lists layout]
+ COMPONENTS = %w[calendars languages numbers units plurals lists layout currencies]
# Arguments:
#
@@ -8,7 +8,7 @@ module Shared
module Currencies
class << self
def countries
- Kernal.warn("Currencies#countries will be deprecated. Please stop using it.")
+ Kernel.warn("Currencies#countries will be deprecated. Please stop using it.")
resource_countries.keys.map(&:to_s)
end
@@ -17,7 +17,7 @@ def currency_codes(locale = :en)
end
def for_country(country_name, locale = :en)
- Kernal.warn("Currencies#for_country will be deprecated. Please stop using it.")
+ Kernel.warn("Currencies#for_country will be deprecated. Please stop using it.")
return nil if !resource_countries[country_name.to_sym]
for_code(resource_countries[country_name.to_sym][:code], locale)
end
@@ -26,7 +26,7 @@ def for_code(currency_code, locale = :en)
currency_code = currency_code.to_sym
data = resource(locale)[currency_code]
{ :currency => currency_code,
- :name => data[:name],
+ :name => data[:one],
:symbol => data[:symbol] } if data
end
@@ -39,27 +39,7 @@ def resource_countries
def resource(locale)
locale = locale.to_sym
@resource ||= {}
- return @resource[locale] if @resource[locale]
-
- fallbacks = locale.to_s.split("_").inject([]) do |list, t|
- list.push((list.length == 0) ? t : "#{list.last}_#{t}")
- end.reverse
-
- fallbacks.push("root")
-
- @resource[locale] = {}
-
- fallbacks.each do |l|
- r = TwitterCldr.get_resource(:locales, l, :currencies)
- r.each_pair do |code, data|
- @resource[locale][code] ||= {}
- data.each_pair do |k, v|
- @resource[locale][code][k] ||= v
- end
- end
- end
-
- @resource[locale]
+ @resource[locale] ||= TwitterCldr.get_resource(:locales, locale, :currencies)[locale][:currencies]
end
end
end
Oops, something went wrong.

0 comments on commit 88f176e

Please sign in to comment.