Translating URLs ZendFramework - php

I have been using zend translate to translate the site content but what about the urls? How could I translate it?
Ex.:
localhost/app/contact (English)
localhost/app/contato (Portuguese)

If you are indeed using Zend Translate you should be able to use translations in your router like:
routes.someroute.route = "/:langparam/#translateme"
routes.someroute.defaults.module = public
routes.someroute.defaults.controller = page
routes.someroute.defaults.action = show
If your translation source contains 'translateme' it wil be translated, if not the router will use 'translateme' as value.

Related

Reroute with extra parameter for multi language sites in Codeigniter

In my codeigniter webapp, I'm using multi language site. Default and in english like these:
www.xxx.com (default)
www.xxx.com/en (english)
And I have a controller where I want to re-route specific calls say potato and tomato to vegie like these:
www.xxx.com/potato/param => www.xxx.com/vegie/param
www.xxx.com/tomato/param => www.xxx.com/vegie/param
So far, I have managed to reroute with default language url using like this in my route.php:
$route['potato/(.+)$'] = 'vegie/$1';
$route['tomato/(.+)$'] = 'vegie/$1';
But I doesn't work for the english site. I did like this, and not working:
$route['en/potato/(.+)$'] = 'en/vegie/$1';
$route['en/tomato/(.+)$'] = 'en/vegie/$1';
Anyone can help me for this? Thanks.
First, create new function to manage the english version, ex: function vegie_en()
then route to it
$route['en/potato/(:any)'] = 'vegie_en/$1';
I have found the problem. I have this in my route.php which makes it rerouting wrongly if there's prefix en/:
$route['en/(.+)$'] = '$1';
I moved this to the end of the route.php and it working very fine now.
I had faced same problem in my project. I fixed it by removing the 'en' and put $2 as for dynamic value.
So in your case, this will work.Please try this given below code.
$route['en/potato/(.+)$'] = 'vegie/$2';
$route['en/tomato/(.+)$'] = 'vegie/$2';

How to get a proper cms link (with pretty url) from smarty in prestashop?

If I want to link to a cms page from a template with smarty, I currently use something like this:
{$link->getPageLink('cms',null,null,'id_cms=4')}
But that is going to generate a regular url (with query string), so if I activate pretty urls (url rewrite), it won't work. I analized the Link class but I can't find a way to generate a proper rewritten url. In fact, THERE IS a simple way:
{$link->getCMSLink(4)}
BUT, taking a look into Link::getCMSLink notes, I read that using an ID instead of a CMS object is deprecated. But from a template I don't have the cms object available.
Anyone had the same problem?
I found it really by "let's try if this one works".....
In PS1.6 you can get CMS object like:
$myCMS = new CMS( YOUR_CMS_ID );
If you want to use it in tpl, you have to define it in your controller e.g.:
$this->context->smarty->assign( "myCMS", $myCMS );
This is my solution. I recently tested it for Prestashop v1.6 and v1.7
This code utilizes the method getCMSLink of the Link class. It is necessary to know the id_cms of the CMS Page, to create the object model.
$link = new Link();
$cmsPageObject = new CMS(
$id_cms,
$id_lang
);
// $cmsLink has the URL string.
$cmsLink = $link->getCMSLink(
$cmsPageObject,
null,
Configuration::get("PS_SSL_ENABLED") === "1",
$id_lang,
null,
null
);

Translating Dynamic Content in Wordpress

Is there any way I can translate dynamic content in wordpress using .po files and e or _ functions?
I have all the static content translated but I would like to have dynamic content translated as well, wp_nav_menu, site header text etc.
I'm using poedit and that doesn't let me add any extra strings into the resource file so if you know how to get around that it would be nice as well.
Recently I have been using Polylang Plugin for WordPress. It gives you plain control over the website translation, from content to menus and strings translations. Best of all: most of your work will be done through WP Admin interface instead of php code.
You will can without plugin if you know the exactly word, like that
$translate = '';
$result = 'dynamical string need to be translate';
if ( $result == 'dynamical string need to be translate' ) {
$translate = __('dynamical string need to be translate', 'plugin');
}
if ( $result == 'other dynamical string' ) {
$translate = __('other dynamical string', 'plugin');
}
echo $translate;

