Codeigniter calendar language problem - codeigniter

I'm trying to get the calendar in CodeIgniter to print month names in Swedish.
In config.php I have this line:
$config ['language'] = 'Swedish';
In autoload.php I have this line:
$autoload ['language'] = array ('calendar');
In my controller:
$this->lang->load('calendar', 'swedish');
So here I am trying to print the date:
<? php echo date ('d M Y', $row['pubDate']);?>
The result is as: 23 May 2011
Month names are printed in English, which is wrong, I want it in Swedish. I have calendar_lang.php in Swedish.
Any advice on how I solve this?

Codeigniter lang files are decided to "translate" only codeigniter functions, methods etc.
They do not affect default php function, like that one you are using (date).
You should look at this page and follow the links on that page.

Related

Routes laravel translation

After much testing and searching, I can not find the solution.
My problem is that I have, for example the route '/services', '/servicios' in spanish.
If my website is in english, all texts are correctly shown in english, same in spanish. But the problem is with the text links, only appear in default locale.
In routes/web.php:
Route::get(trans('rutas.servicios'), 'ServiceController#index')->name('servicios')
File lang/es/rutas.php:
return [
'servicios' => '/servicios',
];
File lang/en/rutas.php:
return [
'servicios' => '/services',
];
and link html:
#lang('menus.servicios')
My goal is to use translated urls without using laravel prefix. That is to say:
https://www.myweb.com/services ~ english
https://www.myweb.com/servicios ~ spanish
share the same Route controller.
Any help? Lot of thanks for your time!
EDIT WITH SOLUTION:
I discovered that laravel performs route mapping before selecting the language. So what I did was to set the language before this, but the session and cookies variables load after this. But I finally discovered that the cached variables satisfied my needs.
At the top of function map() of RouteServiceProvider.php:
App::setLocale(Cache::get('locale'));
To store the selected locale:
Cache::put('locale', $locale, $minutes);

URLEncode in Smarty

I wrote a Code to short my URL but have Problem during the URL encoding because the URL calls an ID with {$CWunschliste->cURLID}
{php}$short = file_get_contents('http://ur.l/api.php?url=' . urlencode({$ShopURL}/index.php?wlid={$CWunschliste->cURLID}));{/php}
{php}$url=json_decode($short,TRUE);{echo $url['short'];}{/php}
How can I rewrite the url encode to call {$CWunschliste->cURLID} ?
If you use {php} tags in Smarty templates you should place there PHP code, so you cannot use Smarty syntax. Your code should probably look like this:
{php}
$short = file_get_contents('http://ur.l/api.php?url=' . urlencode($this->getTemplateVars('ShopURL').'/index.php?wlid='.$this->getTemplateVars('CWunschliste')->cURLID));
$url=json_decode($short,TRUE);
echo $url['short'];
{/php}
However you shouldn't do it this way. You should do such things in PHP. Smarty is just for displaying views and not for getting data from remote urls or other model tasks.
In addition {php} tag is deprecated and can be used only in SmartyBC class.
EDIT
I forgot to remove { from answer ( already fixed it) but even in this case I got the following error
Using $this when not in object context
That's really strange because if you look at Smarty php tag example in this example $this is used to access Smarty object.
However the working solution would be changing $this into $template ( I have to emphasise $template is in this case not the name of Smarty object created in PHP - I've created Smarty object $smarty but in {php} tags I have to access Smarty using $template).
The following code should work for you:
{php}
$short = file_get_contents('http://ur.l/api.php?url=' . urlencode($template->getTemplateVars('ShopURL').'/index.php?wlid='.$template->getTemplateVars('CWunschliste')->cURLID));
$url=json_decode($short,TRUE);
echo $url['short'];
{/php}

Echo Joomla K2 Item Title in Main Template Using PHP

I'm trying to simply echo the title of the current k2 item I'm viewing, but the echo will not occur within the K2 template, it should show in my MAIN site template.
I tried this:
<?php echo $this->title; ?>
But that displays the FULL site title including my company name because I have it set that way in the main Joomla configuration.
I don't want the full site title that is generated for the 'title' tag in the head of the website; I just want to generate the name of the specific item I am currently viewing. This is probably pretty easy, but my PHP knowledge is limited.
I realise this is pretty old. However if you are still looking for a solution. This is not very elegant but will do what you want.
Firstly, just in case you weren't aware, you can get the article id from anywhere in by doing a JRequest:getVar('id') which will use a GET request to get the id from the URL.
$id = JRequest::getVar('id');
$id = explode(':',$id);
echo $id[0];
The reason I am exploding it is because in my site I am using aliases which if you are and you echo $id without you will see its in the form id:alias.
Using this method, you could query the database to get the name associated with that id in the k2_items table. You could create a function to do that which is else where in the templates folder then just assign it to a variable which you echo in the template. That keeps your template clean but gives you what you want.
Like I say, not a quick elegant solution but will work.

CodeIgniter translate PHP date

I have a datetime stored in mysql as timestamp.
I then format the datetime using
$newdate = date('d M Y', strtotime($this->query->datetime));
My question is how do I translate the date using codeigniter builtin lang helper?
in the application language folder add a subfolder for the language you want to translate to. In that folder make a file called date_lang.php and handle all you date translations.
$lang['datefrom'] = "dateTo";
Another option for translation of dates is to use locale.
PHP will handle the date translations for you. Set the locale globally for the user.
setlocale(LC_ALL, 'en_UK.utf8');
In my current project, we use the locale to handle money and dates. We use CI language files to handle string translations

Multiple website custom magento php code

I have 9 websites in my magento installation, which again then have multiple languages etc. like below:
US - English
US - Spanish
US - French
UK - English
FR - French
I have created a php file with custom code which exports orders of websites. And those needs to be stored in separate folders based on country.
I want to run my export file url like http://example.com/xml/export.php?website=us
But to get the orders from a particular website, I need to set the Mage:app properly for that I have used below code:
Mage::app('base_uk', 'website');
But the above code is not working, and it is always fetching the orders from US store only, which is default for Mage:app().
How can I set my code to fetch orders form a specific website?
Please help, Thanks.
For Product collections there is such a thing as ->setStoreFilter($store_id). Since each $store_id is unique for any given website (i.e. if you know the $store_id, you know the $website_id), you might use this.
Sample code:
$orders = Mage::getModel('sales/order')
->getCollection()
->addAttributeToSelect("*")
->addStoreFilter($store_id)
My two cents: run that code for all $store_ids within the desired $website_id.
Note: I did not test this, just thinking with you. Could be that this function is not available for order collections. I still think you should then try to find a function that does filter orders by $store_id, since that is the Magento way to go!

Resources