vemcogroup/laravel-translation

Laravel 的翻译包,用于扫描本地化并上传/下载到 poeditor

3.0.13 2024-03-29 14:26 UTC

README

Latest Version on Packagist Total Downloads

描述

此包允许您扫描应用程序中的翻译,并创建您的 *.json 文件。

它还允许您将基本翻译上传到 poeditor

安装

您可以通过 composer 安装此包

composer require vemcogroup/laravel-translation

包将自动注册其服务提供者。

要发布配置文件到 config/translation.php,请运行

php artisan vendor:publish --provider="Vemcogroup\Translation\TranslationServiceProvider"

这是配置文件的默认内容

return [

    /*
    |--------------------------------------------------------------------------
    | Base Language
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of language is your base language.
    | The base language select will be created as json file when scanning.
    | It will also be the file it reads and uploads to POEditor.
    |
    */

    'base_language' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Functions
    |--------------------------------------------------------------------------
    |
    | Here you define an array describing all the function names to scan files for.
    |
    */

    'functions' => ['__'],
    
    /*
    |--------------------------------------------------------------------------
    | Excluded directories
    |--------------------------------------------------------------------------
    | 
    | Here you define which directories are excluded from scan.
    |
    */
	
    'excluded_directories' => ['vendor', 'storage', 'public', 'node_modules'],
    
    /*
    |--------------------------------------------------------------------------
    | Extensions
    |--------------------------------------------------------------------------
    |
    | Here you define an array describing all the file extensions to scan through.
    |
    */

    'extensions' => ['*.php', '*.vue'],

    /*
    |--------------------------------------------------------------------------
    | API Key
    |--------------------------------------------------------------------------
    |
    | Here you define your API Key for POEditor.
    |
    | More info: https://poeditor.com/account/api
    |
    */

    'api_key' => env('POEDITOR_API_KEY'),

    /*
    |--------------------------------------------------------------------------
    | Project Id
    |--------------------------------------------------------------------------
    |
    | Here you define the project Id to upload / download from.
    |
    */

    'project_id' => env('POEDITOR_PROJECT_ID'),
];

如果您想使用上传/下载到 poeditor 的功能,您需要在 poeditor 中创建一个你的基本语言。

使用方法

现在您可以使用扫描/上传/下载或 create-js 翻译命令

扫描文件

要扫描项目中的翻译,请运行此命令

php artisan translation:scan {--merge : Whether the job should overwrite or merge new translations keys}

该命令在 /resources/lang 中创建您的 base_language .json 文件

添加术语

要仅添加术语,请运行此命令

php artisan translation:add-terms {--scan : Whether the job should scan before uploading}

此命令不会删除未使用的术语,所以请记住 不要 在之后运行 upload 命令。

上传翻译

要上传您的翻译术语到 poeditor,请运行此命令

php artisan translation:upload {--scan : Whether the job should scan before uploading}

如果您有地区更改,您还可以上传本地翻译

php artisan translation:upload {--translations=all : Upload translations for language sv,da,...}

下载翻译语言

要下载 poeditor 中的语言,请运行此命令

php artisan translation:download

创建 JS 语言文件

要创建公共 JS 文件,请运行此命令

php artisan translation:create-js {--download : Download language files before creating js}

现在您可以通过在 /public/lang 中包含 .js 文件,以 window.i18n 的方式访问所有语言

<script src="/build/lang/en.js"></script>

系统翻译

如果您想翻译系统翻译,请更改例如 /resources/lang/en/auth.php 中的术语

'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',

'throttle' => __('Too many login attempts. Please try again in :seconds seconds.'),

然后它将被扫描并包含在同步术语中。