zendframework / zend-i18n

I18n component from Zend Framework
BSD 3-Clause "New" or "Revised" License
65 stars 49 forks source link

INI file formats won't work #64

Closed divix1988 closed 5 years ago

divix1988 commented 7 years ago

pl_PL.ini file:

[Application]
abc = translator works

Config:

'translator' => array(
    'locale' => 'pl_PL',
    'translation_file_patterns' => array(
        array(
            'type'     => 'ini',
            'base_dir' => 'data/lang',
            'pattern'  => '%s.ini',
        ),
    ),
),

Usage: (view) <?= $this->translate('abc') ?>

Error: Each INI row must be an array with message and translation

Contents of $list var from Zend\I18n\Translator\Loader\Ini.php line: 51

Array ( [Application] => Array ( [abc] => translator works )

My main question is: Why the heck does the Ini.php class expects format of 2 values in array like: Array('key', 'value'), where as the correct format is returned by IniReader like Array([key] => value) ??

Either IniReader should output correct format or Ini.php should cope with that format. Anyway the fix which I am curretly using is to put the following two lines inside foreach loop like so:

foreach ($list as $message) {
            $message[] = key($message);
            $message = array_reverse($message);

This would ensure that proper IniReader output is reformated to "proper" acceptable format of Ini.php class. Yet, I would call it a HACK, not a fix.

jbelien commented 5 years ago

I just ran into the same issue !

It's apparently impossible to use .ini files to store the translation ; or at least I didn't find a way to make it work and couldn't find documentation about this anywhere.

Is it worth create a PR ?

froschdesign commented 5 years ago

@jbelien Please check this preview: https://froschdesign.github.io/zend-documentation-showcase/translator/format-examples/#ini

jbelien commented 5 years ago

Awesome! That's exactly the documentation I was looking for! 🎉

Thanks :)

froschdesign commented 5 years ago

@jbelien Can you give me feedback if it works as described?

jbelien commented 5 years ago

Confirmed! 🍾

Both normal syntax and simple syntax work!

froschdesign commented 5 years ago

Sections like Application from the initial post are not supported. Only translation and plural are allowed.

At the moment there are no plans to change this. Maybe later, after the migration to Laminas.

I will close this issue here.


Sorry for the late response.