Thank you for your sample code. It was really helpful and i was finally able to get it working here.
Best Regards,
Fernando Morgenstern
contato@fernandomarcelo.com
Em 21/12/2010, às 11:25, Kaj Ström escreveu:
> Hello!
>
> I have made one project with URL -translation and I have to agree that it was quite difficult to find information.
>
> I´m by no means an expert in the matter.
>
> In my project i have a _initLanguage bootstrap function, which resets the default routes. This project has no modules btw.
>
> Code:
>
> $ctrl = $this->getResource("FrontController");
>
> $router = $ctrl->getRouter();
> $router->setGlobalParam("lang", "en");
>
>
> $route = new Zend_Controller_Router_Route(
> ':lang/:@controller/:@action/*',
> array(
> 'lang' => ":lang",
> 'controller' => 'index',
> 'action' => 'index'
> )
> );
>
> $router->addRoute("default", $route);
>
> Code end.
>
> So i override the default route with my new route that has translation. This sets up the needed route.
>
> In addition i have a front controller plugin that loads the actual translated texts in its routeStartUp() method.
>
> Code:
>
> $frontController = Zend_Controller_Front::getInstance();
> $router = $frontController->getRouter();
>
> $router->setGlobalParam("lang", $activeLang);
>
>
> if($urlLangExists){
> $urlTranslate = new Zend_Translate(
> "array",
> APPLICATION_PATH."/languages/url_". $activeLang .".php", $activeLang
> );
>
> foreach($langs as $lang){
> $lang = trim($lang);
> $urlTranslate->addTranslation(APPLICATION_PATH."/languages/url_$lang.php", "$lang");
> }
> }
> else{
> $urlTranslate = new Zend_Translate(
> "array",
> array(), $activeLang);
> }
>
> $urlTranslate->setLocale($activeLang);
>
> Zend_Controller_Router_Route::setDefaultTranslator($urlTranslate);
>
> Code end.
>
> So the actual translations are held in arrays that the Zend_Translate handles loads.
>
> As I said earlier i have no module part in the URL, but i presume you can handle it similarly to the :lang my version uses to change the language of the site and URL.
>
> Hope this helps!
>
> Regards,
> Kaj Ström
>
> 21.12.2010 9:16, Саша Стаменковић kirjoitti:
>> Looks like nobody knows the answer :(
>>
>> Regards,
>> Saša Stamenković
>>
>>
>> On Sun, Dec 19, 2010 at 1:05 AM, Саша Стаменковић<umpirsky@gmail.com>wrote:
>>
>>> Never managed to do this, waiting for the answer.
>>>
>>> Regards,
>>> Saša Stamenković
>>>
>>>
>>>
>>> On Sat, Dec 18, 2010 at 8:36 PM, Fernando Morgenstern<
>>> contato@fernandomarcelo.com> wrote:
>>>
>>>> Hello,
>>>>
>>>> I am trying to get my urls translated but unfortunately the examples at
>>>> the manual are not working to me.
>>>>
>>>> I was wondering if anyone here knows how to translate all urls, except the
>>>> module part? Adding routes for each controller is not an option to me,
>>>> because of the high number of routes.
>>>>
>>>> From what i understood, i have to remove the default route and add a new
>>>> one, with translation support ( @ ), is that correct?
>>>>
>>>> Please, if you have any examples that works, could you point out an url
>>>> where i can check?
>>>>
>>>> Regards,
>>>>
>>>> Fernando Morgenstern
>>>> contato@fernandomarcelo.com
没有评论:
发表评论