Zend i18n Translator. How to set additional file with translation


#1

Hello!
Can you help me.

I want to use different translations files for different views.
I have registered the translator in module.config.php

'service_manager' => [
    'factories' => [
        'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
    ],
],
'translator' => [
    'locale' => 'en_US',
    'translation_file_patterns' => [
        [
            'type'     => 'phpArray',
            'base_dir' => __DIR__ . '/../language',
            'pattern'  => '%s.php',
        ],
    ],
],

My general translated files uk_UA, ru_RU are located in /module/Application/language/…
But I don’t want put all translation pares into one file.
I’ve created additional files in directories with path looks like my url.
In method $translator->translate($message, $textDomain, $local), maybe I can use $textDomain, that set another location for my translation file?
Or You know other solutions?


#2

Please look at the name of the config key: translation_file_patterns – the last letter “s” means plural. :wink:
You can add more than one sub-array. And if your application has multiple modules, you can add different translation file pattern(s) to each module configuration. The configuration will be merged at the end.


#3

Oh, I’ve understood.
Thank you a lot.