YAML resources files for Ruby often begin with a language code. For example:
en:
string1: 'Hello'
string2: 'Goodbye'
When these strings are translated by Smartling, they will be returned with the appropriate language code. For example, the French file will be:
fr:
string1: 'Bonjour'
string2: 'Au Revoir'
If you want to return the full Smartling Locale Code in your translated files, you can use the yaml_locale_substitution
directive to get the full code as shown below:
en-US:
string1: 'Hello'
string2: 'Goodbye'
translated into French(France), will return:
fr-FR:
string1: 'Hello'
string2: 'Goodbye'
If you wish, locale substitution can be turned off completely using a file directive. This may be desirable if the first key in your YAML file happens to match a language code unintentionally.
Plurals
Smartling’s CAT tool supports plurals according to the CLDR pluralization rules, which define which plural forms are used in each locale.
Out of the box, Ruby on Rails applications support only the standard English plural forms of One and Other. Translating a YAML file into languages with different plural rules, such as Japanese (‘Other’ only) or Czech (One/Few/Many/Other) may cause errors in your Rails application.
To properly localize into multiple languages supporting different plural forms, you must setup your application to use the I18n pluralization backend and define pluralization rules in your application for each locale.
Require Pluralization Backend
1. Create config/initializers/pluralization.rb in your application:
Ruby
I18n::Backend::Simple.send:include, I18n::Backend::Pluralization)
2. Create a rule in plurals.rb for each locale in your application. For example, this rule creates four plural forms for Russian: One, Few, Many and Other. plurals.rb
Ruby
{: ru =>
{: i18n =>
{: plural =>
{: keys => [: one, : few, : many, : other], : rule => lambda
{ | n | n % 10 == 1 && n % 100 != 11 ? : one: [2, 3, 4].include ? (n % 10) && ![12, 13, 14].include ? (n % 100) ? : few : n % 10 == 0 || [5, 6, 7, 8, 9].include ? (n % 10) || [11, 12, 13, 14].include ? (n % 100) ? : many : : other
}
}
}
}
}
Pluralization rules for most locales are publicly available on GitHub.
You may need to edit the locale labels to match the labels used in your application.