How to do i18n better?

How to do i18n better?

am 19.04.2010 00:55:40 von Andre Polykanine

Hi everyone,

I posted this in the PHP-i18n list, however got no answer so trying
here).
We are making a blog platform (http://oire.org/) which is provided in
several languages (currently they are Russian, Ukrainian, and
English).
Now the i18n process is made as follows: we set a cookie on the site
and depending on it we select the language to display the site in. We
have three (currently) interface files: rus.lng, ukr.lng, and enu.lng
(for English US). the format is the following:
define ("MSG379", "Welcome!");
etc. I know that PHP does support somehow exporting the strings into a
..pod file. Maybe it would be better to do that? If so, how can I do
it?
Could you suggest me maybe a better solution than we currently have?
Thanks a lot!

--
With best regards from Ukraine,
Andre
http://oire.org/ - The Fantasy blogs of Oire
Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org
Twitter: http://twitter.com/m_elensule


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 19.04.2010 03:51:42 von Robert Cummings

Andre Polykanine wrote:
> Hi everyone,
>
> I posted this in the PHP-i18n list, however got no answer so trying
> here).
> We are making a blog platform (http://oire.org/) which is provided in
> several languages (currently they are Russian, Ukrainian, and
> English).
> Now the i18n process is made as follows: we set a cookie on the site
> and depending on it we select the language to display the site in. We
> have three (currently) interface files: rus.lng, ukr.lng, and enu.lng
> (for English US). the format is the following:
> define ("MSG379", "Welcome!");
> etc. I know that PHP does support somehow exporting the strings into a
> .pod file. Maybe it would be better to do that? If so, how can I do
> it?
> Could you suggest me maybe a better solution than we currently have?
> Thanks a lot!

A lot of systems just use conditional includes and a language array. So
the following:

Some main file:

$lang = tell_me_what_the_lang_code_is();
require_once( "lang/messages.$lang.php" );

?>

And then in lang/messages.eng.php:

$messages['Welcome!'] = 'Welcome!';
$messages['login-label'] = 'Login:';
$messages['blah-blah'] = 'Blah blah';

?>

And then in lang/messages.fra.php you might have:

$messages['Welcome!'] = 'Bienvenu!';
$messages['login-label'] = 'Accès :';
$messages['blah-blah'] = 'Le blah blah';

?>

There's lots of variations on this also, but the above is a very common
method.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 19.04.2010 10:10:59 von Peter Lind

Consider checking out http://php.net/gettext - it's the set of
functions in PHP for i18n.

With regards to language switching, you should consider using a url
hierarchy for it, instead of just serving all pages with changing
content.

Regards
Peter

--

WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 19.04.2010 11:53:06 von Michiel Sikma

--0016e64696867c2c9a048493edef
Content-Type: text/plain; charset=UTF-8

On 19 April 2010 00:55, Andre Polykanine wrote:

>
> Now the i18n process is made as follows: we set a cookie on the site
> and depending on it we select the language to display the site in. We
> have three (currently) interface files: rus.lng, ukr.lng, and enu.lng
> (for English US). the format is the following:
> define ("MSG379", "Welcome!");
>
>
You might want to consider making the language dependent on the URL, e.g.
http://site.com/ru/pagename for Russian. Doing it this way certainly isn't a
bad solution, but I do strongly recommend against using define() and using
anonymous translation keys. Usually, you have one base language (which is
usually English due to its lack of special characters and ubiquity) from
which you work. You then either simplify your keys, e.g. 'user_welcome' =>
'Welcome, %1$s!', or make the keys the proper base language strings so you
can wrap everything in a language function.

In the latter case, you might have something like

$username); ?>

, and then if the current language is not English, the _()
function will make the appropriate lookup.

The advantage of this is you won't need to have a tertiary source to tell
you which MSG### corresponds to which piece of text.

Michiel

--0016e64696867c2c9a048493edef--

Re[2]: How to do i18n better?

am 19.04.2010 12:54:37 von Andre Polykanine

Hello Peter,

