1. The Ruby on Rails I18n Core API PRESENTED BY -Neeraj Kumar
2.
3.
4.
5.
6.
7.
8.
9. before_filter :set_locale def set_locale # if params[:locale] is nil then I18n.default_locale will be used I18n .locale = params[ :locale ] end - URL : http://example.com/books?locale=pt - will load Portuguese localization.
10.
11. # app/controllers/application_controller.rb def default_url_options (options = {}) logger.debug “default_url_options is passed options: #{options.inspect}” { :locale => I18n .locale} end - Every helper method dependent on url_for automatically include the locale in the query string .
16. def extract_locale_from_tld parsed_locale = request.host.split( '.' ).last I18n .available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil end - parsed_locale = request.host.split('.').first to set the locale from subdomain.
19. def extract_locale_from_accept_language_header request.env[ 'HTTP_ACCEPT_LANGUAGE' ].scan( /^[a-z]{2}/ ).first end - Using GeoIP (or similar) Database – GeoIP Lite Country - User Profile
20.
21.
22.
23.
24.
25. Anatomy of Gem i18n i18n backend core_ext helpers locales backend exceptions gettext helpers locale i18n version locale gettext fallbacks tag
47. raise ( I18n::MissingTranslationData .new(locale, key, options)) if entry.nil? e ntry = pluralize(locale, entry, count) if count entry = interpolate(locale, entry, values) if values end entry end base.rb
48.
49.
50. when '%B' then I18n.t(: "date.month_names" , :locale => locale, :format => format)[object.mon] when '%p' then I18n.t(: "time.#{object.hour < 12 ? :am : :pm}" , :locale => locale, :format => format) if object.respond_to? :hour end base.rb
51.
52.
53. - customization – e.g. the default exception handling does not allow to catch missing translation during automated test easily .
54.
55. module I18n def just_raise_that_exception (*args) raise args.first end end I18n .exception_handler = :just_raise_that_exception