Module: Alchemy::I18n
- Defined in:
- lib/alchemy/i18n.rb
Class Method Summary collapse
- .available_locales ⇒ Object
- .available_locales=(locales) ⇒ Object
- .t(msg, *args) ⇒ Object
-
.translate(msg, *args) ⇒ Object
Alchemy translation methods.
- .translation_files ⇒ Object
Class Method Details
.available_locales ⇒ Object
58 59 60 61 62 63 |
# File 'lib/alchemy/i18n.rb', line 58 def available_locales @@available_locales ||= nil @@available_locales || translation_files.collect do |f| f.match(/.{2}\.yml$/).to_s.gsub(/\.yml/, '').to_sym end end |
.available_locales=(locales) ⇒ Object
65 66 67 68 |
# File 'lib/alchemy/i18n.rb', line 65 def available_locales=(locales) @@available_locales = Array(locales).map(&:to_sym) @@available_locales = nil if @@available_locales.empty? end |
.t(msg, *args) ⇒ Object
20 21 22 23 |
# File 'lib/alchemy/i18n.rb', line 20 def t(msg, *args) ActiveSupport::Deprecation.warn('`Alchemy::I18n.t` is deprecated! Use `Alchemy.t` instead.', caller.unshift) Alchemy::I18n.translate(msg, *args) end |
.translate(msg, *args) ⇒ Object
Alchemy translation methods
Instead of having to translate strings and defining a default value:
Alchemy::I18n.translate("Hello World!", default: 'Hello World!')
We define this method to define the value only once:
Alchemy::I18n.translate("Hello World!")
Note that interpolation still works:
Alchemy::I18n.translate("Hello %{world}!", world: @world)
Notes
All translations are scoped into the alchemy
namespace. Even scopes are scoped into the alchemy
namespace.
So a call for Alchemy::translate(‘hello’, scope: ‘world’) has to be translated like this:
de:
alchemy:
world:
hello: Hallo
51 52 53 54 55 56 |
# File 'lib/alchemy/i18n.rb', line 51 def translate(msg, *args) = args. humanize_default_string!(msg, ) scope = alchemy_scoped_scope() ::I18n.t(msg, .merge(scope: scope)) end |
.translation_files ⇒ Object
70 71 72 |
# File 'lib/alchemy/i18n.rb', line 70 def translation_files Dir.glob(File.join(File.dirname(__FILE__), '../../config/locales/alchemy.*.yml')) end |