i18n
https://github.com/svenfuchs/i18n
Ruby
Internationalization (i18n) library for Ruby
I18n::Base#transliterate
Transliterates UTF-8 characters to ASCII. By default this method will
transliterate only Latin strings to an ASCII approximation:
I18n.transliterate("Ærøskøbing")
# => "AEroskobing"
I18n.transliterate("日本語")
# => "???"
It's also possible to add support for per-locale transliterations. I18n
expects transliteration rules to be stored at
<tt>i18n.transliterate.rule</tt>.
Transliteration rules can either be a Hash or a Proc. Procs must accept a
single string argument. Hash rules inherit the default transliteration
rules, while Procs do not.
*Examples*
Setting a Hash in <locale>.yml:
i18n:
transliterate:
rule:
ü: "ue"
ö: "oe"
Setting a Hash using Ruby:
store_translations(:de, :i18n => {
:transliterate => {
:rule => {
"ü" => "ue",
"ö" => "oe"
}
}
)
Setting a Proc:
translit = lambda {|string| MyTransliterator.transliterate(string) }
store_translations(:xx, :i18n => {:transliterate => {:rule => translit})
Transliterating strings:
I18n.locale = :en
I18n.transliterate("Jürgen") # => "Jurgen"
I18n.locale = :de
I18n.transliterate("Jürgen") # => "Juergen"
I18n.transliterate("Jürgen", :locale => :en) # => "Jurgen"
I18n.transliterate("Jürgen", :locale => :de) # => "Juergen"Edit
git clone [email protected]:svenfuchs/i18n.git
cd i18n
open lib/i18n.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-I18n--Base-transliterate-for-pr
# Commit to gitgit add lib/i18n.rbgit commit -m "better docs for I18n::Base#transliterate"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-I18n--Base-transliterate-for-pr
hub pull-request
# Celebrate!