Currently we're using language codes in the form

fr-CA

where fr is the lower case two-digit language code (French) and CA is the upper case two-digit country code.

This form of language code is described as having a primary 'tag' - the two-digit language code - and a 'subtag' for a 'region'--in this case, Canada.

However, Drupal core uses all lower case for this type of language code. E.g.:

pt-br

for Brazilian Portuguese.

To keep with core, maybe we should also switch to all lower case.

It's worth determining what common practice is. All the examples I find on W3C documents use upper case for the country-code "region" subtags.

http://www.w3.org/International/articles/language-tags/

See also a search for "region" subtags here:

http://people.w3.org/rishida/utils/subtags/index.php?searchtype=1&search...

It seems likely that both forms are accepted, but I'd like to confirm this before making the change.

CommentFileSizeAuthor
#3 country_code_lowercase.patch5.68 KBrecidive

Comments

nedjo’s picture

Title: Switch to all lower case language codes? » Switch to all lower case language codes

Confirmed that language codes are to be considered case insensitive.

http://www.w3.org/International/articles/language-tags/ :

Although the codes are case insensitive, they are commonly written lowercased, but this is merely a convention.

http://www.ietf.org/rfc/rfc3066.txt (the standard referenced in the above w3 doc):

All tags are to be treated as case insensitive; there exist conventions for capitalization of some of them, but these should not be taken to carry meaning.

So we should both (a) switch to all lower case (for consistency with Drupal core) and (b) accept both lower and upper case when matching (i.e., be case insensitive).

Work will include:

  • When creating new languages, create them as lower case.
  • When matching languages, use strtolower() on input to match to lower case.
  • Write an update to update existing language codes--both in language and node tables.
recidive’s picture

Write an update to update existing language codes--both in language and node tables.

The update path may be more complex than that, since there are several modules that stores languages and use them for matching languages in languages table. Some of them may not be case insensitive when matching.

In core, languages fields are: languages.language, node.language and locales_target.language, there is also the language_default variable.

recidive’s picture

Status: Active » Needs review
StatusFileSize
new5.68 KB

I guess we can just have country_code generate new languages lowercased.

Then make it insensitive when matching languages.

What do you think?

Roughed in a patch to do that.

catch’s picture

So is the idea to leave existing languages created by country code with the 'en-CA' format? Presumably since we're just doing this for consistency that ought to be fine - and safer than an incomplete update path.

catch’s picture

Status: Needs review » Postponed (maintainer needs more info)

Did some testing with this and committed #3. Moving to active needs more info in case we need to discuss an upgrade path further.