3

So we're using I18n to localize our website to traditional Chinese

I have a zh-TW.yml file under directory config/locales

I'm trying to see that the translation works in Rails Console.

So I tried:

1.9.3-p0 :001 > I18n.default_locale
 => :zh
1.9.3-p0 :008 > I18n.t 'users.account_header'
 => "zh, users.account_header" 
1.9.3-p0 :009 > I18n.t "x_days", :count => 10
 => "zh, x_days"

Why does it not return the proper Chinese translation? so we know it works and gets the right translation.

I also tried some garbage string, eg

1.9.3-p0 :011 > I18n.t "dfkjafkjadf", :count => 10
 => "zh, dfkjafkjadf" 

It didn't even complain that the translation is missing!

Have I missed something?

Thanks!

Zack Xu
  • 11,505
  • 9
  • 70
  • 78

2 Answers2

3

This might sound silly, but could it simply be that your default locale is zh but your translations are stored under zh-TW?

tigrish
  • 2,488
  • 18
  • 21
  • 1
    Actually this is the problem. After I renamed the yml file to zh.yml, the I18n.translate and I18n.localize methods work as expected by getting the translations from the zh.yml file. I see I18n doc says: "The i18n library takes a pragmatic approach to locale keys (after some discussion), including only the locale (“language”) part, like :en, :pl, not the region part, like :en-US or :en-GB..." So we'll just have 1 file zh.yml until we need to differentiate the different Chinese languages. Thanks – Zack Xu Jun 06 '12 at 15:29
3

I use the same chinese translation in my application.

My Chinese locale zh-CN.yml

zh-CN:
  go: '进行'
  Log out: '退出'

Rails Console:

Loading development environment (Rails 3.2.13)
1.9.3p392 :001 > I18n.default_locale
 => :en 
1.9.3p392 :002 > I18n.locale = 'zh-CN'
 => "zh-CN" 
1.9.3p392 :003 > helper.t('Go')
 => "进行" 
1.9.3p392 :004 > helper.t('Log out')
 => "退出" 
AnkitG
  • 6,438
  • 7
  • 44
  • 72