Regarding the URL switching suggested by you and Michiel, how do I do
this if I have a rather complicated .htaccess file? For instance, a
blog entry URL is formed as follows:
http://oire.org/menelion/entry/190/ which is phisically
http://oire.org/oire.php?o=menelion&e=190
If I need to insert the locale somewhere inhere, sorry, I just don't
know how to do that)
--
With best regards from Ukraine,
Andre
Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org
Yahoo! messenger: andre.polykanine; ICQ: 191749952
Twitter: m_elensule

----- Original message -----
From: Peter Lind
To: Andre Polykanine
Date: Monday, April 19, 2010, 11:10:59 AM
Subject: [PHP] How to do i18n better?

Consider checking out http://php.net/gettext - it's the set of
functions in PHP for i18n.

With regards to language switching, you should consider using a url
hierarchy for it, instead of just serving all pages with changing
content.

Regards
Peter

--

WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 19.04.2010 12:55:03 von Per Jessen

Andre Polykanine wrote:

> etc. I know that PHP does support somehow exporting the strings into =
a
> .pod file. Maybe it would be better to do that? If so, how can I do
> it?
> Could you suggest me maybe a better solution than we currently have?

For mostly dynamic messages or pages, I would take a look at the
gettext() mechanism:

http://php.net/manual/en/book.gettext.php



--=20
Per Jessen, Zürich (14.9°C)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 19.04.2010 15:56:32 von Robert Cummings

Michiel Sikma wrote:
> On 19 April 2010 00:55, Andre Polykanine wrote:
>
>> Now the i18n process is made as follows: we set a cookie on the site
>> and depending on it we select the language to display the site in. We
>> have three (currently) interface files: rus.lng, ukr.lng, and enu.lng
>> (for English US). the format is the following:
>> define ("MSG379", "Welcome!");
>>
>>
> You might want to consider making the language dependent on the URL, e.g.
> http://site.com/ru/pagename for Russian. Doing it this way certainly isn't a
> bad solution, but I do strongly recommend against using define() and using
> anonymous translation keys. Usually, you have one base language (which is
> usually English due to its lack of special characters and ubiquity) from
> which you work. You then either simplify your keys, e.g. 'user_welcome' =>
> 'Welcome, %1$s!', or make the keys the proper base language strings so you
> can wrap everything in a language function.
>
> In the latter case, you might have something like

> $username); ?>

, and then if the current language is not English, the _()
> function will make the appropriate lookup.

Unless you have namespaces (and I can't remember if they completed
namespaced based functions) then don't use something so commuon as a
function named underscore :/

Cheers,
Rob.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 19.04.2010 16:16:36 von Peter Lind

On 19 April 2010 15:56, Robert Cummings wrote:
>
>
> Unless you have namespaces (and I can't remember if they completed
> namespaced based functions) then don't use something so commuon as a
> function named underscore :/
>
> Cheers,
> Rob.
>

You might want to have a look at http://pl2.php.net/_

Regards
Peter


--

WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 19.04.2010 16:19:32 von Robert Cummings

Peter Lind wrote:
> On 19 April 2010 15:56, Robert Cummings wrote:
>>
>> Unless you have namespaces (and I can't remember if they completed
>> namespaced based functions) then don't use something so commuon as a
>> function named underscore :/
>>
>> Cheers,
>> Rob.
>>
>
> You might want to have a look at http://pl2.php.net/_

Ah, never mind *lol* :)

See Tedd... I don't know everything :D

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re[2]: How to do i18n better?

am 19.04.2010 16:28:14 von Peter Lind

On 19 April 2010 12:54, Andre Polykanine wrote:
> Hello Peter,
>
> Regarding the URL switching suggested by you and Michiel, how do I do
> this if I have a rather complicated .htaccess file? For instance, a
> blog entry URL is formed as follows:
> http://oire.org/menelion/entry/190/ which is phisically
> http://oire.org/oire.php?o=menelion&e=190
> If I need to insert the locale somewhere inhere, sorry, I just don't
> know how to do that)

Switch your url structure to something like /en/menelion/entry/190/
and map that to /oire.php?o=menelion&e=190&l=en

