Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access the Locale in Ruby in CSS files

So i am using CSS, JS and Ruby for a project. Now i have my location set etc, in ruby but i want to access them on my css files. This is to customize views for a particular locale. I have done the following in my controller.

 before_filter :set_locale

 private

 def set_locale
    @locale ||= params[:locale] || session[:locale] || I18n.default_locale
      I18n.locale = session[:locale] = @locale
 end

How do i access this set location in my CSS files? for instance to say that if location is russia then make the height 200 px or something like that.

like image 951
CodeGeek123 Avatar asked Jan 16 '23 01:01

CodeGeek123


1 Answers

You can add current locale to html tag as lang. For example

%html{lang: I18n.locale}
<html lang="en"> or <html lang="ru">

and add specific language style with language prefix

html[lang="en"] {
  # for english part
}

html[lang="ru"] {
  # for russian part
}

also you can change behavior existing class

.test-title {
  html[lang="en"] & {
    // specific english style
  }
}
like image 153
kr00lix Avatar answered Jan 24 '23 15:01

kr00lix