Sha256: 5a6071fdff9e87fcc7ef60a9ae241844a0be0881f442068ada8c73ecb6579e81

Contents?: true

Size: 951 Bytes

Versions: 2

Compression:

Stored size: 951 Bytes

Contents

require "i18n_screwdriver/version"
require "i18n_screwdriver/translation"
require "i18n_screwdriver/rails"

module I18nScrewdriver
  def self.filename(locale)
    "config/locales/application.#{locale}.yml"
  end

  def self.for_key(string)
    string.gsub(/\./, "").strip
  end

  def self.load_translations(locale)
    filename = self.filename(locale)
    raise "File #{filename} not found!" unless File.exists?(filename)
    YAML.load_file(filename)[locale]
  end

  def self.write_translations(locale, translations)
    File.open(filename(locale), "w") do |file|
      file.puts "# use rake task i18n:update to generate this file"
      file.puts
      file.puts({locale => translations}.to_yaml)
      file.puts
    end
  end

  def self.grab_texts_to_be_translated(string)
    [].tap do |texts|
      texts.concat(string.scan(/_\("([^"]+)"\)/).map{ |v| v[0] })
      texts.concat(string.scan(/_\('([^']+)'\)/).map{ |v| v[0] })
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i18n_screwdriver-1.2.0 lib/i18n_screwdriver.rb
i18n_screwdriver-1.1.0 lib/i18n_screwdriver.rb