localized_application.rb

Path: lib/features/localized_application.rb
Last Update: Wed Oct 31 00:50:25 +0100 2007

Localized application

This feature allows you to use the language file to localize your application. You can add your own translation strings to the app section of the language file and read them with the l global method. You can use this method in your controllers, views, mail templates, simply everywhere. To make the access more convenient you can use the lc method in controllers, views, partials, models and observers.

  app:
    title: Simple Localization Rails plugin
    subtitle: The plugin should make it much easier to localize Ruby on Rails
    headings:
      wellcome: Wellcome to the RDoc Documentation of this plugin

  l(:title) # => "Simple Localization Rails plugin"
  l(:headings, :wellcome) # => "Wellcome to the RDoc Documentation of this plugin"

The l method is just like the ArkanisDevelopment::SimpleLocalization::Language#entry method but is limited to the app section of the language file.

To save some work you can narrow down the scope of the l method even further by using the l_scope method:

  app:
    layout:
      nav:
        main:
          home: Homepage
          contact: Contact
          login: Login

  l :layout, :nav, :main, :home     # => "Homepage"
  l :layout, :nav, :main, :contact  # => "Contact"

Same as

  l_scope :layout, :nav, :main do
    l :home     # => "Homepage"
    l :contact  # => "Contact"
  end

Please also take a look at the ContextSensetiveHelpers::lc method. It can make life much more easier.

Used sections of the language file

This feature uses the app section of the language file. This section is reserved for localizing your application and you can create entries in this section just as you need it.

  app:
    index:
      title: Wellcome to XYZ
      subtitle: Have a nice day...
    projects:
      title: My Projects
      subtitle: This is a list of projects I'm currently working on

  l(:index, :title) # => "Wellcome to XYZ"
  l(:projects, :subtitle) # => "This is a list of projects I'm currently working on"

[Validate]