Re: Language class for PEAR?
| From: | Stig S. Bakken | Date: | Fri, 08 Feb 2002 18:57:09 +0000 |
| Subject: | Re: Language class for PEAR? | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-4507@lists.php.net to get a copy of this message | ||
I think "I18N" would be a better name for such a class, that would give
room for more locale stuff too (currency, number/date format, etc.)
- Stig
On Fri, 8 Feb 2002, Wolfram Kriesing wrote:
> is there any interest in some language functionality for PEAR?
> i know there is gettext, but this is a different solution (as far as
> i can say with my knowledge about gettext)
>
> examples in action :-)
> http://wolfram.kriesing.de/programming/index.php#SimpleTemplate
> and source code:
> http://wolfram.kriesing.de/programming/index.php#Language
>
> What do those classes provide?
>
> * Language_Common *
> Until now this class provides the method 'get' which can be used to
> determine the language of a given string. It works quite good on
> longer strings, where it just looks for commonly used words,
> like in english: 'the','it','this', etc. and returns the 2-letter
>
> iso-compliant language string.
>
> * Language_Translate *
> 1. Provides functionality to translate strings.
> Where the main idea was not to only pass a string to a method, which
> then translates it, though it does that too. The actual intention was
> to pass i.e. a Markup-file (HTML/XML) which will be translated.
> 2. While only those strings will be translated that are not Markup.
> I.e. <name></name> is a markup string and doesnt need to be
> translated, but i.e. in HTML: <a href="">name</a> or <input
> value="save"> the strings 'name' and 'save' will be
> translated.
> This is useful i.e. compiling template engines, which only need to
> translate a file once, save the compiled template in the cache
> directory under a name like: file.en.php, with the language in the
> name and the translation will not take up processing time again.
> 3. Another important thing when designing this class was that it can
> also translate dynamic strings, like:
> "Welcome $USERNAME to $APPLICATION_NAME!",
> where the order of those variables might also be different in another
> language, i.e. into German you may translate it as:
> "Willkommen zu $APPLICATION_NAME, $USERNAME!".
> This is done here by using simple regular expressions (pieces). The
> example would be saved as this, if the "source language" is english:
> english: "Welcome (.*) to (.*)!"
> german: "Willkommen $2, $1!"
> This way any language, containing dymamically generated content can
> be translated easily.
>
> So here is a short description of the methods and what they do:
> 'simpleTranslate'
> Tries to translate a given string, but only exactly the string as it
> is in the DB.
> 'translate'
> Tries to translate a given string, also trying using the regexp's
> which might be in the DB.
> 'getAll'
> Returns the DB content for the source and the destination language
> given as paramter $lang.
> 'translateMarkUpString'
> Translates all the strings that match any of the "source-language"
> string. The input to this method is mostly an XML/HTML-file (as a
> string), and it is filtered so only real text is translated, at least
> it tries it as good as it can :-).
>
> Where DB, for now, is the only resource to read strings and their
> translations from, but this can be extended to use gettext resources,
> XML, any translation software or whatever.
>
>
> If gettext is capable of all that, then we can maybe think about a
> wrapper class, or simply toss it :-)
>
>