Internationalization

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Internationalization

Post by Ambush Commander »

I recently internationalized a website. I wonder how I did.

You can view it here: http://www.taijiclub.org/en/Main_Page

Some juicy information: there's a folder called locales with files like en.ini which looks like:

Code: Select all

[Menu]
Main_Page="Main Page"
About="About"
News="News"
Downloads="Downloads"
Contact="Contact"
Events="Events"
Digest="Digest"
They're parsed by PHP and put into an array called STRINGS, then whenever I need a particular string I just go echo $STRINGS[$key_name].

Language selection is done via a lang variable that's transparently passed via mod_rewrite.

Input please!

Edit: Oops...
Last edited by Ambush Commander on Sun Nov 27, 2005 4:25 pm, edited 1 time in total.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

umm....your localhost isn't my localhost

8O
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Fixed. :oops:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Internationalization

Post by Weirdan »

Ambush Commander wrote: You can view it here: http://localhost/taijiclub/en/Main_Page
Oh, can we? ;)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

so what are we looking for?

it defaults to English for me...is that what I'm supposed to be seeing? Is there a language selector somewhere?
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Weirdan wrote:
Ambush Commander wrote: You can view it here: http://localhost/taijiclub/en/Main_Page
Oh, can we? ;)
Ambush Commander wrote:Fixed. :oops:
Smartypants... :roll:

Back on topic:

If I were you, I wouldn't use ini's. Parsing them is slower compared to regular PHP variables. And they aren't very flexible; no escaping, value type constrained to numbers and simple strings, can't use other variables in your language string, etc. I use a regular php file for language strings, all packed nicely within a $lang[] array.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Hmm... that wouldn't be too difficult to do.

However, I've begun to become pathologically opposed to includes that do anything besides make class/constant definitions (which means they should always be called include_once()). So... it'd look like...

Code: Select all

LanguageStrings_En extends LanguageStrings
{
  var $menu = array('Main_Page' => 'Main Page');
}
Edit - Actually, I can't do that. All my crappy text editors either can't display Chinese characters (actually font-mixing) or attach a BOM... and you all know about those strange headers already sent errors in Unicode mode.
Last edited by Ambush Commander on Sun Nov 27, 2005 4:43 pm, edited 1 time in total.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Ambush Commander wrote:Hmm... that wouldn't be too difficult to do.

However, I've begun to become pathologically opposed to includes that do anything besides make class/constant definitions (which means they should always be called include_once()). So... it'd look like...

Code: Select all

LanguageStrings_En extends LanguageStrings
{
  var $menu = array('Main_Page' => 'Main Page');
}
Well, actually, I just screw OO here, and make $lang a global variable. I know it's ugly, but I'm too lazy to do it that way. But, you're right, you could just as well do it that way. One suggestion: treat the vars in LanguageStrings_XX as private and use a function to access them instead. Truly OO.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I was editing my response and missed your reply. Just to requote my edit..
Actually, I can't do that. All my crappy text editors either can't display Chinese characters (actually a font-mixing problem) or attach a BOM... and you all know about those strange headers already sent errors in Unicode mode.
Well, actually, I just screw OO here, and make $lang a global variable. I know it's ugly, but I'm too lazy to do it that way. But, you're right, you could just as well do it that way. One suggestion: treat the vars in LanguageStrings_XX as private and use a function to access them instead. Truly OO.
Haha. Well, since internationalization should be a View problem, it shouldn't be too hard to do that... You're right about the function thing... but the whole script that runs the site was originally a quick PHP hack to get the same header/footer on multiple pages: I didn't expect there to be a need for internationalization. ;) (actually I should have...) Anyway, I'll OOPize it before it's too late. :P
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Burrito wrote: Is there a language selector somewhere?
There are two hieroglyphs in the top right corner of the page, they are linked to /ch/ version
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Not Found

The requested URL /taijiclub/en/Main_Page was not found on this server.
Apache/2.0.52 (Win32) PHP/4.3.10 Server at localhost Port 80
:?:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Jcart wrote:
Not Found

The requested URL /taijiclub/en/Main_Page was not found on this server.
Apache/2.0.52 (Win32) PHP/4.3.10 Server at localhost Port 80
:?:
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

There are two hieroglyphs in the top right corner of the page, they are linked to /ch/ version
They're not hieroglyphs! :P 中文 stands for Chinese. Perhaps making it more obvious is needed?
Jcart wrote::?:
You're using the localhost link. Refresh the page.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Ambush Commander wrote:They're not hieroglyphs! :P
I always thought Chinese was ideographic script.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Weirdan wrote:I always thought Chinese was ideographic script.
Well, according to Wikipedia, they're called logograms because they represent a meaningful unit of language. I wouldn't call it pictorial at all.
Post Reply