You can still default to one language and leave the language bit out
of that - but when switching to a language explicitly, having that as
part of the url helps.

Regards
Peter

--

WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 19.04.2010 23:46:04 von Michiel Sikma

--0016e6d464cc40ba0504849de3f8
Content-Type: text/plain; charset=UTF-8

On 19 April 2010 15:56, Robert Cummings wrote:

> -snip-
>
>
> Unless you have namespaces (and I can't remember if they completed
> namespaced based functions) then don't use something so commuon as a
> function named underscore :/
>
> Cheers,
> Rob.
>
>
No, you're actually absolutely right about that, since I had a custom
function in mind when I wrote that example code, not PHP's built in gettext
function ;)
I use frameworks so I end up doing $this->lang() or something similar
myself.

Michiel

--0016e6d464cc40ba0504849de3f8--

Re: How to do i18n better?

am 20.04.2010 01:17:47 von Ashley Sheridan

--=-GgEiHAZo4kC/gkGXbL5a
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Mon, 2010-04-19 at 19:17 -0400, Jason Pruim wrote:

> On Apr 18, 2010, at 6:55 PM, Andre Polykanine wrote:
>
> > Hi everyone,
> >
> > I posted this in the PHP-i18n list, however got no answer so trying
> > here).
> > We are making a blog platform (http://oire.org/) which is provided in
> > several languages (currently they are Russian, Ukrainian, and
> > English).
> > Now the i18n process is made as follows: we set a cookie on the site
> > and depending on it we select the language to display the site in. We
> > have three (currently) interface files: rus.lng, ukr.lng, and enu.lng
> > (for English US). the format is the following:
> > define ("MSG379", "Welcome!");
> > etc. I know that PHP does support somehow exporting the strings into a
> > .pod file. Maybe it would be better to do that? If so, how can I do
> > it?
> > Could you suggest me maybe a better solution than we currently have?
> > Thanks a lot!
>
> I've never actually had to do this... But one idea that I came up with
> is using the browser language in taking a best guess at what language
> to display... In other words, if the user's browser language is set to
> Chinese, you can be fairly certain they read Chinese :)
>
> And now that I typed that out, I realize that may not be what you are
> really looking for... And that's when we get into the part where I
> can't help alot because I've never had to do it :)
>
> So good luck! :)
>
>
>
>


That's the check I did on the last site i worked on (vicestyle.com) The
user agent string is checked for a language and the site uses that. If
none is found (bearing in mind that there's no hard and fast rule about
what can go into a UA string) then it defaults to English.

Links within the site itself allow the user to change their language
afterwards, and you could store that in a cookie to it remembers their
choice.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-GgEiHAZo4kC/gkGXbL5a--

Re: How to do i18n better?

am 20.04.2010 01:17:54 von Jason Pruim

On Apr 18, 2010, at 6:55 PM, Andre Polykanine wrote:

> Hi everyone,
>
> I posted this in the PHP-i18n list, however got no answer so trying
> here).
> We are making a blog platform (http://oire.org/) which is provided in
> several languages (currently they are Russian, Ukrainian, and
> English).
> Now the i18n process is made as follows: we set a cookie on the site
> and depending on it we select the language to display the site in. We
> have three (currently) interface files: rus.lng, ukr.lng, and enu.lng
> (for English US). the format is the following:
> define ("MSG379", "Welcome!");
> etc. I know that PHP does support somehow exporting the strings into a
> .pod file. Maybe it would be better to do that? If so, how can I do
> it?
> Could you suggest me maybe a better solution than we currently have?
> Thanks a lot!

I've never actually had to do this... But one idea that I came up with
is using the browser language in taking a best guess at what language
to display... In other words, if the user's browser language is set to
Chinese, you can be fairly certain they read Chinese :)

And now that I typed that out, I realize that may not be what you are
really looking for... And that's when we get into the part where I
can't help alot because I've never had to do it :)

So good luck! :)




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 20.04.2010 02:46:16 von TedD

