Skip to content

Commit

Permalink
Merge pull request mlitwiniuk#4 from freegenie/master
Browse files Browse the repository at this point in the history
Better command line call, namespace, and existing file fixed
  • Loading branch information
mlitwiniuk committed Jan 15, 2013
2 parents 1c475e8 + 3ffda84 commit 868bc46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can easily translate country codes in your application like this:

<%= I18n.t @user.country, :scope => 'countries' %>

Comes with a Rake task <tt>rake import:country_select 'de'</tt> for importing country names
Comes with a Rake task <tt>rake import:country_select LOCALE=de</tt> for importing country names
from Unicode.org's CLDR repository (http://www.unicode.org/cldr/data/charts/summary/root.html)
Don't forget to restart the application when you add new locale.

Expand Down
10 changes: 6 additions & 4 deletions lib/tasks/localized_country_select_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ namespace :import do
# TODO : Implement locale import chooser from CLDR root via Highline

# Setup variables
locale = ARGV[1]
locale = ENV['LOCALE']
unless locale
puts "\n[!] Usage: rake import:country_select de\n\n"
puts "\n[!] Usage: rake import:country_select LOCALE=de\n\n"
exit 0
end

Expand Down Expand Up @@ -81,8 +81,10 @@ TAIL

# ----- Write the parsed values into file ---------------------------------
puts "\n... writing the output"
filename = Rails.root.join('config', 'locales', "#{locale}.rb")
filename += '.NEW' if File.exists?(filename) # Append 'NEW' if file exists
filename = Rails.root.join('config', 'locales', "country_select_#{locale.downcase}.rb")
if filename.exist?
filename = Pathname.new("#{filename.to_s}.NEW")
end
File.open(filename, 'w+') { |f| f << output }
puts "\n---\nWritten values for the '#{locale}' into file: #{filename}\n"
# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 868bc46

Please sign in to comment.