Hi !
I am trying to localize my Cake 3.3 app to portuguese “Brasil”.
I’ve downloaded this and saved in C:\Apache24\htdocs\cake3\src\Locale\pt_BR
I’ve changed the defaultLocale in C:\Apache24\htdocs\cake3\config\app.php to ‘defaultLocale’ => env(‘APP_DEFAULT_LOCALE’, ‘pt_BR’)
But Cake is still in english and I have tried to change the date format in C:\Apache24\htdocs\cake3\config\bootstrap.php with:
// Configure a custom datetime format parser format.
Type::build('date')
->useLocaleParser()
->setLocaleFormat('dd/MM/yyyy');
Type::build('datetime')
->useLocaleParser()
->setLocaleFormat('dd/MM/yyyy HH:mm:ss');
Type::build('timestamp')
->useLocaleParser()
->setLocaleFormat('dd/MM/yyyy HH:mm:ss');
Add ‘type’ => ‘text’ at dataEntrega input, when the date is loaded to the value it comes locale formated dd/mm/yyyy, and when you save the date its formated to the database format. In addition you can use a js calendar plugin for a nice datepick
for me, its better way …
// in bootstrap
date_default_timezone_set(‘America/Sao_Paulo’);
setlocale(LC_ALL, ‘pt_BR’, ‘pt_BR.utf-8’, ‘pt_BR.utf-8’, ‘portuguese’);
/*
* Enable immutable time objects in the ORM.
*
* You can enable default locale format parsing by adding calls
* to `useLocaleParser()`. This enables the automatic conversion of
* locale specific date formats. For details see
* @link http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data
*/
/*Type::build('time')
->useImmutable();
Type::build('date')
->useImmutable();
Type::build('datetime')
->useImmutable();
Type::build('timestamp')
->useImmutable();*/
date_default_timezone_set('America/Sao_Paulo');
setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
Type::build('time')->useImmutable();
Type::build('date')->useImmutable()->useLocaleParser();
Type::build('datetime')->useImmutable()->useLocaleParser();
Type::build('timestamp')->useImmutable();
\Cake\I18n\Time::setToStringFormat('dd/MM/yyyy HH:mm:ss');
\Cake\I18n\Date::setToStringFormat('dd/MM/yyyy');
\Cake\I18n\FrozenTime::setToStringFormat('dd/MM/yyyy HH:mm:ss');
\Cake\I18n\FrozenDate::setToStringFormat('dd/MM/yyyy');
\Cake\I18n\I18n::locale('pt-BR'); // new !
Type::build('decimal')->useLocaleParser();
Type::build('float')->useLocaleParser();