Quantcast

Translated segments

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Translated segments

Fernando
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
[hidden email]



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Translated segments

umpirsky
Never managed to do this, waiting for the answer.

Regards,
Saša Stamenković


On Sat, Dec 18, 2010 at 8:36 PM, Fernando Morgenstern <
[hidden email]> 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
> [hidden email]
>
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Translated segments

umpirsky
Looks like nobody knows the answer :(

Regards,
Saša Stamenković


On Sun, Dec 19, 2010 at 1:05 AM, Саша Стаменковић <[hidden email]>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 <
> [hidden email]> 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
>> [hidden email]
>>
>>
>>
>>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Translated segments

Fernando
Yes, another example of a ZF feature that people don't use because the documentation is bad :)

Well, as i did so many times with ZF, will have to dig into the code and try to find how it works.

I will post here if i find anything about it.

Regards,

Fernando Morgenstern
[hidden email]



Em 21/12/2010, às 05:16, Саша Стаменковић escreveu:

> Looks like nobody knows the answer :(
>
> Regards,
> Saša Stamenković
>
>
> On Sun, Dec 19, 2010 at 1:05 AM, Саша Стаменковић <[hidden email]> 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 <[hidden email]> 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
> [hidden email]
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Translated segments

Kaj Ström
In reply to this post by umpirsky
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, Саша Стаменковић<[hidden email]>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<
>> [hidden email]>  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
>>> [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Translated segments

Fernando
Hello,

Thank you for your sample code. It was really helpful and i was finally able to get it working here.

Best Regards,

Fernando Morgenstern
[hidden email]



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, Саша Стаменковић<[hidden email]>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<
>>> [hidden email]>  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
>>>> [hidden email]

Loading...