By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

gettext vs custom ways

P: n/a
Hi. Does anyone here have experience with PHP gettext functions? I'd
like to know how they work better. Also, is gettext more efficient
than serializing the language strings into language files and
unserializing them at each request?

I found this on Google saying that some guy sped up gettext, but I
have no idea how fast it was in the first place:
http://savannah.nongnu.org/forum/for...?forum_id=3648

I was planning to just unserialize the appropriate language file at
each page request and then use the strings kind of like phpBB does
(language strings are assigned to constants and the needed strings are
assigned to the template engine per-page). It seems to me that this
would be easier to deal with than using _() and an English string to
encode every string before sending it to the template engine.

-Mike PII

May 11 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On May 11, 1:02 am, Mike P2 <sumguyovrt...@gmail.comwrote:
Hi. Does anyone here have experience with PHP gettext functions? I'd
like to know how they work better. Also, is gettext more efficient
than serializing the language strings into language files and
unserializing them at each request?

I found this on Google saying that some guy sped up gettext, but I
have no idea how fast it was in the first place:http://savannah.nongnu.org/forum/for...?forum_id=3648

I was planning to just unserialize the appropriate language file at
each page request and then use the strings kind of like phpBB does
(language strings are assigned to constants and the needed strings are
assigned to the template engine per-page). It seems to me that this
would be easier to deal with than using _() and an English string to
encode every string before sending it to the template engine.

-Mike PII
I personally don't use _() because of that, although it doesn look
great, I just use the phpmyadmin way (which has a good lang detect
script) - as you suggest,

obtain user language preference (auto/deliberate choice via post/
cookie)
set it app wide in session
use it in html files, paths and so on
select one of a number of predefined language php files
---en--
$_LANG['please_login'] = 'Please Login'
$_LANG['username'] = 'username';
....

---de---
#allow string to be inserted where appropriate
$_LANG['user_already_exists'] = 'Der Benutzer %s existiert bereits!';

and so on
all files have names such as en_GB-utf-8.php
and are properly encoded - I just stick to utf8.

PhpMyAdmin or another large internationalised app can provide many
translations for you already.

Allow your users to help with translation through http://www.translingo.org,
or using the firefox addon "phplangeditor" and others....

as you say _('heres something that needs to be translated') seems
strange to me as well because although it certainly makes the code
readable, so do well chosen variable names.
I would be grateful for your thoughts should you change your mind

May 11 '07 #2

P: n/a
On May 10, 9:10 pm, shimmyshack <matt.fa...@gmail.comwrote:
Allow your users to help with translation throughhttp://www.translingo.org,
or using the firefox addon "phplangeditor" and others....

as you say _('heres something that needs to be translated') seems
strange to me as well because although it certainly makes the code
readable, so do well chosen variable names.
I would be grateful for your thoughts should you change your mind
Hey, that's a cool extension. But how does translingo work? What I was
planning to do is create a page where my multilingual users can help
out by translating a list of strings (anyone who wants to help out --
I don't know every language I will support and I don't completely
trust online translation websites to make good translations) through
their web browser and a PHP script, and I can accept that string as
the translation if others look at it and agree and I try bringing it
back to English with an online translator. This might be a waste of
time if translingo does something like that anyway. I can't find much
description of how it works on the translingo website.

Also, although I see that large multilingual applications include()
files that set a bunch of array indexes or constants, I was
considering (and benchmarking) the possibility of just serialize()ing
a language array and unserialize()ing it back when needed if it might
be faster. Would it take longer to parse the PHP code and load that (I
do have Zend optimizer running) each page load like phpMyAdmin does or
to file_get_contents() and unserialize()? Benchmarking suggests to me
that unserializing would be much faster, but I'm wondering if this is
strange and I am doing something wrong.

-Mike PII

May 11 '07 #3

P: n/a
..oO(shimmyshack)
>On May 11, 1:02 am, Mike P2 <sumguyovrt...@gmail.comwrote:
>Hi. Does anyone here have experience with PHP gettext functions? I'd
like to know how they work better. Also, is gettext more efficient
than serializing the language strings into language files and
unserializing them at each request?
I've used gettext a while ago, but can't really compare it with other
methods. All I can say is that it worked well and made it quite easy to
extract all translatable strings from the source code to create the
message files.
>I personally don't use _() because of that, although it doesn look
great, I just use the phpmyadmin way (which has a good lang detect
script) - as you suggest,
[...]

---de---
#allow string to be inserted where appropriate
$_LANG['user_already_exists'] = 'Der Benutzer %s existiert bereits!';

and so on
all files have names such as en_GB-utf-8.php
and are properly encoded - I just stick to utf8.
gettext also works very well with UTF-8, you can even use it in the
message IDs.
>as you say _('heres something that needs to be translated') seems
strange to me as well because although it certainly makes the code
readable, so do well chosen variable names.
Given the example above that would be something like

printf($_LANG['user_already_exists'], $userName);

or

printf(_('Der Benutzer %s existiert bereits!'), $userName);

I prefer the second one. For me it's easier to read and easier to modify
if necessary.

Micha
May 11 '07 #4

P: n/a
To be honest, I'm not really worried about how easy the code is to
read. I'd be using RoR in that case. I want speed. What I care about
most is what method will be the most efficient.

Of coarse I'd prefer code readability of things like XML event-based
parsing vs object-based access, because the first is absolute
spaghetti code sometimes, but one line that is slightly different
doesn't bother me.

-Mike PII

May 11 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.