简体   繁体   中英

RAILS I18n: How to use @ in translation key?

Here is in our yml file:

Or make up unique one like login@a.com : 'test'

But here is the error on view page for I18n.t("Or make up unique one like login@a.com") :

translation missing: zh-CN.Or make up unique one like login@a.com

What causes the missing translation of t()?

UPDATE:

Just verified that the problem was caused by @ sign. Now the question becomes how to use @ in translation key.

I highly recommend the Rails i18n guide for beginners.

It will help you understand how to structure your files, how to setup routes to support a locale param, how to set the locale, and other useful tips.


The t helper is not intended to take a string of text to translate. It takes a yaml key and outputs the translated text from a locale file.

You want to structure your yaml file as such:

config/locales/en.yml

en:
  some_key: hello world

config/locales/cn.yml

cn:
  some_key: hello in Chinese

Then using it in your views

<%= t :some_key %>

Based on the I18n.locale setting, the t helper will look up :some_key in the corresponding locale file and output the translated text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM