azizdevfull/lang-gen 问题修复 & 功能扩展

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

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

azizdevfull/lang-gen

最新稳定版本:1.1.0

Composer 安装命令:

composer require azizdevfull/lang-gen

包简介

Automatic translation generator for Laravel

README 文档

README

Latest Version on Packagist Total Downloads License

Automatically generate missing translation keys in your Laravel application.

LangGen scans your application code (app and resources/views) for translation keys like __('messages.welcome') or @lang('auth.failed') and automatically creates the corresponding PHP language files.

Unlike other tools, LangGen supports nested array keys (dot-notation) and creates clean, native PHP arrays without needing a database.

🚀 Features

  • Auto-Discovery: Scans PHP and Blade files for __(), @lang(), trans().
  • JSON Support: Handles keys with spaces or single strings (e.g., __('Log in')) by generating lang/{code}.json.
  • Nested Arrays: Converts auth.password.min into ['password' => ['min' => '...']].
  • Smart Conflict Handling: Configurable policy to preserve or overwrite existing keys.
  • Custom Paths: Configurable directories to scan (e.g., Modules, routes).
  • Native PHP Files: Works with standard Laravel lang/*.php files.
  • No Database Required: Lightweight and zero-setup.

🎥 Video Tutorial

You can see how LangGen works and how to use it in a real project in this YouTube video:

Laravel LangGen – Auto Generate Translations

👉 Watch on YouTube: https://youtu.be/UCr1kR8rMy8

📦 Installation

You can install the package via composer:

composer require azizdevfull/lang-gen --dev

Optionally, you can publish the configuration file:

php artisan vendor:publish --tag="lang-gen-config"

🛠 Usage

Basic Usage

Run the command to scan your codebase and generate missing keys for the default language (default: en):

php artisan lang:gen

Specify Language

To generate translations for a specific language (e.g., Uzbek):

php artisan lang:gen uz

This will:

  1. Scan your configured directories (default: app, resources/views, routes).
  2. Find all translation keys (nested arrays and JSON strings).
  3. Create or update lang/uz/messages.php and lang/uz.json.
  4. Populate missing keys with a readable default value (e.g., "Messages Welcome").

⚙️ Configuration

The configuration file config/lang-gen.php allows you to customize the behavior:

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Scanned Directories
    |--------------------------------------------------------------------------
    |
    | Here you may define the directories that LangGen should scan for
    | translation keys. By default, we scan the 'app', 'resources/views',
    | and 'routes' directories.
    |
    | You can add custom paths here, for example: base_path('Modules')
    |
    */
    'paths' => [
        base_path('app'),
        base_path('resources/views'),
        base_path('routes'),
    ],
    /*
    |--------------------------------------------------------------------------
    | Conflict Policy
    |--------------------------------------------------------------------------
    |
    | Determines how to handle specific key conflicts.
    |
    | Scenario:
    | You have an existing key as a string: 'messages.home' => 'Home'
    | But your code now uses a nested key:  __('messages.home.title')
    |
    | Options:
    | 'preserve'  - Keeps the existing string value. The new nested key is skipped/ignored.
    | 'overwrite' - Replaces the existing string with an array to allow the new nested key.
    |
    */
    'conflict_policy' => 'overwrite', // 'preserve' or 'overwrite'

    /*
    |--------------------------------------------------------------------------
    | Default Language
    |--------------------------------------------------------------------------
    |
    | The default language code to generate translations for.
    | Examples: 'en', 'uz', 'ru'.
    |
    */
    'default_lang' => 'uz',

];

💡 Example

In your code (resources/views/welcome.blade.php):

<h1>{{ __('home.hero.title') }}</h1>
<p>@lang('home.hero.subtitle')</p>

Run command:

php artisan lang:gen en

Result (lang/en/home.php):

<?php

return [
    'hero' => [
        'title' => 'Home Hero Title',
        'subtitle' => 'Home Hero Subtitle',
    ],
];

JSON Key Example

In your code:

<button>{{ __('Create Account') }}</button>

Result (lang/en.json):

{
    "Create Account": "Create Account"
}

🧪 Testing

composer test

🔒 Security

If you discover any security related issues, please email aziz16110904@gmail.com instead of using the issue tracker.

👥 Credits

📄 License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固