开发者

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 us开发者_开发百科ed 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


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.


Use gettext().


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