Re: Multiple languages in :lang pseudo selector?

Hello Paweł,

See below for a few comments.

On 2011/10/03 5:13, Paweł Dyda wrote:
> Hi,
>
> As we all know, CSS has built-in Localization mechanism that helps adapt
> style sheets to concrete Locale demands.
> One of the examples of CSS pseudo-classes designed for these purposes is
> :lang.
>
> Now, quite often I have a problem where I need to define certain property
> for a group of languages (for example set different color scheme or
> different font size for Asian customers).
> OK, if only developers would use element Identifiers, there won't be any
> problem:
>
> #someid:lang(ja), #someid:lang(ko), #someid:lang(zh), #someid:lang(vi) {
>    background-color: black;
>    .... (other properties)
> }
>
> Unfortunately, in my company I and my colleagues are struggling to enforce
> this best practice, so instead they might use an identifier for just a
> top-level element (like DIV, etc.) but not for its children. In such case,
> selector code could look like:
>
> #main p span:lang(ja), #main p span:lang(ko), #main p span:lang(zh), #main p
> span:lang(vi) {
>    ...
> }

Yes, this gets very long and clumsy. One way to shorten it may be to use 
a separate stylesheet per language, which then includes common parts so 
that things don't get out of sync too easily. But this only works if we 
are talking about separate pages, not for pages that mix all these 
languages.

> If we have quite a few such definitions (for example some elements must be
> wider in German, Greek and Russian but not in other languages), maintaining
> such CSS file could quickly become challenging. And unfortunately, files
> with many such definitions could quickly become totally unreadable. Of
> course in my idealistic example, all the properties where grouped into one
> definition but in reality Localization Team would define another class for
> each element they need to modify - this would create terrible mess.
>
> Currently, what we do is, we actually implement server-side Localization for
> CSS files (i.e. generating CSS for given Locale on the fly), but this is
> non-standard solution which requires quite an effort to get it right.
> What I think we could afford to make an improvement to current :lang
> pseudo-selector specification - let it handle comma-separated list of
> languages:
>
> #main p span:lang(ja,ko,zh,vi) {
>   ...
> }
>
> I understand that this could complicate CSS parsing algorithms but actually
> it could be viewed as just a syntactic sugar - it could be easily
> transformed to previous form.

It could also be quite a bit faster. But I'm not sure. Anyway, there is 
a totally unofficial (and as far as I understand not yet published) 
draft of CSS selectors 4, which at 
http://dev.w3.org/csswg/selectors4/#matches contains syntax that may be 
applicable to your case.

Your selector would then look something like:

#main p span:matches(:lang(ja), :lang(ko), lang(zh), :lang(vi))

> Please tell me what you think about it?

I think the best idea is to send your use case and your syntax proposal 
to the www-style@w3.org mailing list.

Regards,    Martin.

> Kind regards,
> Paweł Dyda.
>

Received on Monday, 3 October 2011 09:20:59 UTC