I have translated the GnuCash website to zh_CN.

Tao Wang dancefire at gmail.com
Sat May 1 23:12:34 EDT 2010


On Sun, May 2, 2010 at 9:00 AM, Geert Janssens
<janssens-geert at telenet.be> wrote:
> On Saturday 1 May 2010, Tao Wang wrote:
>> Hi,
>>
>> I have translated GnuCash website to zh_CN. Could you commit it?
>>
> Hi Tao,
>
> I have added your translation to the website, but it doesn't seem to work when
> I test it on my system. Does it work for you ?
>
> Perhaps one of the devs with access to the server logs could check if the
> translations cause some error.
>

No, it doesn't work for me.

I check the info.php on the server, which contains a list of "locale
-a". I found server doesn't support "zh_CN", I think this might be the
problem.

For Japanese, the debug info on the first line is:
<!-- ja_JP , locale_res [ja_JP] , dir_res /home/gnucash/www/gnucash -->
But, for Chinese, it's:
<!-- zh_CN , locale_res [] , dir_res /home/gnucash/www/gnucash -->
which locale_res is empty.

>> And for website, since it's PHP-based website, Could you add a short
>> code to automatically detect user's language? I think the information
>> should contained in the users request. If the user language detected,
>> and the language is available for the website, then just redirect user
>> to their language automatically. Thanks.
>>
> This is a useful idea. I may have a look at this later.
>
> Geert
>

I write a code to automatically detect user's language and assign
$locale and $lang_dir
=============================
# key: locale, value: lang_dir
$supported_languages = array(
	'de_DE' => 'de', 'es_ES' => 'es', 'fr_FR' => 'fr',
	'it_IT' => 'it', 'ja_JP' => 'ja', 'nb_NO' => 'nb',
	'nl_NL' => 'nl', 'pl_PL' => 'pl', 'pt_PT' => 'pt_PT',
	'zh_CN' => 'zh_CN', 'en_US' => ''
	);

if ($locale == "") {
	# Get user prefered languages, and match agasint supported language
	if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
	{
		# tolower() => remove space => '-' -> '_'
		# "fr-ch;q=0.3, en, zh-cn;q=0.7" => "fr_ch;q=0.3,en,zh_cn;q=0.7"
		$languages = str_replace('-','_', str_replace(' ', '',
str_strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])));
		$languages = explode(",", $languages);
		foreach ($languages as $item)
		{
			# "zh_cn;q=0.7" => "zh_cn"
			$lang = substr($item, 0, strcspn($item, ';'));
			$lang_short = substr($lang, 0, 2);
			# full match is prefer, but short match is acceptable.
			foreach ($supported_languages as $loc_lang => $loc_dir)
			{
				if ($lang == str_strtolower($loc_lang)) { $locale = $loc_lang; break; }
				if ($lang_short == substr($loc_lang, 0, 2 )) { $locale = $loc_lang; }
			}
			if ($locale != "") { break; }
		}
	}
	# nothing matched, use default language
	if ($locale == "") { $locale = "en_US"; }
	$lang_dir = $supported_language[$locale];
}
=================================

The only problem is the code cannot distinguish "automatic" and
"English". Because, based on current structure, English page is same
as http://www.gnucash.org/, rather than http://www.gnucash.org/en/.
So, visit http://www.gnucash.org, the language should be automatically
detected, and when user click [English], and really want English, but
since the link is same, the code will automatically detected the
language again. If English page moved to /en, just like other
language, I think the problem will be fixed.

And one more question, why not use parameter for different language?
such as http://www.gnucash.org/index.phtml?lang=zh_CN. So that
sub-directories for different languages is not necessary anymore. Only
one set files is required.

I also found the <meta> for charset is missing, the following line
should put in <head>, and before <title></title>:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />


-- 
Regards

Tao Wang


More information about the gnucash-devel mailing list