coffreo / php-translation-js-extractor-bundle

为 php-translation/symfony-bundle 包添加 JavaScript 翻译提取器

v2.1.2 2024-06-18 15:59 UTC

This package is auto-updated.

Last update: 2024-09-18 16:46:24 UTC


README

Coffreo提供

PHP from Packagist Build Status Coverage Scrutinizer Code Quality

从 JavaScript 源文件中提取翻译。

同一捆绑包也适用于 JMSTranslation:请参阅 Coffreo/jms-translation-js-extractor-bundle

安装

使用 Symfony flex 的应用程序

composer require coffreo/php-translation-js-extractor-bundle

不使用 Symfony flex 的应用程序

  • 安装捆绑包

    composer require coffreo/php-translation-js-extractor-bundle
    
  • 启用捆绑包

    • symfony 3.*

      // config/AppKernel.php
      public function registerBundles()
      {
          return array(
              // ...
              new Coffreo\PHPTranslationJsExtractorBundle\CoffreoPHPTranslationJsExtractorBundle(),
              // ...
          );
      }
    • symfony 4.*(如果尚未通过 symfony/flex 添加)

      // config/bundles.php
      
      return [
          // ...
          Coffreo\PHPTranslationJsExtractorBundle\CoffreoPHPTranslationJsExtractorBundle::class => ['all' => true],
      ];

使用方法

此捆绑包允许使用 Coffreo/js-translation-extractor 从 JavaScript 文件中提取翻译字符串。

无需特定的命令行,只需使用原始的 php-translation/symfony-bundle 命令即可。

$ bin/console translation:extract ....

找到的翻译将自动添加到当前的翻译文件中,作为 PHP、twig 文件。

配置

此捆绑包不需要配置。
但是,要从 JS 文件中提取字符串,您必须在 php-translation/symfony-bundle 配置中指明您的 JS 文件存储位置。

# paths below are symfony 4.X paths, make sure to change them for sumfony 3.X
# config/packages/php_translation.yaml
translation:
    ...
    configs:
        app:
            dirs: 
              - "%kernel.project_dir%/templates"
              - "%kernel.project_dir%/src"
              - "%kernel.project_dir%/assets"     # <-- add path containing JS files 
            #...

开发者命令

  • 运行测试
composer test
  • 应用编码标准
composer cs

在提交之前必须应用编码标准,否则 TravisCI 将失败

许可

本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件