[Solar-talk] Locale files

Rodrigo Moraes rodrigo.moraes at gmail.com
Fri Dec 21 12:15:21 CST 2007


Hello, we are back!

Let me resurrect this thread. :)

The initial problem was how to make locale files more manageable, and
we kind-of agreed that it would be good if we could have all locale
keys in one single file. So I made a locale class that works with
adapters:

    http://tipos.googlecode.com/svn/trunk/lib/tipos/Tipos/Locale.php
    http://tipos.googlecode.com/svn/trunk/lib/tipos/Tipos/Locale/Adapter.php

The default adapter works exactly as current Solar_Locale:

    http://tipos.googlecode.com/svn/trunk/lib/tipos/Tipos/Locale/Adapter/Array.php

Now we can have an adapter that reads locales from an unique file,
like this one (it has a *terrible* name, sorry :):

    http://tipos.googlecode.com/svn/trunk/lib/tipos/Tipos/Locale/Adapter/OneArray.php

I made a quick script that converts existing locale files from
multiple vendors into one single array. The array format is simple:

<?php
return array(
   // Solar
   'Solar' => array(
       'FORMAT_LANGUAGE' => 'Português',
       'FORMAT_COUNTRY' => 'Brasil',
       ...
   ),
   // Solar_App_Bookmarks
   'Solar_App_Bookmarks' => array(
       'ACTION_ADD' => 'Novo bookmark.',
       ...
   ),
   ...
);
?>

It works very fine; and to test it just change the 'locale_class' key
in Solar configuration.

thoughts? :)

-- rodrigo


On Aug 16, 2007 12:09 PM, Antti Holvikari wrote:
> Hi All!
>
> Im starting the locale discussion here which we already started on #solarphp.
>
> Ok so, the problem with the current locale  implementation is that
> it's a living hell trying to maintain all the locale files. They're
> everywhere and you don't know if and what is missing from every file.
>
> I would want to keep the keys grouped by class, but still be able to
> define keys in one file or in as many files as I want. For example,
> the files could be separated by "packages", as in pear packages. Since
> Solar is distributed in one package, there really isn't a need to
> separate locales to many files.
>
> So what would the file look like? I'm thinking something along these lines:
>
> array(
>     'Solar_Example' => array(
>         'KEY' => 'Val',
>     ),
>     'Solar_Example_Other' => array(
>         'KEY' => 'Val',
>     ),
> )
>
> That could be in, say, Solar/Locale/en_US.php. Now, I could still have
> a locale dir in my own package 'Vendor/App/Sunny/Locale', which would
> be merged to the master Solar locale array.
>
> Now, how should we implement the locale file searching and merging?
> Forcibly search under every parent class? :-(



More information about the Solar-talk mailing list