See Variadic mixin arguments, Loops, List Functions. For example it could be implemented somewhat like:
.test {
.translate('/images/image.png', grc, lat, san);
}
.translate(@image, @langs...) {
background-image: @image;
.-(length(@langs));
.-(@i) when (@i > 0) {
.-((@i - 1));
@lang: extract(@langs, @i);
&:lang(@{lang}) {
background-image: replace(@image, "\.", "_@{lang}.");
}
}
}
replace
function requires Less 1.7.0 but for earlier versions you can use plain string interpolation/concatenation or format function as in @helderdarocha answer.
(Also note that the @langs...
mixin parameter above can also accept the language list as a single variable), e.g.:
@languages: de, fr, es, ru, en-uk; // in fact commas here are optional too
.test {
.translate('/images/image.png', @languages);
}
And just in case, the same mixin using for
wrapper (just to show that Less loops don't have to be that scary :):
@import "for";
.translate(@image, @langs...) {
background-image: @image;
.for(@langs); .-each(@lang) {
&:lang(@{lang}) {
background-image: replace(@image, "\.", "_@{lang}.");
}
}
}