Sha256: 32737dc303626035230fdc9b4dc4e8e3607c5ae8baee07d282b549b03b7a4240
Contents?: true
Size: 1.19 KB
Versions: 10
Compression:
Stored size: 1.19 KB
Contents
module Alchemy class I18n ## Thanks Typus for this I18n hack! # # Instead of having to translate strings and defining a default value: # # AlchemyAlchemy::I18n.t("Hello World!", :default => 'Hello World!') # # We define this method to define the value only once: # # AlchemyAlchemy::I18n.t("Hello World!") # # Note that interpolation still works: # # AlchemyAlchemy::I18n.t("Hello %{world}!", :world => @world) # # Notes: # ----- # # Already scoped to alchemy namespace! # def self.t(msg, *args) options = args.extract_options! options[:default] = options[:default] ? options[:default] : msg scope = ['alchemy'] case options[:scope].class.name when "Array" scope += options[:scope] when "String" scope << options[:scope] when "Symbol" scope << options[:scope] unless options[:scope] == :alchemy end ::I18n.t(msg, options.merge(:scope => scope)) end def self.available_locales translation_files.collect { |f| f.match(/.{2}\.yml$/).to_s.gsub(/\.yml/, '') }.uniq end def self.translation_files Rails.application.config.i18n.load_path.select { |p| p.split('/').last.match(/alchemy/) } end end end
Version data entries
10 entries across 10 versions & 1 rubygems