lib/i18n_screwdriver.rb in i18n_screwdriver-0.6.0 vs lib/i18n_screwdriver.rb in i18n_screwdriver-1.0.0

- old
+ new

@@ -1,33 +1,35 @@ -# encoding: utf-8 +require "i18n_screwdriver/version" +require "i18n_screwdriver/rails" -require 'action_view' -require 'action_controller' -require 'i18n/screwdriver/scanner' +module I18nScrewdriver + def self.filename(locale) + "config/locales/application.#{locale}.yml" + end -module I18n - module Screwdriver - def self.included(klass) - klass.send :include, InstanceMethods + 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 - - module InstanceMethods - def _(translation) - # the . is a special character in rails i18n - we have to strip it - translation_without_dot = translation.gsub(/\./, '').strip - translated = I18n.translate(translation_without_dot) - - if defined?(Rails) && Rails.env.development? && translated.start_with?('translation missing') - # TODO: add translation with key to all translation files - # so that rake task is obsolete - instant feedback! - end - - translated - 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 -ActionView::Base.send :include, I18n::Screwdriver -ActionController::Base.send :include, I18n::Screwdriver -ActionController::IntegrationTest.send :include, I18n::Screwdriver -ActionController::TestCase.send :include, I18n::Screwdriver \ No newline at end of file