Internationalization of bg-image by CSS

1

I have a project in Rails that needs different images for each language, however and image is pulled from CSS and I can not change it. How to change the image according to the chosen language?

  background: url("/caminho/imagem.jpg");

edit: I have received many answers and forgot to provide some infos, my ruby is 1.8.7 and rails is 3, it is not advisable for me to create another css file and although I am not sure, my css is not 2 or any other most recent.

edit2: and I'm using haml instead of html

    
asked by anonymous 11.09.2014 / 21:35

3 answers

1

What worked was to create 2 code blocks within the same css file:

class-br{
  atributos-br
}
class-en{
  atributos-en
}

and use the class attribute in haml by assigning locale as variable:

%li{:class=> "class-#{params[:locale]}"}
    
15.09.2014 / 16:58
1

PHP uses translation packages for each language:

language/
     pt.php
     en.php
     es.php

You can only create a CSS with the images for each language. Separate the images in a css-idioma.css and load whatever it is referring to the language.

css/
     pt.css
     en.css
     es.css

css/pt.css background: url("/caminho/imagem.jpg"); // background escrito em português
css/en.css background: url("/caminho/imagem.jpg"); // background escrito em ingles
css/en.css background: url("/caminho/imagem.jpg"); // background escrito em espanhol
    
11.09.2014 / 22:19
1

Complementing excellent response from @PapaCharlie :

After you have created the different CSS for each language, use the following code to tell Rails that these CSS should also be precompiled for production:

# /config/initializers/assets.rb
Rails.application.config.assets.precompile += ["imagens.pt-BR.css", "imagens.en.css"]

Read more:

12.09.2014 / 02:13