Transliteration Rules
Transliteration is the conversion of text from one script to another. In the context of web applications, this is most commonly used to convert characters from non-Latin alphabets (like Cyrillic, Greek, or Arabic) into an ASCII-friendly equivalent. This is especially useful for generating clean, readable URLs (slugs) or for simplifying search queries.
rails-i18n provides transliteration rules for a variety of languages.
How to Use
The Rails framework uses the i18n gem's transliteration capabilities, which are automatically enhanced by rails-i18n. You can use it directly like this:
# With Ukrainian rules loaded from rails-i18n
I18n.transliterate("Київ")
# => "Kyiv"
# With German rules loaded
I18n.transliterate("Übermut")
# => "Uebermut"
Many libraries, such as friendly_id, use this feature under the hood to generate slugs from titles.
Supported Languages
This gem provides transliteration rules for the following locales, found in the rails/transliteration/ directory:
az(Azerbaijani)bg(Bulgarian)ca(Catalan)da(Danish)de(German)el(Greek)es(Spanish)fa(Persian)fr(French)hu(Hungarian)ka(Georgian)oc(Occitan)pl(Polish)pt(Portuguese)ro(Romanian)ru(Russian) - Uses a custom Ruby rule for complex cases.uk(Ukrainian) - Uses a custom Ruby rule for complex cases.vi(Vietnamese)
These rules are automatically loaded when you include the gem in your project, unless you have disabled the :transliteration module in your configuration.