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

Reply via email to