backtheweb/laravel-linguo

Laravel 解析多语言

1.0.6 2024-08-18 18:32 UTC

This package is auto-updated.

Last update: 2024-09-18 16:38:28 UTC


README

Laravel 多语言解析器

安装

Laravel 服务提供者

config/app.php 中添加服务提供者和别名

'providers' => [

    [...]
    Backtheweb\Linguo\LinguoServiceProvider::class,
],

'aliases' => [
    [...]
    'Linguo' => Backtheweb\Linguo\LinguoFacade::class,
]

并发布配置

php artisan vendor:publish --provider="Backtheweb\Linguo\LinguoServiceProvider" --tag=config

配置

编辑 config/linguo.php

return [

    'headers' => [
        'Project-Id-Version'    => env('APP_NAME', 'linguo'),
        'Language-Team'         => 'TeamName <info@example.com>'
    ],

    'paths' => [
        base_path('resources/views'),
        base_path('app/Http/Controllers'),
    ] ,

    'target'    =>  resource_path('lang'),
    'domain'    => 'default',
    'domains'   => [
        'auth',
        'pagination',
        'passwords',
        'validation',
    ],      // ignore domains, filenames on langs folder such as pagination, passwords,...

    'locales'   => ['es_ES', 'en_US', 'it_IT', 'fr_FR', 'de_DE', 'pt_BR'],
];

:解析器将查找翻译键的位置 i18nPath:存储翻译文件的路径

解析和生成翻译文件

解析

php artisian linguo:scan        // Create file
php artisian linguo:update      // Create or update po files
php artisian linguo:compile     // Convert po to json