de vs de_AT vs de_CH de_DE

This is a FORK of the CMS Made Simple project and is not oficially supported in any way by the CMS Made Simple development team.
Locked
kriz

de vs de_AT vs de_CH de_DE

Post by kriz »

I'm building a site with English and German content. I've setup the database for en and de and the config_lang.php for en_US and de_DE. My default language is en_US.

In my page template I'm using {lang} to allow language switching.

Code: Select all

define('DEFAULT_LANG', 'en_US');
$force_mle_default = false;

$hls = array(
    'en_US' => array(
        'block'=>'en',
        'flag'=>'<img src="images/lang/en_US.png" style="border:0" alt="English" />',
        'text'=>'English',
    ),
    'de_DE' => array(
        'block'=>'de',
        'parent' => 'de',
        'flag'=>'<img src="images/lang/de_DE.png" style="border:0" alt="Deutsch" />',
        'text'=>'Deutsch',
    ),
);
Everything is working fine as long as the browser sends either en_US or de_DE as HTTP_ACCEPT_LANGUAGE header. As soon as a browser sends de_AT, de_CH or simply de then the DEFAULT_LANG content (that is en_US) is shown.

Is there a possibility to map all the de languages to the de content (and all the en languages to the en content)?

I can add additionaly hls entries but this will duplicate the language choices in my {lang} list and I don't like this...

Kriz
alby

Re: de vs de_AT vs de_CH de_DE

Post by alby »

kriz wrote: Everything is working fine as long as the browser sends either en_US or de_DE as HTTP_ACCEPT_LANGUAGE header. As soon as a browser sends de_AT, de_CH or simply de then the DEFAULT_LANG content (that is en_US) is shown.
In addition to order (or quality) the important prerequisite is parent language and accuracy of the language.
If browser send HTTP_ACCEPT_LANGUAGE with:
de_AT, en, de => en_US
de_AT, de, en => de_DE
de_DE, en => de_DE

This is a very controversial point (view from #44 to #50)

Alby
Wiedmann
Forum Members
Forum Members
Posts: 233
Joined: Wed Mar 26, 2008 1:49 am

Re: de vs de_AT vs de_CH de_DE

Post by Wiedmann »

the important prerequisite is parent language and accuracy of the language.
I think I understand his problem.

Example:
config.lang.php

Code: Select all

<?php
define('DEFAULT_LANG', 'de');
$force_mle_default = false;

$hls = array(
    'de' => array(
        'block'      => 'de',
        'flag'       => '<img src="images/lang/de_DE.png" style="border:0" alt="Deutsch" />',
        'text'       => 'Deutsch',
        'parent'     => 'de',
        'locale_cms' => 'de_DE',
        'locale'     => (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'deu_deu' : 'de_DE.UTF-8',
    ),
    'en' => array(
        'block'      => 'en',
        'flag'       => '<img src="images/lang/en_US.png" style="border:0" alt="English" />',
        'text'       => 'English',
        'parent'     => 'en',
        'locale_cms' => 'en_US',
        'locale'     => (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'eng_us' : 'en_US.UTF-8',
    ),
);
?>
Now I request the page with a browser:
HTTP_ACCEPT_LANGUAGE = en-gb

The result is a German website.

(normaly I use a PEAR package for this locale/browser things. And I'm quite shure, I have English with this browser header.)
alby

Re: de vs de_AT vs de_CH de_DE

Post by alby »

kriz wrote: Is there a possibility to map all the de languages to the de content (and all the en languages to the en content)?
Yes and there is also an inconsistency  :-X

Substitute in mle/function.mle.php:

Code: Select all

		$language = trim($browser_lang[0]);
		if (strlen($language) == 2)
		{
			$language = strtolower($language);
			if(in_array($language, array_keys($t_hls['parent']))) return $t_hls['parent']["$language"];
		}
		else
		{
			$language = strtolower(substr($language, 0, 2)) .'_'. strtoupper(substr($language, 3, 2));
			if(in_array($language, array_keys($t_hls['locale']))) return $t_hls['locale']["$language"];
		}
with:

Code: Select all

		$language = strtolower(trim($browser_lang[0]));
		if(strlen($language) > 2) $language = substr($language, 0, 2);
		if(in_array($language, array_keys($t_hls['parent']))) return $t_hls['parent']["$language"];
Alby
Locked

Return to “[locked] CMSMS MLE fork”