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

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

问题描述

我试图将我的网站国际化,一件事是为不同的语言使用不同的字体大小。还有一些文本图像也需要替换。



我认为唯一的方法是在公共文件夹中加载特定于区域设置的CSS文件,并加载他们基于我的视图中的区域设置。这避免了编译这些特定CSS文件的资产管道。

解决方案

在组织中最好的办法是使用不同的样式表到本地化,然后在布局中根据区域设置在要呈现的样式表上设置一个条件。



只需放置本地特定样式,如果您考虑



来自OP的更新:



这里是我配置的工作:




  • 我创建了一个 locales 目录下的 app / assets / stylesheets

  • 我把locale特定的样式表放在里面,例如 fr.sass

  • 我在 layouts / application.html.erb 中设置条件引用css文件:

    <%if I18n.locale!=:en%>
    <%= stylesheet_link_taglocales /+ I18n.locale.to_s%>
    <%end%>

  • 我在 config / application.rb中设置预编译规则 li>


config.assets.precompile + ='locales / *。css' p>

请注意,我将要编译成 application.css 的资源是白色的,所以特定于语言环境的样式不进入 application.css


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.

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.

UPDATE from OP:

Here is what I have configured to have this working:

  • 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'

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.

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

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