Created
May 24, 2012 23:48
-
-
Save camertron/2784928 to your computer and use it in GitHub Desktop.
Exporting base CLDR data using Sven Fuch's ruby-cldr gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'ruby-cldr' | |
require 'cldr' | |
require 'cldr/data' | |
require 'cldr/download' | |
require 'yaml' | |
# NOTE: nb = no (norwegian) | |
locales = ["he", "en", "fr", "it", "de", "es", "ja", "ko", "ru", "tr", "pt", "fil", "hi", "ms", "id", "nl", "da", "sv", "pl", "hu", "fi", "nb", "zh", "zh-Hant", "ar", "fa", "ur", "th", "uk", "ca", "el", "af", "cs", "eu"] | |
components = ["calendars", "currencies", "delimiters", "languages", "numbers", "Plurals", "territories", "timezones", "units"] | |
Cldr.download(nil, "/tmp/cldr") | |
Cldr::Export::Data.dir = "/tmp/cldr/common" | |
Cldr::Export.export(:locales => locales, :components => components, :target => "/tmp/cldr/export") | |
# for some reason the generation of the plurals.yml file is broken, so we have to convert them from the .rb files here | |
locales.each do |locale| | |
begin | |
File.open(File.join("/tmp/cldr/export", locale, "plurals.yml"), "w+") do |f| | |
f.write(YAML.dump({ locale => File.read(File.join("/tmp/cldr/export", locale, "plurals.rb")) })) | |
end | |
FileUtils.rm(File.join("/tmp/cldr/export", locale, "plurals.rb")) | |
rescue | |
end | |
end | |
# copy zh plurals to zh-Hant (they can share, but locale code needs to be different) | |
File.open("/tmp/cldr/export/zh-Hant/plurals.yml", "w+") do |f| | |
f.write(File.read("/tmp/cldr/export/zh/plurals.yml").gsub("zh:", "zh-Hant:").gsub(":zh", ":'zh-Hant'")) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment