【文件属性】:
文件名称:i18n:Ruby的国际化(i18n)库
文件大小:104KB
文件格式:ZIP
更新时间:2021-02-02 03:53:11
ruby i18n RubyRuby
RubyI18n
Ruby国际化和本地化(i18n)解决方案。
目前由@radar维护。
用法
滑轨
您将最常在Rails应用程序中使用此库。
用法的示例, 。
Ruby(无Rails)
如果要在没有Rails的情况下使用此库,则只需将i18n添加到Gemfile :
gem 'i18n'
然后使用一些翻译和默认语言环境配置I18n:
I18n . load_path << Dir [ File . expand_path ( "config/locales" ) + "/*.yml" ]
I18n . default_locale = :en # (note that `en` is already the default!)
您项目中的一个简单翻译文件可能位于config/locales/en.yml ,如下所示:
en :
test : " This is a test "
然后,您可以通过以下方式访问此翻译:
I18n . t ( :test )
您可以通过将I18n.locale设置为其他值来切换项目中的语言环境:
I18n . locale =