This approach has almost the same set of advantages as setting the locale from the domain name: namely that it's RESTful and in accord with the rest of the World Wide Web. It does impact the readability of URLs, though, when the locale "hangs" at the end of every URL in your application.
It does require a little bit more work to implement, though. Moreover, from the architectural standpoint, locale is usually hierarchically above the other parts of the application domain: and URLs should reflect this.
You probably want URLs to look like this: without a locale.
A localized application will likely need to provide support for multiple locales.
To accomplish this, the locale should be set at the beginning of each request so that all strings are translated using the desired locale during the lifetime of that request.
The locale can be set in a loads a German localization.
The locale can be set using one of many different approaches.
One option you have is to set the locale from the domain name where your application runs. This solution has aforementioned advantages, however, you may not be able or may not want to provide different localizations ("language versions") on different domains.I18n.default_locale end # Get locale from top-level domain or return nil if such locale is not available # You have to put something like: # 127.0.0.1 # 127.0.0.1 # 127.0.0.1 # in your /etc/hosts file to try this out locally def extract_locale_from_tld parsed_locale = split('.')I18n.available_locales.map(&:to_s).include? parsed_locale : nil end # Get locale code from request subdomain (like # You have to put something like: # 127.0.0.1 gr.application.local # in your /etc/hosts file to try this out locally def extract_locale_from_subdomain parsed_locale = request.subdomains.first I18n.available_locales.map(&:to_s).include? The most obvious solution would be to include locale code in the URL params (or request path).
The most usual way of setting (and passing) the locale would be to include it in URL params, as we did in the in this case.
) 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.
The process of "internationalization" usually means to abstract all strings and other locale specific bits (such as date or currency formats) out of your application.