lib/i18n_screwdriver.rb in i18n_screwdriver-7.3 vs lib/i18n_screwdriver.rb in i18n_screwdriver-7.4

- old
+ new

@@ -2,10 +2,14 @@ require "i18n_screwdriver/translation" require "i18n_screwdriver/translation_helper" require "i18n_screwdriver/rails" module I18nScrewdriver + DUMMY_TEXT = "TRANSLATION_MISSING" + + Error = Class.new(StandardError) + def self.filename_for_locale(locale) File.join("config", "locales", "application.#{locale}.yml") end def self.generate_key(string) @@ -17,11 +21,11 @@ File.exists?(filename_for_locale(locale)) end def self.load_translations(locale) path = filename_for_locale(locale) - raise "File #{path} not found!" unless File.exists?(path) + raise Error, "File #{path} not found!" unless File.exists?(path) sanitize_hash(YAML.load_file(path)[locale]) end def self.write_translations(locale, translations) File.open(filename_for_locale(locale), "w") do |file| @@ -94,18 +98,18 @@ translations.merge(Hash[symbols.uniq.map{ |symbol| [generate_key(symbol), ""] }]) end def self.default_locale @default_locale ||= begin - raise "Please set I18.default_locale" unless I18n.default_locale.present? + raise Error, "Please set I18.default_locale" unless I18n.default_locale.present? I18n.default_locale.to_s end end def self.available_locales @available_locales ||= begin - raise "Please set I18.available_locales" unless I18n.available_locales.count > 0 + raise Error, "Please set I18.available_locales" unless I18n.available_locales.count > 0 I18n.available_locales.map(&:to_s) end end def self.update_translations_file(locale, translations) @@ -126,10 +130,10 @@ end end def self.translate(string, options = {}) translation = I18n.translate(generate_key(string), options) - translation.present? ? translation : "TRANSLATION_MISSING" + translation.present? ? translation : DUMMY_TEXT end def self.extract_text(string) namespace, text = string.split("|", 2) text ? text : namespace