-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Inno,

I solved the same problem some time ago, with simply a new route (which
i will probably port to ZF in modified way some day). It works like this:

Fixed text is prepended with an @, while translatable parameters are
prepended with :@. For example:

route.about.type  = 'App_Controller_Router_Route_Translatable
route.about.route = '@imprint'

Now, the route looks for a Zend_Translate instance with the key
Zend_Translate within Zend_Registry, searches for the message-id
"imprint", translates it, and then tries to match the route.

There are also translatable parameters as said before:

route.statistics.type  = 'App_Controller_Router_Route_Translatable
route.statistics.route = '@statistics/:@timerange'

Here again, "statistics" is simply translated and matches. What the
:@timerange parameter does is the following:

When you assemble the route like this:

$urlHelper->url(array('timerange' => 'this-month'), 'statistics');

The route looks for a message with the id "this-month" and if available,
puts it into the url, else the message id itself. When matching a URL,
it replaces the translated parameter with the message id again, so you
don't have to care about it in your application itself.

For the route code, see the attached file.

Regards,
Ben
...................................
:  ___   _   ___ ___ ___ _ ___    :
: |   \ /_\ / __| _ \ _ (_)   \   :
: | |) / _ \\__ \  _/   / | |) |  :
: |___/_/:\_\___/_| |_|_\_|___/   :
:........:........................:
: Web    : http://www.dasprids.de :
: E-mail : m...@dasprids.de       :
: Jabber : jab...@dasprids.de     :
: ICQ    : 105677955              :
:........:........................:


Innocentus schrieb:
> Dear Friends,
> 
> I want to internationalize the urls of my Zend Framework-driven website.
> The url-structure should look like this (ex. about us):
> * de.domain.tld/ueber-uns/
> * en.domain.tld/about-us/
> * fr.domain.tld/sur-nous/
> The default actual locale should be set to the selected subdomain.
> 
> I have created a configuration-ini file which looks like the following:
> ---
> [...]
> ;; en.domain.tld/about-us/
> routes.doc.route = "_(about us)/"
> routes.doc.defaults.controller = aboutUs
> routes.doc.defaults.action = show
> [...]
> ---
> 
> As you can see I have tagged parts of the route with _( ). In view you
> also do this for tagging parts for i18n.
> And this is because those parts should be translated with
> Zend_Translate (gettext).
> I use poedit - and with those tagged parts poedit is able to
> automatically generate a translation-table (.po-file).
> 
> In bootstrap I fetch this ini-file (which has just been described
> above) and iterate trough the route-entries.
> I also fetch all avaiable translation-languages and also iterate
> trough them for each route-entry.
> ---
> [...]
> // ROUTING - Setup the routing (URLs) of website
> //Load routes from routing-ini:
> $routing_configuration = new Zend_Config_Ini(
>     APPLICATION_PATH . '/config/routing.ini',
>     APPLICATION_ENVIRONMENT
> );
> //Get router
> $router = $frontController->getRouter();
> //Get all available translation languages
> $translation_languages = $translate->getList();
> //Go trough the defined routes
> foreach($routing_configuration->routes as $route_name=>$route_data)
> {
>       //Go trough the available languages
>       if(count($translation_languages) > 0){
>           foreach($translation_languages as $translation_language)
>           {
>               //Translate the route and add it to the router
>                 //! - How to parse the route before adding it? -!
>                 //! - How can I name the same route for different
> language-versions? -!
>                   $router->addRoute($route_name,
>                               new
> Zend_Controller_Router_Route($route_data->_data->route,
>                                                            array('controller' 
> =>
> $route_data->_data->defaults->_data->controller,
>                                                                      'action' 
> =>
> $route_data->_data->defaults->_data->action
>                                                                       )
>                                                     )
>               );
>           }
>     }
> }
> [...]
> ---
> In each iteration the route should be parsed so that Zend_Translate
> can translate those _( ) pieces.
> - This is the first problem I have encountered:
>  How can I parse those _( )-tagged text out, translate it and
> reassemble it back into the route-string?
> 
> Then a new route will be created with the translated string.
> - And herein lies the second problem:
> Normally I define a single route named 'about_us'.
> In this case I have multiple routes in different languages for this:
> * de.domain.tld/ueber-uns/ (German version for about us)
> * en.domain.tld/about-us/ (English version for about us)
> * fr.domain.tld/sur-nous/ (French version for about us)
> They are all pointing to the same controller. (In this case it is the
> about_us-controller).
> How should I manage the route-name for multiple languages?
> 
> When I want to use a route later in the view (url-helper), I need to
> pass a route-name.
> The helper-function should fetch the correct route - depending on the
> actual locale.
> - How can I do that?
> 
> However, despite to these problems I would find it really nice to use
> different urls for different languages.
> Maybe someone could help me. Any hints will be appreciated.
> 
> Thank you for your answers.
> With best regards
> Innocentus
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmdscgACgkQ0HfT5Ws789A/1wCdElHvL64bKMXBHQP7G/Jzql9j
JyIAn1s3aJ+ZV+jtNHUNo1dLxu8G2e7G
=HArj
-----END PGP SIGNATURE-----

<<attachment: Translatable.php>>

Attachment: Translatable.php.sig
Description: PGP signature

Reply via email to