incenteev/translation-checker-bundle

用于检查Symfony项目中翻译的命令行工具

v1.9.1 2024-01-16 14:54 UTC

This package is auto-updated.

Last update: 2024-09-16 16:42:05 UTC


README

此扩展提供了一些命令行命令来检查您的翻译。这些命令旨在在CI作业中轻松使用。

CI Latest Stable Version Latest Unstable Version Scrutinizer Code Quality

安装

安装是一个快速(我保证!)的两步过程。

  1. 下载IncenteevTranslationCheckerBundle
  2. 启用Bundle

第一步:使用composer安装IncenteevTranslationCheckerBundle

运行以下composer require命令

$ composer require incenteev/translation-checker-bundle

第二步:启用Bundle

注意:如果您使用Flex,在此步骤中无需操作,因为Flex会为您完成。

最后,在kernel中启用Bundle

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Incenteev\TranslationCheckerBundle\IncenteevTranslationCheckerBundle(),
    );
}

警告:此Bundle要求在FrameworkBundle中启用翻译器。

使用方法

此Bundle提供了一些命令行命令。要列出所有命令,请运行

$ bin/console list incenteev:translation

默认情况下,所有命令仅显示摘要。以详细模式运行以获取详细报告。

查找缺失的翻译

incenteev:translation:find-missing命令从我们的应用程序源代码中提取必要的翻译,然后将其与测试的语种的可用翻译进行比较。如果检测到任何缺失的翻译,它将退出失败代码。

警告:翻译提取不会找到我们应用程序使用的所有翻译。因此,虽然失败退出代码表示存在问题,但成功退出代码并不能保证所有翻译都可用。建议仅使用此命令参考语种,然后通过与其他语种的比较来测试其他语种。

将翻译与参考语种进行比较

incenteev:translation:compare命令比较两个不同语种的可用翻译,如果目录不匹配,则退出失败代码。

注意:此命令可能不适合语种的区域变体(例如fr_FR)。仅用于主语种。

配置

要使用比较目录与提取翻译的命令,您需要配置应解析翻译的Bundle。默认情况下,只有templates(以及Symfony 4及更早版本上的app/Resources/views)中的模板被注册到提取器中。您可以注册也将被处理的Bundle。

# app/config/config.yml
incenteev_translation_checker:
    extraction:
        bundles:
            - TwigBundle
            - AcmeDemoBundle

该Bundle还支持从JS文件中提取翻译,适用于使用willdurand/js-translation-bundle的项目。

# app/config/config.yml
incenteev_translation_checker:
    extraction:
        js:
            # Paths in which JS files should be checked for translations.
            # Path could be either for files, or for directories in which JS files should be looked for.
            # This configuration is required to enable this feature.
            paths:
                - '%kernel.project_dir%/web/js'
                - '%kernel.project_dir%/web/other.js'
            # The default domain used in your JS translations. Should match the js-translation-bundle configuration
            # Defaults to 'messages'
            default_domain: js