rauwebieten/craft-translations-extractor

Craft CMS 翻译提取器

1.0.2 2023-01-16 14:35 UTC

This package is auto-updated.

Last update: 2024-09-16 18:26:00 UTC


README

正在进行中,使用风险自负

要求

此插件需要 Craft CMS 3.5 或更高版本。

安装

composer require rauwebieten/craft-translations-extractor

使用

php craft translations-extractor/index

此命令将在您的模板文件夹中搜索翻译字符串。此命令使用正则表达式查找所有翻译字符串,它将找到以下翻译字符串

<p>
    {# translation with t filter #}
    {{ "Hello world"|t }}

    {# translation with translate filter #}
    {{ "Hello craft"|translate }}

    {# translation with single quotes #}
    {{ 'Hello template'|t }}

    {# translation with single/double quotes #}
    {{ 'This is a "quoted string"'|t }}
    {{ "This is another \"quoted string\""|t }}
    {{ 'This too is a \'quoted string\''|t|raw }}
</p>

对于项目中的每个定义的语言,它将创建一个翻译文件。

  • 不再使用的翻译字符串将从翻译文件中删除
  • 现有的翻译字符串将与新找到的翻译字符串合并
translations/en/site-extracted.php

您可以随意处理此文件。例如,将其包含在主翻译文件中。这样,您仍然可以使用带有自定义翻译字符串的 site.php 文件。

// translations/en/site.php
<?php return array_merge(include __DIR__ .'site-extracted.php',[
  'other-translation-strings' => 'blah blah'
]);

不支持。

此插件是正在进行中的项目。使用风险自负。

此插件无法

  1. 检测带参数的翻译字符串,例如 "{num} pages"(params={num:3})
  2. 检测其他命名空间中的翻译字符串,例如 "hello"|t('plugin-handle')

路线图

  1. 解决上述提到的问题
  2. 使用翻译 API
  3. Craft 4 支持