tarektaher/artisan-language 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tarektaher/artisan-language

最新稳定版本:0.1.1

Composer 安装命令:

composer require tarektaher/artisan-language

包简介

add artisan commands for language

README 文档

README

Latest Version License Download

Artisan Language is a Laravel package designed to streamline the management of translation keys in your application. It provides powerful Artisan commands to synchronize, scan, and manage translation keys for Blade templates, PHP files, and JavaScript files.

Features

  • Synchronize translation keys across multiple locales.
  • Automatically update JSON language files with missing keys.
  • Remove unused keys from JSON language files.
  • Scan Blade, PHP, and JavaScript files for translation keys.
  • Fully customizable through the configuration file.

Installation

Install the package via Composer:

composer require tarektaher/artisan-language

Publish the configuration file:

php artisan vendor:publish --tag=artisan-language-config

This will create the configuration file at config/artisan-language.php.

Configuration

The configuration file allows you to define paths, patterns, and settings for the package.

Default Configuration:

return [
    'default_language' => 'en', // Default language for synchronization
    'languages' => [ // Supported languages
        'en' => 'English',
        'fr' => 'French',
    ],
    'scan_paths' => [ // Paths to scan for translation keys
        app_path(),
        resource_path('views'),
        resource_path('assets/js'),
    ],
    'scan_pattern' => '/(@lang|__|\$t|\$tc)\s*(\(\s*[\'"])([^$]*)([\'"]+\s*(,[^\)]*)*\))/U', // Regex pattern to detect keys
    'lang_path' => base_path('lang'), // Path to JSON language files
];

Commands

1. Scan for Missing Keys

Scan configured paths (Blade templates, PHP files, JavaScript files) for missing translation keys and update the JSON language files.

php artisan lg:scan

Options:

  • --lang: Specify the target language (default: configured default language).

Example:

php artisan lg:scan --lang=fr

2. Synchronize Translation Keys

Synchronize translation keys between the base language and a target locale.

php artisan lg:sync {locale}

Arguments:

  • locale: The locale to synchronize.

Options:

  • --nomissing: Skip adding missing keys from the base language file.
  • --nofurther: Skip removing extra keys from the target language file.

Example:

php artisan lg:sync fr --nomissing

3. Add Translation Keys

Add a new translation key to the specified language file.

php artisan lg:add {key} {value} {--lang=en}

Arguments:

  • key: The translation key to add.
  • value: The value for the key.

Options:

  • --lang: Specify the target language (default: en).

Example:

php artisan lg:add welcome "Welcome to our app" --lang=fr

4. Remove Translation Keys

Remove a translation key from the specified language file.

php artisan lg:remove {key} {--lang=}

Arguments:

  • key: The translation key to remove.

Options:

  • --lang: Specify the target language.

Example:

php artisan lg:remove "Your email is invalid" --lang=fr

Customization

You can customize paths, regex patterns, and language file locations in the configuration file (config/artisan-language.php).

Download

You can download the latest release of Artisan Language here:

Download Artisan Language

Contributing

Contributions are welcome! Feel free to fork this repository, submit a pull request, or open an issue on GitHub.

License

This package is open-sourced software licensed under the MIT License. See the LICENSE file for details.

Support

For issues or questions, please contact Tarek Taher or open a GitHub issue.

With Artisan Language, managing translations has never been easier. Start synchronizing and scanning your keys today! 🎉

统计信息

  • 总下载量: 106
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-28