| « PHP Session management - The middle of a month is wrapped... ...yes wrappers again ! | Hide .svn files on a samba share » |
Wrap the wrapper that is already wrapped in a wrapper... huh ???
OS, Linux, Fedora, HTML, PHP Add commentsLink: http://www.php.net/gettext
I always wondered if that is wise ?
I know wrappers are good but to what extent ?
What if I wrap a wrapper ! Will that be good ?
What if someone will wrap my wrapper in another wrapper ? Isn't that too much overhead ?
Why would anyone make a wrapper... let's say to wrap the gettext extension from PHP ?
Linux itself is translated with gettext. (More at www.gnu.org/software/gettext/)
PHP has support for gettext starting from version 3... yes it's 3 not a typo !
Follow up:
If you want multilingual interface all you need to write is:
<?php
// Load RO locale
setlocale(LC_ALL, 'ro_RO.utf8');
bindtextdomain('messages', 'Locales/');
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
echo _('Username:') . ' <input type="text" name="username">';
echo _('Password:') . ' <input type="password" name="password">';
echo '<input type="submit" value="' . _('Login') . '">';
?>
So all a programmer needs to do is wrap all strings in '_()'... hmmmmmm wrapping again...
The above will output:
Nume utilizator: [input field]
Parola: [input field]
[Autentificare]
If you change the line "setlocale(LC_ALL, 'ro_RO.utf8')" into "setlocale(LC_ALL, 'en_US.utf8')" you will get:
Username: [input field] Password: [input field] [Login]
Of course there is a problem with HTML files. But there is a plugin for Smarty.
Of course you will need to write a small piece of code if you want your client to translate it's own app...
But why the need to wrap a simple call ?
Please look at it:
<?php echo _('Translate me !'); ?>
It's so simple!... isn't it ?
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
Recent comments