0

i try to localize the input and output in my app to german and encounter problems with the following setup:

Installed CakePHP 3.2.1 via SSH/Composer on my hosted WebSpace.

Created a database with only one table "invoices" for testing, with columns "id", "datum" (datetime) and "amount" (decimal 10,2).

Baked with "bin/cake bake all invoices".

Checked the localization abbreviations from my web hoster via SSH with "locale -a"...

de_DE
de_DE@euro
de_DE.iso88591
de_DE.iso885915@euro
de_DE.utf8
de_DE.utf8@euro

Edited config/bootstrap.php:

ini_set('intl.default_locale', 'de_DE');

Added some php-test-output to /src/Template/Invoices/add.ctp:

<?php
    use Cake\I18n\I18n;
    use Cake\I18n\Time;
    $now = Time::now();
    echo $now->i18nFormat('dd.MM.yyyy HH:mm:ss');
    echo " +++ ";
    echo $now->i18nFormat('l, N. F Y');
?>
<nav class="large-3 medium-4 columns" id="actions-sidebar">
    <ul class="side-nav">
        <li class="heading"><?= __('Actions') ?></li>
        <li><?= $this->Html->link(__('List Invoices'), ['action' => 'index']) ?></li>
    </ul>
</nav>
<div class="invoices form large-9 medium-8 columns content">
    <?= $this->Form->create($invoice) ?>
    <fieldset>
        <legend><?= __('Add Invoice') ?></legend>
        <?php
            echo $this->Form->input('datum');
            echo $this->Form->input('betrag');
        ?>
    </fieldset>
    <?= $this->Form->button(__('Submit')) ?>
    <?= $this->Form->end() ?>
</div>

This was my php-test-output:

07.02.2016 12:42:19 +++ ,

As you can see, the first output looks like german date time format, but i had to pass the format manually, like i would do using plain php code, so where can i tell CakePHP to ALWAYS use this format for date or time fields inside the whole app?

After the "+++" i expected the following output, but there is only the comma:

Sonntag, 7. Februar 2016

Is a localized format also possible for input fields? My dropdown field 'datum' for the month still has english names and the order of the first 3 dropdown fields for the date is wrong.

I would be grateful if you can give me a hint how to get native localized german dates, numbers and currencies in CakePHP form input elements and arbitrary output data.

Thanks in advance and best regards,

TheDude

ndm
  • 59,784
  • 9
  • 71
  • 110
TheDude
  • 1
  • 1

1 Answers1

0

i18n dates are formatted using IntlDateFormatter, which uses ISO date format patterns, not the default PHP date patterns.

l is deprecated, and doesn't generate any output, N doesn't seem to be a recognized symbol at all, and it is responsible for the rest of the pattern to fail, I don't know why that is though.

Anyhow, for valid symbols, check for example

The pattern that you are looking for, is EEEE, d. MMMM Y.

ndm
  • 59,784
  • 9
  • 71
  • 110