This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi, I have changed the locale config in config/app to
'timezone' => 'Asia/Jakarta',
'locale' => 'id'
But, when I trying this code,
{{ post.published_at|date('l, j F Y') }}
The date format in English. Not Indonesian language.
Am I missing something?
thanks,
Last updated
Try to use Twig extensions plugin with strftime filter:
Posted at {{ article.date | strftime('%d.%m.%Y %H:%M:%S') }}
Hello,
I have exactly the same issue, except created_at fields are correctly localized...
I know it's and old topic, but....
@didier28788 Try this code with Twig Extensions:
{{ date | localizeddate('full') }}
Works on my machine ;-)
Vojta Svoboda said:
@didier28788 Try this code with Twig Extensions:
{{ date | localizeddate('full') }}
Works on my machine ;-)
Thanks, I tried but unfortunately dates are still displayed in English...
didier28788 said:
Thanks, I tried but unfortunately dates are still displayed in English...
Same issue !!
Change locale in :
- config/app.php : No effects.
- Set
setlocale(LC_TIME, 'fr_FR')
in app.php (has suggest here) : No effects.
But the localizeddate('none', 'none', 'fr', 'Europe/Paris', 'MMM')
filter give me the good translation.
Mr Hound said:
didier28788 said:
Thanks, I tried but unfortunately dates are still displayed in English...
Same issue !!
Change locale in :
- config/app.php : No effects.
- Set
setlocale(LC_TIME, 'fr_FR')
in app.php (has suggest here) : No effects.But the
localizeddate('none', 'none', 'fr', 'Europe/Paris', 'MMM')
filter give me the good translation.
Thanks Mr Hound, but how do you display "day month year" with this syntax?
didier28788 said:
Thanks Mr Hound, but how do you display "day month year" with this syntax? Well,
According to plugin's doc localizeddate section :
format: Optional pattern to use when formatting or parsing.
Possible patterns are documented in the ICU user guide.
So to get "day month year" try : localizeddate('none', 'none', 'fr', 'Europe/Paris', 'dd MMM YYYY')
Hope this will help.
If created_at field is localized, but other fields still displayed in English, just add your fileds to the Model.
class ModelName extends Model
{
protected $dates = ['field_name'];
}
Last updated
This is how I understand this problem (struggle with it my self a lot).
The first problem is that some plugins is not programed with other countries than default in mind. For an example the Rainlab blog plugin, it use: date('Y-m-d\TH:i:sP')
(I will come back to this later in my post)
Then you get the core locale set by setlocale(LC_TIME, X ); (where X is the locale code). The core locale is the webserver value for Locale configuration, that you basically need to set on script level in php. That is not set by October CMS.
You can set it in: config/app.php For example, I needed to put: setlocale(LC_ALL, 'sv_SE.UTF-8'); (so I get Swedish)
Well, then you get one default locale for the October CMS. What if you want to dynamically change it, i.e. you have a multi language site, so you installed Rainlab translate plugin?
Then you need use the Twig extensions plugin (as proposed in the tree above). Well that plugin use Intl Locale formate, witch is an other level off locale (even an other standard). That need the server to have Intl installed and php on the server to have that configured as an extension. Luckily the intl extension is enabled by default on PHP versions 7.2, 7.3, and 7.4.
But it might not be configured with the right default locale. I had to put: intl.default_locale = "sv_SE.UTF-8" in my php.ini file
So far so good, now we get the Twig extensions to function, for our date format. Still the main problem exist, plugins not programmed for multi languages support and not even for the Intl locale that is default for the twig extension. So you need to change every date() and strftime() to your own.
To get the default locale set in config.app you need to change it to: {{ date|localizeddate('full', 'none', defaultLocale, null, 'dd MMMM, yyyy') }} ore: {{ date|localizeddate('full', 'none', "sv", null, 'dd MMMM, yyyy') }} (Swedish example)
To get it dynamically (if you have RainLab translate plugin installed): {{ date|localizeddate('full', 'none', activeLocale, null, 'dd MMMM, yyyy') }}
That is a lot of work to do! I'm working on building a plugin to set the setlocale(LC_TIME, X ) dynamically. Don't now if it is overkill, is there a better way to get date() and strftime() to function dynamically?
I am not an expert on October, Laravel ore Sympony, try to learn. This is my first post here.
Last updated
I found a solution, for the multiple locale date format. With this plugin you can configure the right php setLocale code. There is just a small bug in it for Opera and Chrome on Mac. See separate post.
Plugin: https://octobercms.com/plugin/utopigs-localize
Bug fix: https://octobercms.com/plugin/support/utopigs-localize/bug-in-opera-and-chrome-for-utf-8-character
Last updated
1-14 of 14