Teaching Rails more languages is now as simple as:
- downloading example locales,
- putting them in your
- adding a method to
ApplicationControllerthat detects the user’s language:
class ApplicationController < ActionController::Base before_filter :set_locale def set_locale I18n.locale = request.env.fetch('HTTP_ACCEPT_LANGUAGE', '')[/(?:,|^)(de|en)\b/, 1] end end
You have to adjust the regexp to allow automatic recognition of more languages; I haven’t found out yet how to get a list of all available locales without using I18n.load_path, but maybe the community helps me out.
It’s cool that changes to the locale files are applied instantly in development mode! A great improvement :D