Nathan H
Nathan H

Reputation: 49371

PHP: Tips on having different languages

We're taking our site international, .fr, .mx and soon some others.

I was thinking of creating language files like english.inc.php that would have basically a big array of every static text that we use.

For example $lang['welcome'] = 'Welcome';

I would dynamically include the correct language file based on the domain name used, and then use those arrays in the code everywhere we used to have static text.

Is that the right way to go?

Before I go too deep into it, I would appreciate any tips from people who had to this before.

Thanks!

Nathan

Upvotes: 2

Views: 955

Answers (3)

Keiji
Keiji

Reputation: 245

I've always used Gettext, it's really fast and you can use external tools such as Poedit.

Upvotes: 0

Ryan Doherty
Ryan Doherty

Reputation: 38740

Please research gettext for php http://php.net/manual/en/book.gettext.php, it is designed for exactly what you are doing and can handle all the various complexities of internationalization. (plurals, context, etc).

The way gettext works is each locale has a plain text file with translations and in your PHP code you do this:

<?php echo _("Welcome to my site");?>

Gettext then pulls from the appropriate locale file.

Internationalization is very complex and it's best to use a tried-and-true solution. We use gettext at Mozilla for most of our big websites and it is fast, well-known and full-featured.

Upvotes: 4

BalusC
BalusC

Reputation: 1108537

Use gettext().

Upvotes: 0

Related Questions