使用i18n-js插件的Rails javascript
rails javascript i18n specific yml using i18n-js plugin
我的问题是,如果有任何方式配置i18n-js,以便只有一个特定的.yml文件正在由javascript查找,但不是全部。我遵循了下面链接中的示例,并让javascript查找正确的键;然而,当我查看这个插件在inspect元素中生成的translate .js时,所有的翻译键都显示出来了。我们担心随着应用的发展,这将成为一个问题,因为javascript只需要知道它需要的翻译键。我想只是有一个config/locale/en/javascript。把javascript的所有翻译都放在这里。
遵循示例
https://github.com/fnando/i18n-js http://blog.10to1.be/rails/2011/03/22/localizing-javascript-in-your-rails-app/跑rake i18n:js:setup
application.js
//= require i18n
//= require i18n/translations
application.html.haml
= javascript_include_tag 'translation'
目录|config
|-locales
|--en
|---en.yml
|---javascript.yml <------ that's what I want and the js only look at this one2
根据文档可以指定一个特定的键。我有问题得到翻译。js文件更新,所以我不能验证这实际上是有效的,但文档说它:
内部配置/i18n-js.yml
translations:
- file: "app/assets/javascripts/application/i18n/translations.js"
only: '*.js*'
在en.yml js:
posts:
select2:
placeholder: 'Please, select tags'
no-matches: 'No tags found'
目前没有办法通过简单的配置来做到这一点。
i18n-js
不知道任何YML翻译文件或翻译文件夹(如Rails的默认config/locales
)。它只是要求i18n
gem(随Rails一起发布)检索所有可用的翻译,然后将它们导出为JS格式。
js_i18n
,在其中覆盖默认的i18n加载路径,如下所示:
# config/environments/js_i18n.rb
# code similar to the rest of your config files - you could copy `development.rb`
# ...
config.i18n.load_path = Dir[Rails.root.join('config', 'locales', 'js', '*.{rb,yml}').to_s]
然后使用config/locales/js
下只加载YML/Ruby文件的环境来运行任何你喜欢的任务,例如:
RAILS_ENV=js_i18n rake i18n:js:export
相关文章:
- Rails/Javascript链接到用于切换多个元素的函数
- Ruby on Rails javascript getting truncated
- Rails/Javascript:将实例变量传递给Coffeescript时发生Uncaught ReferenceEr
- 有没有一种方法可以在IE8中解决我的Rails javascript应用程序.js的问题
- Ruby on rails javascript没有;无法正确加载(HTML5模板)
- 将Rails-Javascript资产拆分为head和body
- Rails:Javascript中的附加和插入代码
- Karma与Jasmine和Rails javascript清单
- 生产中的Rails Javascript 404(资产管道)
- Rails / JavaScript 在渲染视图之前交换 CSS 类
- Rails JavaScript 包含 TypeError:“null”不是一个对象(评估 'document.
- Rails JavaScript JSON 解析错误
- pjax losing the rails javascript
- Rails:Javascript 没有到达 heroku
- Websocket Rails JavaScript 不起作用
- Rails Javascript haml 变量创建
- 包含 Rails javascript,但不在 heroku 上执行
- 预编译后缺少 Rails JavaScript 资产
- Rails / javascript试图隐藏没有一定宽度的图像
- Rails:Javascript 从一个文件运行,但不能从另一个文件运行