Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i18n in CSS property "content"

I'm using Java Web (Spring framework) and LESS as CSS preprocessor.

When applying internationalization on my project, I successfully migrated every message inside JSP and JS code in message.properties files. But I don't know if it's possible to do the same in CSS/LESS code. I really need to do it since there are messages inside a content property.

I already saw the solution using :lang selector, but it would be much better if I could import the messages from a central input file.

like image 737
Andrewmat Avatar asked Dec 09 '15 12:12

Andrewmat


Video Answer


1 Answers

I'm late to the party, but I want to point out an answer to another Stack Overflow question where it turns out that you can use an attr() value for the content property, referencing an attribute on the selected HTML elements. Shamelessly copying the example from the linked answer, you can write your HTML elements as:

<div class="myclass" data-content="My Content"></div>

and have the following CSS rule applied to them:

.myclass:before {
    content: attr(data-content);
}

actually showing "My Content" on the page. That basically means you can now use Spring i18n as:

<div class="myclass" data-content="<s:message code="content"/>"></div>

and complete your migration to message.properties files.

like image 171
Giulio Piancastelli Avatar answered Nov 01 '22 05:11

Giulio Piancastelli