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
Related
I want to use #dates or #calendars to get a list of the elapsed months of the current year. This can be achieved using ${#dates.monthName(date)} and a bit of logic, but the name of the months comes in english, and I need it in spanish.
Is there a way to tell thymeleaf to use one locale or another? I've read it uses the standard Date and Calendar from Java, so maybe some sort of application settings for this classes in spring would work?
You've to use the method monthName(Object target, Locale locale) of Thymeleaf DateUtils.
I think something like this should work:
${T(org.thymeleaf.util.DateUtils).monthName(#dates.createNow(), #locale.getDefault())}
I have create files for english and german language statically in laravel rscources/lang/en and resources/lang/de folders. i want to change the string of particular lang key using my controller. how i can do ??
Example in resources/lang/en/custom.php
'my_key' => 'My key'
Example in blade:
__('custom.my_key')
or
#lang('custom.my_key')
I am using Laravel 5.2 with Carbon and I trying to get dates in locale format. I mean if I have the date 2015-12-31 in the database, I want it to be printed as 12/31/2015 or 31/12/2015 depends on the user locale.
In the User model I have an attribute locale that presents the user locale. But I don't know who to make it works. I know that Laravel using Carbon for dates, but in the Carbon class I see that the format Y-m-d is hard coded.
I still need the dates will be saved in format Y-m-d and only the presentation will depends on the User->locale attribute.
So how can I achieve that behavior? Is there any way to do that with Carbon itself?
I have solution for you.
Override getAttribute method in your model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use DateFormatting;
protected $dates = [
'finished_at',
// other field names that you need to format
];
public function getAttribute($key)
{
if ( array_key_exists( $key, $this->getDates() ) ) {
// here you can format your date
}
return parent::getAttribute($key);
}
}
after all you can access to this fields as usual(using magic __get())
$model->finished_at;
There is a way to do this using Carbon but it seems like it's really going to vary according to the specs of your server and what not. From reading, it seems like locale packages aren't always consistent. Use locale -a on your production server terminal to check which supported locales you have installed. If you need to install one, use sudo locale-gen <NEW LOCALE>.
But once you have your locale strings sorted out, it seems that you can say
$date = new Carbon;
setlocale('en_GB');
echo $date->formatLocalized('%x'); // '16/06/16'
I derived the %x modifier from the strftime() function, it specifies the format to be "the preferred date representation based on locale, without the time" according to the php manual
Do you know of any way to check the current time in Joomla considering the selected time zone in global configuration?
I have been looking in administrator settings but did not see any single word about the current time.
You can use the following code:
$date = new DateTime();
$config = JFactory::getConfig();
$date->setTimezone(new DateTimeZone($config->get('offset')));
This does two things. The first line creates a DateTimeobject based on the current server time and timezone. The following two lines get Joomla's global configuration and change the timezone of out date object to that timezone.
You can then format the date to whatever format you like by calling $date->format('Y-m-d H:i:s');. You can replace the format specifier by whatever you need, a reference of possible formatting options can be found here: http://www.php.net/manual/de/function.date.php
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.