Here is in our yml file:
Or make up unique one like [email protected] : 'test'
But here is the error on view page for I18n.t("Or make up unique one like [email protected]")
:
translation missing: zh-CN.Or make up unique one like [email protected]
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.