Skip to content
joshmh edited this page Sep 13, 2010 · 13 revisions

Implementation

YAML loading is already done in the I18n module in Sven’s fork. Globalize2 will just have to manage the load paths, and send a list of the full file paths to I18n. We should make sure that the I18n module/SimpleBackend handle the YAML files as specified below.

The DB-backend will be deferred until after we’re finished with the model translation stuff. Probably 2nd release.

Structure

Directory Structure

Globalize2 will search for YAML translation files in all defined load paths. Some paths will be setup by default, such as the rails core translations, plugin translations, and application translations.

Rails app translation files go in e.g., app/locales/de-DE/articles.yml. This is just a convention, Globalize2 will slurp in all files under app/locales. An exception will be raised on duplicate definitions of keys within a load path (e.g., files within app/locales).

File Structure

  • Files will start off with the locale specification.
  • Then keys will be grouped by scope.
    • Q: Will we allow collapsing of scopes? E.g._, @error-messages.tooshort: Field is too short@.
    • A: No, not for now. Keep it simple.
  • Plural forms will be specified by hash, not by array. We should probably use CLDR’s conventions on plural form naming.
    • We should ask people from different countries how these plural form names work out for them.

en-US:
  error-messages:
    invalid:
      single: This field is invalid.
      many:   These fields are invalid.

Backends

We will supply two backends for the i18n API: YAML and DB-based. There may be a lot of common functionality, so the backends might inherit from a base class, or delegate functionality out to other components.

YAML will be the official format for view translations in Rails.

ViewTranslation Object

Translated strings will be returned as ViewTranslation objects, which inherit from String.


class ViewTranslation < String
  attr :locale
  attr :requested_locale
  attr :key
  attr :options
  attr :grammatical_number
  def fallback?
  end
end

requested_locale is the locale used when the string was translated: either the current locale or an explicitly requested locale. locale is the locale that the translation actually belongs to. This may be different than the requested locale, if fallbacks were defined and there was no translation in the requested locale.

key is the array that’s used to define the namespaced translation key. E.g., @[ :activerecord, :errormessages, :invalid ]@.

options is the original options hash that was passed to I18n.translate.

grammatical_number is the grammatical number computed based on the provided count and the current locale algorithm. Examples are :one, :few, :many.

fallback? returns a boolean value: true if a fallback locale was used, false otherwise.