Translate YAML files
WebTranslateIt supports YAML files, including support for pluralization. YAML files can come in 3 flavors.
🔗The classic ruby .yml file
As used by the i18n gem included in Ruby on Rails.
🔗The more complex .yml file
As used by the r18n gem.
WebTranslateIt can use a few filters: proc, pl, String, R18n::Untranslated, escape, html, markdown, textile and gender. Please contact Support if you need another filter.
🔗The flat yaml file
As used by some PHP i18n libraries.
You will notice that plural keys such as “one” aren’t editable in the Chinese interface. This is no mistake, this is due to the fact that the “one” rule doesn’t exist in the Chinese language, so it doesn’t make sense to have one.
For an in-depth explanation about plural rules, visit Understanding Plural Strings
In English, we have our well-known plural rules “one” and “other”:
The word “dog” changes depending on the quantifier.
In Chinese words don’t change depending on the quantifier like most languages do. They would say something like:
The plural rules are defined by CLDR, which has documented all the known rules.
Now here’s the thing: The Ruby on Rails framework only knows how to handle English plural rules (one/other) which works for most occidental languages. It works for German for instance, but works badly for French and it’s really not adapted for Chinese, Arabic, Russian or Polish. You need to use the pluralization back-end.
🔗Using the pluralizer back-end in your Rails application:
config/initializers/pluralization.rbfile in your app, and copy/paste the following code to add the pluralization backend:
Download this plurals.rb file, which is part of the i18n gem and place the file under the
If necessary, rename the locales key names to suit your application’s needs. For instance, if you use the
zh-CNlocale code instead of
zh, rename the
zh-CNin the plurals.rb file.
Restart your application. Rails will be able to create plural phrases using the correct plural rules for Chinese and other languages.
🔗“no”, “yes” imported as false in WebTranslateIt?
YAML strings are typed, which means some keys are cast into a specific type. For instance, the number
1 is cast into an Integer and the word
false is cast into a boolean.
Mind, though, as there are also shorthands for booleans, like
off, which are cast into booleans. The words
off are equal to
false You can read more about it in the YAML specification regarding booleans.
You can easily reproduce this behaviour. Given this YAML file:
Let’s try to load this YAML file using irb:
no key is interpreted as
false by Ruby. In order for you to use the
no key for Norway in your app, you’ll have to rename your key in your file to
"no", so it can be cast as a string instead of as a boolean.
Once this is done, upload your language file to WebTranslateIt again, and the
no key should appear, instead of
🔗Syck, Psych and ya2yaml
Syck is an old YAML parser and dumper used by old versions of ruby (< 1.9). Newer version of ruby are compiled with Psych if the library
libyaml is installed on your system. Psych is also rails’s preferred YAMLer when available.
It turns out, some files dumped using Syck cannot be parsed using Psych.
The good news is that WebTranslateIt recognizes both formats: YAML files dumped with Psych and those dumped with Syck. Internally, the system will first try to load a YAML file using Psych. If the parsing fails, it will try to load the YAML file using Syck.
However, to retain compatiblity with both parsers, the YAML files generated by WebTranslateIt are dumped using a third library called ya2yaml, which is compatible with both Psych and Syck parsers. This is the reason why you will notice a few syntactic changes when you download your YAML files.
🔗Type Casting, nil and blank values
WebTranslateIt supports Type Casting. That is, if you upload a segment as an String, Array, Integer, Float or Symbol, it will be exported as such.
WebTranslateIt can’t determine the type of blank or untranslated values, though. A segment left untranslated can be considered as a nil entry, using the
~ symbol or as a blank entry using
By default, untranslated and unproofread translations are exported as nil (
~), so Rails’s fallback mechanism know that there is no translation intentionally left blank here.
If you want the translation to be blank (and not nil), leave the translation box blank and flag the translation as proofread. WTI will know that this segment is meant to be left blank (
If you want the translation to be nil, place
~in the translation box. This segment will be exported as a nil entry.