yannxtrem/laralang 问题修复 & 功能扩展

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

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

yannxtrem/laralang

Composer 安装命令:

composer require yannxtrem/laralang

包简介

A Laravel package to extract translatable strings from views and Livewire components into a JSON file.

README 文档

README

Latest Stable Version License

Laravel Lang Extractor is a lightweight, zero-dependency development tool for Laravel 11 & 12.

It automatically scans your application's Views and Livewire components to find translatable strings (using the __('key') helper), deduplicates them, and exports them into a clean JSON file ready for translation.

It replaces complex Bash scripts or heavy dependencies when you just need a simple JSON extraction.

🚀 Features

  • Recursive Scanning: Scans resources/views (Blade files) and app/Livewire (Component classes).
  • Regex Extraction: Detects __('string') and __("string").
  • Smart Deduplication: Automatically removes duplicate keys.
  • JSON Output: Generates a valid JSON file compatible with Laravel's JSON translation support.
  • Unicode Support: Preserves accents and special characters (no escaped Unicode sequences).
  • Laravel Native: Fully integrated Artisan command.

📋 Requirements

  • PHP 8.2 or higher
  • Laravel 11.0 or higher

📦 Installation

Install the package via Composer as a development dependency:

composer require yannxtrem/laralang --dev

Note: Since this tool is used during development to generate translation files, it is recommended to install it with the --dev flag.

🛠 Usage

Basic Extraction

Run the artisan command to scan your project and generate the JSON file:

php artisan laralang:extract

By default, this will create a file named a_trad.json in your project root.

Custom Output File

You can specify the output filename and path using the --output option:

php artisan laralang:extract --output=lang/fr.json

Or for another language:

php artisan laralang:extract --output=lang/es.json

🔍 How it works

  1. Scan: The command looks for *.php and *.blade.php files in:
    • resources/views/
    • app/Livewire/
  2. Extract: It applies a regex pattern to find usage of the Laravel translation helper:
    • Matches: __('Hello World')
    • Matches: __("Hello World")
  3. Process:
    • Keys are sorted alphabetically.
    • Duplicates are removed.
  4. Save: The result is saved as a JSON object where the key is the string found, and the value is an empty string (or the existing translation if you implement merging logic in the future).

Example Output

{
    "Back to home": "",
    "Confirm password": "",
    "Login": "",
    "Welcome to our application": ""
}

⚡ Workflow Example

  1. Develop your features using __('My text') in Blade or PHP files.
  2. Run php artisan translation:extract --output=lang/fr.json.
  3. Open lang/fr.json and fill in the empty values with translations.
  4. Laravel automatically uses these translations when the locale is set to fr.

🤝 Contribution

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This package is open-sourced software licensed under the MIT license.

yannxtrem/laralang 适用场景与选型建议

yannxtrem/laralang 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 yannxtrem/laralang 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 yannxtrem/laralang 我们能提供哪些服务?
定制开发 / 二次开发

基于 yannxtrem/laralang 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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