Page 1 of 2
Internationalization
Posted: Sun Nov 27, 2005 4:17 pm
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...
Posted: Sun Nov 27, 2005 4:24 pm
by Burrito
umm....your localhost isn't my localhost

Posted: Sun Nov 27, 2005 4:26 pm
by Ambush Commander
Fixed.

Re: Internationalization
Posted: Sun Nov 27, 2005 4:28 pm
by Weirdan
Oh, can we?

Posted: Sun Nov 27, 2005 4:35 pm
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?
Posted: Sun Nov 27, 2005 4:37 pm
by foobar
Weirdan wrote:
Oh, can we?

Ambush Commander wrote:Fixed.

Smartypants...
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.
Posted: Sun Nov 27, 2005 4:40 pm
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.
Posted: Sun Nov 27, 2005 4:43 pm
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.
Posted: Sun Nov 27, 2005 4:46 pm
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.

Posted: Sun Nov 27, 2005 4:53 pm
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
Posted: Sun Nov 27, 2005 4:53 pm
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

Posted: Sun Nov 27, 2005 4:55 pm
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

Posted: Sun Nov 27, 2005 4:56 pm
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!

中文 stands for Chinese. Perhaps making it more obvious is needed?
Jcart wrote:
You're using the localhost link. Refresh the page.
Posted: Sun Nov 27, 2005 5:09 pm
by Weirdan
Ambush Commander wrote:They're not hieroglyphs!
I always thought Chinese was ideographic script.
Posted: Sun Nov 27, 2005 5:16 pm
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.