Codeigniter i18n issue with the default controller and the non-default language - php

First of all I want to thank you all for reading and apologize if the question has already been answered and I couldn't find it and for my bad english. That said, the issue:
I'm having trouble with an application I'm working on. I'm pretty new in codeigniter and the i18n internationalization. I want to know why the following is happening and how can I manage to fix it (I'm not just asking for 'teh codez'):
Codeigniter has this behavior when I enter some url:
if i enter: it redirects to:
site.com site.com/default_language/default_controller
site.com/default_language site.com/default_language (and loads the default controller)
site.com/language site.com/language (and loads the default controller)
Want I want to do is to change that behaviour to:
if i enter: it redirects to:
site.com site.com/default_language/default_controller
site.com/any_language site.com/any_language/default_controller
My languages in MY_Lang.php are:
$languages = array(
'es' => 'spanish',
'en' => 'english'
);
And my routes.php:
$route['default_controller'] = "cover";
$route['^(es|en)/(.+)$'] = "$2";
$route['^(es|en)$'] = $route['default_controller'];
Please let me know if you need another piece of code.
Thanks and greetings from Argentina!

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';

retrieve the URL for a different language of the current page in prestashop

Good day all.
I'm developing a simple module for prestashop, the idea is to be able to setup the hreflang thing in the backoffice, and inject the code in the header of all the pages. I'm actually struck at this point:
let say I'm on a page which URL is:
http://www.server.com/en/content/8-quality
from here, I want to retrieve the URL of the same page, let's say in italian:
http://www.server.com/it/content/8-qualita
is there a way to do it without try to search this on the database? I mean, this should be work for cms pages, products, categories and so on, I would like a way to ask Prestashop:
which is the URL of the current page in a given langage?
thanks in advance.
Assuming the page you want is a cms one, in the Link.php class, you have the following function :
public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null)
Juste call it with the good lang id and it's done. You can call it from smarty with
{$link->getCMSLink('quality', null, false, $id_lang)}

Cakephp routed url and pagination issue

I Have a problem with my cakephp url routing . I've found some questions and answers in Stackoverflow, but nothing solved my issue. Please Don't close this question or marked as duplicate . My case is genuine.
Using Cakephp 1.3.11
My router code is below
Router::connect('/search/*', array('controller' => 'searches', 'action' => 'index'));
My URL will look like this
http://192.168.0.110/myproject/search/operational_area:1
But , when I looking forward to second page , it will shaped to below
http://192.168.0.110/myproject/searches/index/page:2/operational_area:1
I don't want the searches/index , but search should be there with params
My paginator options
$paginator->options = array(
'url'=>array(
'controller'=>'searches',
'action'=>'index',
'operational_area'=>$this->params['named']['operational_area']
)
);
I've done all possible things in my code , I followed some snippets from SO, But nothing helped me . The problem still persists. Anybody could came across this issue would be great.
Thanks in advance

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

SugarCRM - How to set the default homepage for all users

I am using SugarCRM Version 5.2.0k (Build 5837). I would like to be able to set a default home page (with dashlets I've created myself) that will be the same for all users, can anyone advice on best way to do this?
Thanks in advance for your help
I'd like to know how to do this too... see here for some ideas, but it's clear that it's not a supported feature.
I wonder if you can write a module that installs a hook for post user creation (assuming that this hook is provided) and then populate the appropriate part of the user preferences table when the hook is invoked. Of course, your module will probably break with each upgrade of SurgarCRM, so this might be more trouble than it i worth.
Edit:
I had a look at the Dash Manager module that is referenced in the thread I linked to above. It's approach is to copy the preferences of the admin user to all other users when the administrator clicks a link in the admin page. So, the admin user is used as a sort of template for other users. Rudimentary solution, but not a bad start - using a template user and treating the preferences (as stored in the DB table) as opaque seems like the way to go.
It's quite easy to do it.
I have done it in SugarCRM 6.5.23.
Here I have mentioned steps to do it:
Just copy sugarcrm_root/modules/Home/index.php and paste it in SugarCRM_root/custom/modules/Home/index.php.
Now you can customize it's behavior as you want.
You can remove default dashlets and add your own dashlets by creating one file at SugarCRM_root/custom/modules/Home/dashlets.php and add this code in it:
<?php
unset($defaultDashlets);
$defaultDashlets = array(
'CustomDashlet' => 'ModuleName',
'UpcomingAppointmentsDashlet' => 'Meetings', //Example
);
Once you do this thing still you have 3 dashlets left in your hook code you can remove it if it's needed code for that hook is like this:
$dashlets[create_guid()] = array(
'className' => 'iFrameDashlet',
'module' => 'Home',
'forceColumn' => 0,
'fileLocation' => $dashletsFiles['iFrameDashlet']['file'],
'options' => array('titleLabel' => 'LBL_DASHLET_DISCOVER_SUGAR_PRO',
'url' => '...',
'height' => 315,
));
Hope this will help you. :)

Categories