At 12:17 AM +0100 4/20/10, Ashley Sheridan wrote:
>Links within the site itself allow the user to change their language
>afterwards, and you could store that in a cookie to it remembers their
>choice.
>
>Thanks,
>Ash

Ash:

This is something I found interesting.

http://php1.net/c/language-example/

Click the flag of your choice. However, I have no idea of the quality
of the translation.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re[2]: How to do i18n better?

am 20.04.2010 12:34:30 von Andre Polykanine

Hi Ash,

Yepp, it's understood. But how exactly did you store the
language-specific strings: in an array or using another way?


--
With best regards from Ukraine,
Andre
Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org
Yahoo! messenger: andre.polykanine; ICQ: 191749952
Twitter: m_elensule

----- Original message -----
From: Ashley Sheridan
To: Jason Pruim
Date: Tuesday, April 20, 2010, 2:17:47 AM
Subject: [PHP] How to do i18n better?

On Mon, 2010-04-19 at 19:17 -0400, Jason Pruim wrote:

> On Apr 18, 2010, at 6:55 PM, Andre Polykanine wrote:
>
> > Hi everyone,
> >
> > I posted this in the PHP-i18n list, however got no answer so trying
> > here).
> > We are making a blog platform (http://oire.org/) which is provided in
> > several languages (currently they are Russian, Ukrainian, and
> > English).
> > Now the i18n process is made as follows: we set a cookie on the site
> > and depending on it we select the language to display the site in. We
> > have three (currently) interface files: rus.lng, ukr.lng, and enu.lng
> > (for English US). the format is the following:
> > define ("MSG379", "Welcome!");
> > etc. I know that PHP does support somehow exporting the strings into a
> > .pod file. Maybe it would be better to do that? If so, how can I do
> > it?
> > Could you suggest me maybe a better solution than we currently have?
> > Thanks a lot!
>
> I've never actually had to do this... But one idea that I came up with
> is using the browser language in taking a best guess at what language
> to display... In other words, if the user's browser language is set to
> Chinese, you can be fairly certain they read Chinese :)
>
> And now that I typed that out, I realize that may not be what you are
> really looking for... And that's when we get into the part where I
> can't help alot because I've never had to do it :)
>
> So good luck! :)
>
>
>
>


That's the check I did on the last site i worked on (vicestyle.com) The
user agent string is checked for a language and the site uses that. If
none is found (bearing in mind that there's no hard and fast rule about
what can go into a UA string) then it defaults to English.

Links within the site itself allow the user to change their language
afterwards, and you could store that in a cookie to it remembers their
choice.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re[2]: How to do i18n better?

am 20.04.2010 18:56:48 von Ashley Sheridan

On Tue, 2010-04-20 at 13:34 +0300, Andre Polykanine wrote:
> Hi Ash,
>
> Yepp, it's understood. But how exactly did you store the
> language-specific strings: in an array or using another way?
>
>
> --
> With best regards from Ukraine,
> Andre
> Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org
> Yahoo! messenger: andre.polykanine; ICQ: 191749952
> Twitter: m_elensule
>
> ----- Original message -----
> From: Ashley Sheridan
> To: Jason Pruim
> Date: Tuesday, April 20, 2010, 2:17:47 AM
> Subject: [PHP] How to do i18n better?
>
> On Mon, 2010-04-19 at 19:17 -0400, Jason Pruim wrote:
>
> > On Apr 18, 2010, at 6:55 PM, Andre Polykanine wrote:
> >
> > > Hi everyone,
> > >
> > > I posted this in the PHP-i18n list, however got no answer so trying
> > > here).
> > > We are making a blog platform (http://oire.org/) which is provided in
> > > several languages (currently they are Russian, Ukrainian, and
> > > English).
> > > Now the i18n process is made as follows: we set a cookie on the site
> > > and depending on it we select the language to display the site in. We
> > > have three (currently) interface files: rus.lng, ukr.lng, and enu.lng
> > > (for English US). the format is the following:
> > > define ("MSG379", "Welcome!");
> > > etc. I know that PHP does support somehow exporting the strings into a
> > > .pod file. Maybe it would be better to do that? If so, how can I do
> > > it?
> > > Could you suggest me maybe a better solution than we currently have?
> > > Thanks a lot!
> >
> > I've never actually had to do this... But one idea that I came up with
> > is using the browser language in taking a best guess at what language
> > to display... In other words, if the user's browser language is set to
> > Chinese, you can be fairly certain they read Chinese :)
> >
> > And now that I typed that out, I realize that may not be what you are
> > really looking for... And that's when we get into the part where I
> > can't help alot because I've never had to do it :)
> >
> > So good luck! :)
> >
> >
> >
> >
>
>
> That's the check I did on the last site i worked on (vicestyle.com) The
> user agent string is checked for a language and the site uses that. If
> none is found (bearing in mind that there's no hard and fast rule about
> what can go into a UA string) then it defaults to English.
>
> Links within the site itself allow the user to change their language
> afterwards, and you could store that in a cookie to it remembers their
> choice.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>

