user938363
user938363

Reputation: 10378

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.

Upvotes: 0

Views: 116

Answers (1)

maček
maček

Reputation: 77826

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.

Upvotes: 2

Related Questions