Localizing a ruby on rails application
Upcoming SlideShare
Loading in...5
×
 

Localizing a ruby on rails application

on

  • 724 views

For more information: http://extremia.fi/

For more information: http://extremia.fi/

Statistics

Views

Total Views
724
Views on SlideShare
724
Embed Views
0

Actions

Likes
1
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Localizing a ruby on rails application Localizing a ruby on rails application Presentation Transcript

    • Localizing a Ruby on Rails Application http://extremia.fi/
    • Background• In order to reach a wider audience and to improve the usability of your Rails web application, you can offer your site in more than one language• The easiest way to do this is to utilize the built-in internationalization library I18n• To convert an existing Rails application to utilize the library you need to go through a few steps http://extremia.fi/
    • Steps1. Replace hardcoded locale-specific text in your views with calls to I18n.translate (aka I18n.t) with a key as the parameter. Note that special keys exist for some things like ActiveRecord- models, e.g. “Sign in” on your login-page with t(‘login.sign_in’).2. Add localization for Date and Time objects in your views, using I18n.localize (aka I18n.l), e.g. l Time.now. http://extremia.fi/
    • Steps (continues)4. Create translation files for each locale in config/locales directory and place your translation keys inside with the corresponding translations for the locale. Locale-specific formats also go in the same file.5. Set I18n.locale before rendering your views, so that I18n knows which locale to use when searching for translations. A good place for doing this is in a before_filter method in your ApplicationController. http://extremia.fi/
    • Interpolation and Pluralization• Additional variables may be passed when calling I18n.translate for interpolation• You don’t need to break up sentences to multiple keys when something needs to be put in the middle• I18n.translate supports pluralization using an additional :count interpolation variable http://extremia.fi/
    • Interpolation and Pluralization• The parameter is used to pick a plural form from the translations according to the pluralization rules defined by CLDR (Unicode Common Locale Data Repository) for the current locale• The requested key in the locale therefore must be a hash containing the possible plural form keys (like in the example below) http://extremia.fi/
    • Backends• I18n uses a backend object stored in I18n.backend whenever you call I18n.translate, which defaults to I18n::Backend::Simple• The simple backend keeps a hash populated with all locales from YAML files in memory• Other backends may be more suitable in large applications, especially when it’s desirable to let users contribute by translating text to their favorite language http://extremia.fi/
    • Backends• Storing locales in a database can create a problem with performance, but that may be averted by chaining a cache backend (e.g. I18n::Backend::Memoize) in front of your database backend using I18n::Backend::Chain• The database lookups will be stored in the cache, and database will be only used as a fallback if a key can’t be found in the cache