CSS文件的Rails I18n [英] Rails I18n of CSS file

查看:23
本文介绍了CSS文件的Rails I18n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的网站国际化,其中一件事是为不同的语言使用不同的字体大小.还有一些文字图片也需要替换.

I am trying to internationalize my site, and one thing is to use different font-size for different languages. Also some text-images need to be replaced as well.

我认为唯一的方法是在公共文件夹中添加额外的特定于语言环境的 CSS 文件,并根据我认为的语言环境加载它们.这避免了资产管道编译那些特定的 CSS 文件.但我想知道是否有更好的方法来做到这一点?

I think the only way to do this is to have additional locale-specific CSS files in the public folder and load them based on locale in my view. This avoids asset pipeline from compiling those specific CSS files. But I am wonderiing if there a better way to do this?

推荐答案

组织中最好的选择是拥有特定于本地化的不同样式表,然后在布局中设置条件,根据区域设置呈现哪些样式表.

Your best bet in organization is to have different style sheets specific to localization, then set up a condition in your layout on what style sheets to render based of the locale.

只需放置特定于本地的样式,如果您考虑一下...它不应该对加载时间产生太大影响,因为我相信您只是在更改字体大小.

Just only put local specific style, and if you think about it...it shouldn't effect load times that much because I believe you are only changing font sizes.

来自 OP 的更新:

这是我为使其正常工作而进行的配置:

Here is what I have configured to have this working:

  • 我在 app/assets/stylesheets
  • 下创建了一个 locales 目录
  • 我将特定于语言环境的样式表放入其中,例如 fr.sass
  • 我在 layouts/application.html.erb 中设置条件以引用 css 文件:<代码><% if I18n.locale != :en %><%= stylesheet_link_tag "locales/" + I18n.locale.to_s %><%结束%>
  • 我在 config/application.rb
  • 中设置了预编译规则
  • I created a locales directory under app/assets/stylesheets
  • I put locale specific stylesheets inside, such as fr.sass
  • I setup the condition in the layouts/application.html.erb to reference the css files: <% if I18n.locale != :en %> <%= stylesheet_link_tag "locales/" + I18n.locale.to_s %> <% end %>
  • I setup the pre-compile rules in config/application.rb

config.assets.precompile += 'locales/*.css'

请注意,我将要编译到 application.css 的资产列入白名单,因此特定于语言环境的样式不会进入 application.css.

Note that I am white-listing the assets I want to compile into application.css, so the locale specific styles will not get into the application.css.

这篇关于CSS文件的Rails I18n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