Use another I18n key in an I18n interpolation
This is actually a pretty common question, but the short answer is no, this isn’t possible unfortunately 🙁
This is actually a pretty common question, but the short answer is no, this isn’t possible unfortunately 🙁
You got to call a private method on the backend. This is how you get access: translations = I18n.backend.send(:translations) translations[:en][:test_string] # => “testing this”
I set in config/application.rb usually config.i18n.fallbacks = [:de, :fr, :en] So you can declare the order of the fallback. But keep attention in some environments/*.rb the configuration is overwritten.
Those labels can be customized using I18n under the +helpers.submit+ key and using %{model} for translation interpolation: en: helpers: submit: create: “Create a %{model}” update: “Confirm changes to %{model}” It also searches for a key specific to the given object: en: helpers: submit: post: create: “Add %{model}” Source @ actionview/lib/action_view/helpers/form_helper.rb
Call: I18n.t instead of simple t. t is a helper method only available in the views, delegating the whole logic to I18n module. UPDATE: As mentioned in the comments, view helper is not only delegating to the I18n module, it makes sure that you can use a default scopes as well.
Based on what you’ve described, this should work: I18n.t(“some_translation.key”, :default => “fallback text”) See the documentation for details.
Use the l (alias for localize) method instead of raw strftime, like this: l(date, format: ‘%B %d, in the year %Y’) See here for more information. You can also define ‘named’ formats, a couple of them (short, long) are already predefined.
Try this: en.yml : en: misc: kids: zero: no kids one: 1 kid other: %{count} kids In a view: You have <%= t(‘misc.kids’, :count => 4) %> Updated answer for languages with multiple pluralization (tested with Rails 3.0.7): File config/initializers/pluralization.rb: require “i18n/backend/pluralization” I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization) File config/locales/plurals.rb: {:ru => { :i18n => { :plural => { … Read more
Important: Make sure your app is not using I18n 0.6.8, it has a bug that prevents the configuration to be set correctly. Short answer In order to silence the warning edit the application.rb file and include the following line inside the Rails::Application body config.i18n.enforce_available_locales = true The possible values are: false: if you want to … Read more