Page 1 of 1

Multi language site problem. UTF-8 or ISO-8859-1 ?

Posted: Fri Jan 27, 2006 9:08 am
by colovray
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I have a multi language site with possibilities to choose between english, french, german, italien and spanish.
To do this I keep a config file for each language and each file has an entry using the define command for
many variables. For example for a variable NATION each language file would have the approporiate definition and so in the french file I would have a line

define("NATION","Nationalité");


Here is a short example of what the php file would look like.

index.php

Code: Select all

<?php 
session_start();
ini_set('arg_separator.output','&'); 
echo("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");

$mylang = 'fr';
require_once( "../language/lang-$mylang.php" );
// next tline commented out. It appears in lan-fr.php
//define("NATION","Nationalité");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1 "/>
	<title>Test1</title>

</head>

<body>
<? echo  NATION ?>
<P>
Nationalité


</body>
</html>
The output on the web is as follows:

Nationalité
Nationalité


As you can see the variable NATION has been correctly resolved but the string in the file is not displayed as I would want. If I change ISO-8859-1 to UTF-8 in this file then I get the opposite result:

Nationalit鼐>
Nationalité

This is annoying and is confusing me.
I need to use the line
require_once( "../language/lang-$mylang.php" );
to get the correct language definitions and I think that the problem lies here, as if I define the variable within
this index.php file then it works out fine.

Can anyone help explain this?


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Jan 27, 2006 9:26 am
by feyd
I'm not sure about the binary safety of constants, but have you tried using an array of the language values?

$lang['Nation'] for instance. I know standard strings are binary safe..

Posted: Fri Jan 27, 2006 10:51 am
by Maugrim_The_Reaper
Keep in mind that when you set a charset, the browser will expect the actual output to be correctly encoded.

So if you use UTF-8 save the file in UTF-8 encoding... Otherwise you're passing an ISO-8859-1 (or whatever) file around with a false charset setting. (Usually ends up in my experience misrepresenting á, é type characters).

I'd also suggest using an array of some description. I know where you're coming from, try passing my real gaelic name - Pádraic - around in PHP, to databases, back into HTML... Weird stuff happens. Hotmail and Sourceforge have never managed to display my name correctly - it's annoying so it is.

/me leaves to sulk for a bit