Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding more translations. adding rake import task. bumping version
- Loading branch information
Showing
11 changed files
with
1,171 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Binary file not shown.
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,3 @@ | |||
module I18nCountryTranslations | module I18nCountryTranslations | ||
VERSION = "0.0.3" | VERSION = "0.0.4" | ||
end | end |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,73 @@ | |||
# desc "Explaining what the task does" | require 'rubygems' | ||
# task :i18n-country-translations do | require 'open-uri' | ||
# # Task goes here |
|
||
# end | # Rake task for importing country names from Unicode.org's CLDR repository | ||
# (http://www.unicode.org/cldr/data/charts/summary/root.html). | |||
# | |||
# It parses a HTML file from Unicode.org for given locale and saves the | |||
# Rails' I18n hash in the plugin +locale+ directory | |||
# | |||
|
|||
namespace :import do | |||
|
|||
desc "Import country codes and names for various languages from the Unicode.org CLDR archive. Depends on Hpricot gem." | |||
task :country_translation do | |||
begin | |||
require 'hpricot' | |||
rescue LoadError | |||
puts "Error: Hpricot library required to use this task (import:country_select)" | |||
exit | |||
end | |||
|
|||
# Setup variables | |||
locale = ENV['IMPORT_LOCALE'] | |||
unless locale | |||
puts "\n[!] Usage: IMPORT_LOCALE=de rake import:country_translation\n\n" | |||
exit 0 | |||
end | |||
|
|||
# ----- Get the CLDR HTML -------------------------------------------------- | |||
begin | |||
doc = Hpricot( open("http://www.unicode.org/cldr/data/charts/summary/#{locale}.html") ) | |||
rescue => e | |||
puts "[!] Invalid locale name '#{locale}'! Not found in CLDR (#{e})" | |||
exit 0 | |||
end | |||
|
|||
|
|||
# ----- Parse the HTML with Hpricot ---------------------------------------- | |||
countries = [] | |||
doc.search("//tr").each do |row| | |||
if row.search("td[@class='n']") && | |||
row.search("td[@class='n']").inner_html =~ /^namesterritory$/ && | |||
row.search("td[@class='g']").inner_html =~ /^[A-Z]{2}/ | |||
code = row.search("td[@class='g']").inner_text | |||
code = code[-code.size, 2] | |||
name = row.search("td[@class='v']").inner_text | |||
countries << { :code => code.to_sym, :name => name.to_s } | |||
end | |||
end | |||
|
|||
|
|||
# ----- Prepare the output format ------------------------------------------ | |||
output =<<HEAD | |||
#{locale}: | |||
countries: | |||
HEAD | |||
countries.each do |country| | |||
output << " #{country[:code]}: \"#{country[:name]}\"\n" | |||
end | |||
output <<<<TAIL | |||
TAIL | |||
|
|||
|
|||
# ----- Write the parsed values into file --------------------------------- | |||
puts "\n... writing the output" | |||
filename = File.join(File.dirname(__FILE__), '..', '..', 'rails', 'locale', "#{locale}.yml") | |||
filename += '.NEW' if File.exists?(filename) # Append 'NEW' if file exists | |||
File.open(filename, 'w+') { |f| f << output } | |||
puts "\n---\nWritten values for the '#{locale}' into file: #{filename}\n" | |||
# ------------------------------------------------------------------------------ | |||
end | |||
|
|||
end |
Oops, something went wrong.