laasti/

symfony-translation-provider

一个用于 Symfony 译文组件的 league/container v2 服务提供者。

v2.0.1 2016-04-21 02:19 UTC

This package is auto-updated.

Last update: 2024-09-20 23:33:58 UTC


README

一个用于 Symfony 译文组件的 league/container v2 服务提供者。

安装

composer require laasti/symfony-translation-provider

用法

$container = new League\Container\Container;
$container->addServiceProvider('Laasti\SymfonyTranslationProvider\SymfonyTranslationProvider');

$container->add('config.translation', [
    //Two-letter or four-letter locales are accepted
    'locale' => 'en',
    //When a message is not found in the locale, look in those too
    'fallback_locales' => ['en'],
    'message_selector_class' => 'Symfony\Component\Translation\MessageSelector',
    //Symfony's package offers many different loaders
    'loaders' => [
        'array' => 'Symfony\Component\Translation\Loader\ArrayLoader',
        'json' => 'Symfony\Component\Translation\Loader\JsonFileLoader'
    ],
    'resources' => [
        'en' => [
            //The first item is the loader to use, the second the resource the loader will use
            ['array', ['hello_world' => 'Hello']]
            //The third item in array is the resource's domain
            //Sseful to namespace messages, defaults to messages
            ['json', 'my-json-file.json', 'forms']
        ]
    ],
]);

$translator = $container->get('Symfony\Component\Translation\Translator');

$translator->trans('hello_world); //returns "Hello"

贡献

  1. 复制它!
  2. 创建您的功能分支:git checkout -b my-new-feature
  3. 提交您的更改:git commit -am '添加一些功能'
  4. 推送到分支:git push origin my-new-feature
  5. 提交 pull request :D

历史

查看 Github 的发行版或标签

致谢

作者:Sonia Marquette (@nebulousGirl)

许可

在 MIT 许可证下发布。请参阅 LICENSE.txt 文件。