labor-digital/typo3-translation-utils

一组TYPO3命令行任务,用于处理翻译标签

安装: 474

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放性问题: 0

类型:typo3-cms-extension

10.0.5 2022-04-29 17:40 UTC

This package is auto-updated.

Last update: 2024-09-29 05:42:50 UTC


README

一个简单的开发辅助包,提供一些命令行工具来处理翻译文件。

注意事项:这是一个开发辅助工具,不应在生产机器上安装!

要求

安装

使用Composer安装此包

composer require labor-digital/typo3-translation-utils --dev

之后,您可以在TYPO3安装的扩展管理器中激活扩展

文档

t3tu:export <EXT_KEY>

将扩展的翻译标签导出到csv文件中。为您的扩展中的每个基本翻译文件创建一个csv文件。这意味着locallang.xlf将导出到locallang.csv,而locallang_be.xlf将导出到locallang_be.csv。

脚本将加载您目录中的所有翻译,这些翻译的命名格式为de.locallang.xlf, es.locallang.xlf,...,并将标签放入文件的自定义列中。

这样,您可以轻松地提供翻译者所有翻译及其匹配键的概览。

选项:--format | -f

允许您更改翻译的输出格式。默认情况下,导出.csv文件。使用此选项,您还可以将其设置为.xls, .xlsx或.ods,具体取决于您的需求

t3tu:import <EXT_KEY>

将翻译的csv文件导入xlf翻译文件。这是“导出”的基本反向操作。在您更改翻译目录中的csv文件内容后,此命令将读取所有csv文件并更新/创建所需的翻译xlf文件。

注意如果脚本在您的语言目录中找到.xls, .xlsx或.ods文件,它将以与.csv文件相同的方式解析它们。如果您的Excel文件中存在UTF-8编码字符的问题,这很有帮助。

t3tu:sync <EXT_KEY>

将所有翻译文件(例如,de.locallang.xlf,...)与源文件(例如,locallang.xlf)以及反之亦然同步。

同步使用源文件作为“真相之源”,这意味着您在那里添加或删除的所有翻译键都将添加/删除到相应的翻译文件中。所有在翻译文件中新建条目都将使用COPY FROM - $SOURCELANG:作为前缀,以便轻松识别。

如果您在源文件中重命名翻译键,翻译文件中的键将自动更新以匹配。(只有当“source”标签同时匹配源文件和翻译文件时,才会这样做!否则,翻译文件中的键将被重新创建!)

同步将自动更新翻译文件中的“source”标签,如果它在源文件中更改。

同步还将确保所有源文件具有相同语言变体可供使用。这意味着在实践中,如果您从

  • locallang.xlf
  • de.locallang.xlf
  • locallang_be.xlf
  • es.locallang_be.xlf

开始,同步后您将得到类似以下内容

  • locallang.xlf
  • de.locallang.xlf
  • es.locallang.xlf
  • locallang_be.xlf
  • de.locallang_be.xlf
  • es.locallang_be.xlf

您还可以通过为您的语言添加一个空文件来引入新的语言变体。文件将自动准备一些虚拟内容并添加到所有现有的源文件中。

配置

您可以使用由 TYPO3 - Better API 扩展提供的“ext config”框架来配置扩展。要创建配置,请向 $ext_key/Configuration/ExtConfig/TranslationUtils.php 中添加一个新的类,如下所示

<?php
namespace LaborDigital\T3baExample\Configuration\ExtConfig;
use LaborDigital\T3ba\ExtConfig\ExtConfigContext;
use LaborDigital\T3tu\ExtConfigHandler\ConfigureTranslationUtilsInterface;
use LaborDigital\T3tu\ExtConfigHandler\TransUtilsConfigurator;

class TranslationUtils implements ConfigureTranslationUtilsInterface
{
    public static function configureTranslationUtils(TransUtilsConfigurator $configurator, ExtConfigContext $extConfigContext): void
    {
        // The default export format can be configured for the extension
        $configurator->setDefaultExportFormat('xls');
        
        // You can also add constraints that define which languages and/or files should be included by specific actions or not.
        $configurator->exportConstraint()
                     ->addAllowedLanguage('en,es')
                     ->addIgnoredFile('locallang_mod_module.xlf');
        
        // As a rule of thumb, the "allow-list" always beats the "ignore-list". So in this example, we ignore spanish
        // but explicitly allow it for the "locallang.xlf" file when the t3tu:sync command is executed.
        $configurator->syncConstraint()
                     ->addIgnoredLanguage('es')
                     ->addIgnoredFile('locallang_be')
                     ->addAllowedFile('locallang.xlf', 'es');
    }
    
}

配置其他扩展

默认情况下,配置限制在添加配置类的扩展。所以,上面的 T3baExample 命名空间仅在 t3ba_example 扩展中有效。要为其他扩展提供配置,您可以使用 ext config 实现提供的“runWithExtKeyAndVendor”模拟器。使用此方法,您可以提供类似于由另一个扩展添加的配置。因此,要配置 ext:news,您可以这样做

<?php

namespace LaborDigital\T3baExample\Configuration\ExtConfig;


use LaborDigital\T3ba\ExtConfig\ExtConfigContext;
use LaborDigital\T3tu\ExtConfigHandler\ConfigureTranslationUtilsInterface;
use LaborDigital\T3tu\ExtConfigHandler\TransUtilsConfigurator;

class TranslationUtils implements ConfigureTranslationUtilsInterface
{
    public static function configureTranslationUtils(TransUtilsConfigurator $configurator, ExtConfigContext $extConfigContext): void
    {
        $extConfigContext->runWithExtKeyAndVendor('news', null, function () use ($configurator) {
            // Everything in this closure is executed as if the configuration was added by ext:news
            $configurator->setDefaultExportFormat('xls');
        });
    }
}

Postcardware

您可以使用此软件包,但如果它进入您的生产环境,我们非常感谢您从您家乡寄给我们一张明信片,并说明您正在使用我们的哪个软件包。

我们的地址是:LABOR.digital - Fischtorplatz 21 - 55116 Mainz, Germany

我们将所有收到的明信片发布在我们的 公司网站 上。