Sha256: 7d0513a891224f7ac175be88e974c11a4b4c9494ce20108dea377fde5fafde1f

Contents?: true

Size: 1.37 KB

Versions: 14

Compression:

Stored size: 1.37 KB

Contents

namespace :i18n do
  desc 'Find all translations in views, helpers and controllers'
  task :update do
    require "i18n_screwdriver"
    require "yaml"

    translations = I18nScrewdriver.gather_translations
    puts "Found #{translations.keys.size} unique translations"
    default_locale = I18n.default_locale.to_s
    I18nScrewdriver.update_translations_file(default_locale, translations)
  end

  desc 'Translate all not yet translated texts for a given locale'
  task :translate do
    require "i18n_screwdriver"
    require "yaml"

    raise "ERROR: usage: TRANSLATE=de rake i18n:translate" unless ENV['TRANSLATE']
    locale = ENV['TRANSLATE']
    default_locale = I18n.default_locale.to_s

    texts = I18nScrewdriver.load_translations(default_locale)
    translations = {}
    begin
      translations = I18nScrewdriver.load_translations(locale)
    rescue I18nScrewdriver::Error => e
      puts "WARNING: #{e.message}"
    end

    puts "Translating #{translations.keys.size} entries from <#{default_locale}> to <#{locale}> (enter :q to save and quit, ctrl-c to abort):"
    texts.keys.sort.each do |key|
      next unless ["", nil].include?(translations[key])
      puts "> #{texts[key]}"
      input = STDIN.gets.chomp
      break if input == ":q"
      translations[key] = input
    end

    puts "Saving translations..."
    I18nScrewdriver.write_translations(locale, translations)
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
i18n_screwdriver-10.2.0 lib/tasks/i18n.rake
i18n_screwdriver-10.1.0 lib/tasks/i18n.rake
i18n_screwdriver-10.0.1 lib/tasks/i18n.rake
i18n_screwdriver-10.0.0 lib/tasks/i18n.rake
i18n_screwdriver-9.7 lib/tasks/i18n.rake
i18n_screwdriver-9.6 lib/tasks/i18n.rake
i18n_screwdriver-9.5 lib/tasks/i18n.rake
i18n_screwdriver-9.4 lib/tasks/i18n.rake
i18n_screwdriver-9.3 lib/tasks/i18n.rake
i18n_screwdriver-9.2 lib/tasks/i18n.rake
i18n_screwdriver-9.1 lib/tasks/i18n.rake
i18n_screwdriver-9.0 lib/tasks/i18n.rake
i18n_screwdriver-8.1 lib/tasks/i18n.rake
i18n_screwdriver-8.0 lib/tasks/i18n.rake