The differences were stored in an array with a file per language like
so:

$lang['Welcome'] = 'Welcome';
$lang['Contact'] = 'Contact';

and in a a different file for German maybe:

$lang['Welcome'] = 'Willkommen';
$lang['Contact'] = 'Kontakt';

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 20.04.2010 20:27:12 von Per Jessen

Ashley Sheridan wrote:

> That's the check I did on the last site i worked on (vicestyle.com)
> The user agent string is checked for a language and the site uses
> that. If none is found (bearing in mind that there's no hard and fast=

> rule about what can go into a UA string) then it defaults to English.=


The language preference is not set in the UA string, it is set in the
Accept-Language header along with the priority.=20

> Links within the site itself allow the user to change their language
> afterwards, and you could store that in a cookie to it remembers thei=
r
> choice.

The standard in Apache is 'prefer-language'.



--=20
Per Jessen, Zürich (12.4°C)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: How to do i18n better?

am 20.04.2010 20:50:13 von Ashley Sheridan

--=-ZnkPk6Z+GKJe6Kh7+cXF
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Tue, 2010-04-20 at 20:27 +0200, Per Jessen wrote:

> Ashley Sheridan wrote:
>=20
> > That's the check I did on the last site i worked on (vicestyle.com)
> > The user agent string is checked for a language and the site uses
> > that. If none is found (bearing in mind that there's no hard and fast
> > rule about what can go into a UA string) then it defaults to English.
>=20
> The language preference is not set in the UA string, it is set in the
> Accept-Language header along with the priority.=20
>=20
> > Links within the site itself allow the user to change their language
> > afterwards, and you could store that in a cookie to it remembers their
> > choice.
>=20
> The standard in Apache is 'prefer-language'.
>=20
>=20
>=20
> --=20
> Per Jessen, Zürich (12.4°C)
>=20
>=20


I wasn't aware of that one, but I know most browsers send a language
with part of the UA string

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-ZnkPk6Z+GKJe6Kh7+cXF--

Re: How to do i18n better?

am 21.04.2010 07:50:10 von Per Jessen

Ashley Sheridan wrote:

> On Tue, 2010-04-20 at 20:27 +0200, Per Jessen wrote:
>=20
>> Ashley Sheridan wrote:
>>=20
>> > That's the check I did on the last site i worked on (vicestyle.com=
)
>> > The user agent string is checked for a language and the site uses
>> > that. If none is found (bearing in mind that there's no hard and
>> > fast rule about what can go into a UA string) then it defaults to
>> > English.
>>=20
>> The language preference is not set in the UA string, it is set in th=
e
>> Accept-Language header along with the priority.
>>=20
>> [snip]=20
>=20
>=20
> I wasn't aware of that one, but I know most browsers send a language
> with part of the UA string
>=20
> Thanks,
> Ash

Accept-Language, the 'prefer-language' cookie, the various apache confi=
g
options etc. are all part of the Apache content-negotiation
setup/framework. On our website(s), I rely entirely on
Accept-Language. In the very rare case where it isn't set, I set a
default based on the IP-address of the client. =20


--=20
Per Jessen, Zürich (8.4°C)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php