coliving/laravel-autotranslate

一个Laravel扩展包,用于使用DeepL自动将应用程序的语言文件翻译成选定的语言。

1.2.0 2024-06-20 06:36 UTC

This package is not auto-updated.

Last update: 2024-09-27 07:04:06 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

一个Laravel扩展包,用于使用DeepL自动将应用程序的JSON语言文件翻译成选定的语言。这是由bernskioldmedia/laravel-autotranslate包支持的,适用于Laravel 11。

安装

您可以通过Composer安装此包

composer require coliving/laravel-autotranslate

您可以使用安装命令安装此包

php artisan autotranslate:install

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="laravel-autotranslate-config"

这是已发布的配置文件内容

return [

    /**
     * The source language that your application language is in before translation.
     */
    'source_language' => 'en',

    /**
     * This is your DeepL API key.
     */
    'api_key' => env('AUTOTRANSLATE_DEEPL_KEY'),

    /**
     * DeepL supports settings for each language to translate to.
     * These are the default settings that will be applied
     * unless you override it for a specific language below.
     *
     * See the DeepL PHP SDK for more information: https://github.com/DeepLcom/deepl-php
     */
    'options' => [

        // Choose the formality of the text.
        // This setting is only available for certain languages: https://github.com/DeepLcom/deepl-php#listing-available-languages
        // Available options: 'less', 'more', 'default', 'prefer_less', 'prefer_more'
        'formality' => 'default',

        // Specify how input text should be split into sentences.
        // Available options: 'on', (default) 'off', 'nonewlines'
        'split_sentences' => 'on',

        // Controls automatic-formatting-correction.
        // Set to true to prevent automatic-correction of formatting.
        'preserve_formatting' => false,

        // Type of tags to parse before translation.
        // Available options: 'html', 'xml'
        'tag_handling' => 'html',

        // The ID of the DeepL glossary to use.
        'glossary' => null,
    ],

    'language_options' => [

//      'de' => [
//          'formality' => 'less',
//      ],

    ],

];

使用方法

要翻译您的应用程序语言文件,您可以使用autotranslate:translate命令

php artisan autotranslate:translate sv

语言参数是必需的,并且应该与您应用程序语言文件夹中的语言路径相对应。

自动导出字符串

如果您想自动将应用程序中的字符串导出到语言文件,您可以使用Laravel可翻译字符串导出器包。

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

鸣谢

许可协议

MIT许可(MIT)。有关更多信息,请参阅许可文件