Zend translate URL and language switcher

I have managed to make my URL i18n compliant using Zend_Controller_Router.
Ie:
en/user/login becomes fr/utilisateur/connexion and both URLs go to the same controller/action.
The problem I am facing is the following
I have a language switcher that is displayed as follow :
Français
English
Italiano
etc.
The currently active language doesn't have an anchor tag, but all others do.
For the languages that have an anchor on them I am building the URL and I want them to be translated in their specific languages.
Currently if I am in French all the urls get builded in french, even if I set the #local key as a param in the URL view helper (tried "#locale" => 'en', "#locale" => new Zend_Locale('en'))
en/utilisateur/connexion
it/utilisateur/connexion
instead of
en/user/login
it/utente/collegamento
because the locale used while building the URL is the one that is defined application wide.
EDIT
I digged a bit deeper in my issue an I found that only the current locale add its resources loaded, which mean I can't get route in the proper language for the route to be built in the right language
My new issue is : how do I load multiple language translation resources?
(I am planning to implement cache in the far future (near release), so I might get better performances)
Hope this helps re the new issue.
"My new issue is : how do I load multiple language translation resources?"
Just a quick caveat to say I didn't write the code below, it was taken from a example app put together by the guys at Zend however it might help to have it broken down like this.
Their approach for the example app was using a csv file containing translations and using your config file (the default one in a new project being application.ini) to specify the path to all your language translation resources.
like this:
;; Languages
language.file.en = APPLICATION_PATH "/../language/en/translate.csv"
language.file.fr = APPLICATION_PATH "/../language/fr/translate.csv"
language.file.de = APPLICATION_PATH "/../language/de/translate.csv"
language.file.es = APPLICATION_PATH "/../language/es/translate.csv"
language.name.zz = Language
language.name.en = English
language.name.fr = Français
language.name.de = Deutsche
language.name.es = Español
And in each csv file, if you are using something like Excel or Open Office to create it, column A would be the original language and column B the translation.
As an example where English is the original language and a Spanish translation is required:
A B
login entrar
logout salir
You could do that for all the words/phrases you want to translate.
If a translation isn't found then the default original word is used.
Your main application bootstrap could have something like this:
protected function _initLanguage()
{
$options = $this->getOptions();
Zend_Registry::set('language',$options['language']);
$langSess = new Zend_Session_Namespace('language');
if (!isset($langSess->translate)) {
$translate = new Zend_Translate('csv', $options['language']['file']['en']);
$langSess->translate = $translate;
}
if (!isset($langSess->locale)) {
$langSess->locale = 'en';
}
Zend_Locale::setDefault($langSess->locale);
}
As the translate object is held in the session you can use it in any of your views etc using something like:
$langSess = new Zend_Session_Namespace('language');
$translate = $langSess->translate;
and:
<?php echo $translate->_('login') ?>
where you want something to be translated on selecting an alternative language. In the example above the word login would appear when English is selected and entrar when Spanish is selected.
There's loads more to Zend_Translate than this and several ways to implement it so I'm not saying this is the best way by any means.
If it helps or if I can give you more info let me know.
Cheers,
Dave

How can I easily change the text on a page using zend framework and php

What I am looking for is something where I can easily change the text on a page. I want to set it to a default value and if something is present for a specific page to change it
So it would say something like:
I like stackoverflow
But if the value of website was "reddit" it would instead say
I like reddit
So stackoverlflow would be the default, reddit would be something that is set to overwrite it.
edit:added comment
Scenario I: Domain Name based data handling
If you want to work on the basis of domain, then in Zend Framework you can work with customize routers.
Scenario II: GET/POST based input handling
Otherwise if you want to display on the basis of GET or POST input you can place something default value as
$myDynamicVar = $this->getRequest()->getParam('some_key', 'default-value');
Scenario III: subdomain based input handling
Again you will need to have your custom router for the purpose, in addition to having support of wildcard subdomain names with your hosting provider
In a definitions file:
<?php
/* site.php
* customize this file
*/
class Site
{
static public $name = "stackoverflow";
}
?>
In your page file:
<?php
/* page.php */
include_once 'site.php';
echo "I like {Site::$name}";
?>

Categories