Re: languages and PHP



Per Jessen wrote:
David Christopher Zentgraf wrote:

Your biggest problem will be if you accept any kind of user input
which could be in any kind of language.
Depending on your server configuration you'll probably have some
serious cleaning and filtering to do.
I often have to employ this line for example:
foreach (array_keys($_POST) as $key) $clean[$key] =
mb_convert_encoding($_POST[$key], "UTF-8");

Trying to make sure that you'll receive UTF-8 helps as well:
<form action="form.php" method="post" enctype="multipart/form-data"
accept-charset="utf-8">

I work almost exclusively in UTF-8 (language irrelevant), but I've never
had to do any of the above. The mb_convert_encoding() from UTF-8 to
UTF-8 doesn't seem to make much sense?

I agree. Provided you HTML is dished out with UTF-8 in the doctype
definiton etc. then all forms are automatically sent in UTF-8....

Also for multilingual content (labels etc.) in PHP have a look at the
gettext extension. This will let you code in your default language with
a minimal wrapper and translate to other languages with catalog files.

Be careful about breaking strings tho' as the xgettext crawler file will
not be able to extract strings properly. Also do not use variable
substituion but rather use printf/sprintf e.g.:
$var = sprintf(_('Here is %d example of a translatable string.'), 1);

That way the string you translate is nice and standard.(here _() is the
name of the gettext function which is quite common).

You may leave this up to your templating engine (e.g. no labels in
code), so it may not matter.

Also if you are writing modular code, ensure you think about the gettext
domains first and you'll probably want to pass the domain in with
*every* string in your system to ensure it's modular design (e.g. each
module has it's own gettext domain). If you want a good example of
modular gettext usage, I'd recommend looking at the source of gallery2.

HTH.

Col
.



Relevant Pages

  • Re: GNU gettext
    ... The gettext documentation explains how the keys work. ... translation files, or that you'd need to write a small utility to help ... gettext was desined for plain C, the keys are C strings ... as a developer you have no clue what every language ...
    (microsoft.public.dotnet.languages.csharp)
  • gettext vs custom ways
    ... Does anyone here have experience with PHP gettext functions? ... than serializing the language strings into language files and ... each page request and then use the strings kind of like phpBB does ... encode every string before sending it to the template engine. ...
    (comp.lang.php)
  • Re: Multi(dual) language support in roguelikes.
    ... speakers with maybe a second language on top of it. ... I don't know how gettext handles the proper declension/conjugation ... of verbs in dynamically built strings. ... The hard, hard, HARD, part of translation isn't the dynamic verb ...
    (rec.games.roguelike.development)
  • Re: Internationalization of webpages with php ... best practices?
    ... Other options are using gettext yourself or simply having files for ... each language with different strings values defined in them. ... webpages in php? ...
    (php.general)
  • Re: add support for other languages
    ... language DLLs or a single DLL with multiple language support, ... Just compile in Unicode ... You can create a hand-edited resource that contains Unicode strings, but you have to do it ... I don't know where is the language support comes into ...
    (microsoft.public.vc.mfc)