Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 35 lines (30 sloc) 1.138 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
locales = (ENV['LOCALES'] || ask("Which locales do you want to use (separate with commas if more)?")).split(/[,\s]+/)

locales.each do |locale|
  locale += '.yml' unless locale =~ /\.(yml|rb)$/
  file "config/locales/#{locale}",
    open("http://github.com/svenfuchs/rails-i18n/raw/master/rails/locale/#{locale}").read
end

def uri_exists?(uri)
  uri = URI.parse(uri)
  Net::HTTP.start(uri.host, uri.port) do |http|
    http.head(uri.request_uri).is_a?(Net::HTTPSuccess)
  end
end

if @base_path
  log '', 'Trying to download module specific localizations...'
  @used_legos.each do |lego|
    locales.each do |locale|
      fn = "#{locale.split(".").first}.#{lego}.yml"
      path = "#{@base_path}/locales/#{fn}"
      if @base_path !~ /^https?:\/\// or uri_exists?(path)
        content = open(path).read rescue nil
        file "config/locales/#{fn}", content if content
      end
    end
  end
end

gsub_file "config/environment.rb",
  /(#\s*)?config.i18n.default_locale.*$/,
  "config.i18n.default_locale = '#{locales.first.gsub(/\.(yml|rb)$/, '')}'"

git :add => "."
git :commit => "-a -m 'Added #{locales.join(",")} localizations'"
Something went wrong with that request. Please try again.