Rails i18n:如何知道当前的语言是什么?

问题描述 投票:0回答:1

我知道 i18n/l10n 通常在 Rails3 中是如何完成的,因此我选择使用一个单独的 ERB 文件来调用

t(...)
进行本地化。但对于特定的部分,我需要一些特别的东西:

我需要显示一个字符串,其本地化来自外部数据库

那么我如何知道当前的语言,以使用

en
ja
参数调用外部数据库?

类似于 UNIX 中的 $LANG。最好从视图或控制器访问。

ruby-on-rails-3 internationalization
1个回答
140
投票
I18n.locale # Get and set the current locale

本地存储在符号中,例如

:en
:de
(不是字符串
'en'
'de'
) 在 if 语句中:

if I18n.locale==:en
...
end
© www.soinside.com 2019 - 2024. All rights reserved.