对于你的问题,有一个简短的答案和一个长答案。这是简短版本。如果你想要长版本,请告诉我。
使用国际化需要实践和关注运行时上下文。但是可以仅设置简单表单国际化而不涉及整个国际化架构。
您列出的帮助程序不是简单表单的一部分,它们是标准应用程序yaml的一部分。除了select:
是简单表单的一部分,但使用标签prompts:
定义。
your_app_name:
application:
helpers:
submit:
model_1_name:
create: Add %{model}
delete: Delete %{model}
update: Save changes to %{model}
model_2_name:
create: Like
delete: Unlike
update: Unlike
mode_3_name:
create: Add %{model}
delete: Delete %{model}
update: Save changes to %{model}
简单表单
简单表单有自己的yaml部分,位于您的应用程序yaml文件中但不在helpers:
中。如果需要,它与helpers:
在yaml结构中具有相同的优先级。
在您的yaml中,标题标签为simple_form:
,此文件中使用的结构和标签至关重要。
...
simple_form:
error_notification:
default_message: "Please review the problems below:"
hints:
your_model:
column_1_name: Your hint sentence.
column_whatever_name: Please enter the ...
another_model:
column_in_this_model: Valid range is from 1 to 5 ....
labels:
your_model:
column_1_name: Email
column_2_name: Password
priority:
model:
column: Text
prompts:
model:
column: Text
required:
text: 'required'
mark: '*'
prompts:
your_model:
column_name: Select the type of..
another_model:
column_name: Select the state...
这是简短的答案。如果您需要任何后续信息,请告诉我。
使用i18n-tasks gem填补漏洞
安装i18n-tasks gem--它是一个命令行工具,将帮助您了解应用程序本地化字符串在YAML中所需的结构。它揭示了极其不透明的结构背后的结构。
$i18n-tasks health
| en | simple_form.error_notification.default_message | Please review the problems below: |
| en | simple_form.hints.location.short_desc | General information, not a review. |
| en | simple_form.hints.location.website | Please enter the leading http:// or https:// |
| en | simple_form.hints.review.rating | Range is from 1 = Meh to 5 = Super yum |
| en | simple_form.labels.session.email | Email |
| en | simple_form.labels.session.password | Password |
| en | simple_form.no | No |
| en | simple_form.priority.article.category | Article |
| en | simple_form.priority.location.country | United States of America |
| en | simple_form.prompts.article.category | Select the type of article |
| en | simple_form.prompts.location.state | Select the state |
| en | simple_form.required.mark | * |
| en | simple_form.required.text | required |
| en | simple_form.yes
label.
级别直接引用你的翻译 yaml。$i18-tasks missing
这里有一个转折点——在你的代码中需要存储翻译的地方,可以使用伪造字符串 t('bogus') 来调用你的翻译帮助器。
i18-tasks 会将其标记为缺失的翻译字符串,并在此过程中告诉你在该上下文中此字符串的 yaml 结构,以便 Rails i18n 找到它。
是的,这个方法看起来很奇怪,但你只需要这样做,直到理解了 i18n 的结构。从经验中,你就能更好地知道在本地化 yaml 中放置字符串的位置。
锤子式方法 为了完整起见,我也要提到硬编码每个翻译路径也是可行的,例如...
t('defaults.labels.read_more_link_label')
查找:
your_app_name:
application:
defaults:
labels:
read_more_link_label: "Read more..."
i18-tasks gem中有很多功能,非常有帮助。