Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails i18n: How to know what is the current language?

I am aware of how i18n/l10n is usually done in Rails3, and I chose to have a single ERB file that calls t(...) for localization. But for a particular part I need something special:

I need to display a string whose localization is coming from an external database.

So how can I know the current language, to call the external database with an en or ja parameter?

Something like $LANG in UNIX. Preferably accessible from view or controller.

like image 644
Nicolas Raoul Avatar asked Jul 20 '11 09:07

Nicolas Raoul


People also ask

What is i18n in Rails?

The Ruby I18n (shorthand for internationalization) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for translating your application to a single custom language other than English or for providing multi-language support in your application.

What is i18n t?

Internationalization (i18n) is the process of preparing software so that it can support local languages and cultural settings. An internationalized product supports the requirements of local markets around the world, functioning more appropriately based on local norms and better meeting in-country user expectations.

Is en a valid locale?

I18n::InvalidLocale: :en is not a valid locale. Bookmark this question.

What is i18n and l10n?

Internationalization (i18n) is the process of developing products in such a way that they can be localized for languages and cultures easily. Localization (l10n), is the process of adapting applications and text to enable their usability in a particular cultural or linguistic market.


1 Answers

I18n.locale # Get and set the current locale 
like image 75
Vadim Golub Avatar answered Sep 18 '22 20:09

Vadim Golub