fzayne/lara-translation 问题修复 & 功能扩展

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

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

fzayne/lara-translation

Composer 安装命令:

composer require fzayne/lara-translation

包简介

A Laravel package to extract translation keys from source files and export them into a dedicated translation file.

README 文档

README

LaraTranslation is a Laravel package that extracts translation keys from your PHP and Blade files and exports them to JSON files for multiple locales.

This is especially useful for applications using Laravel's JSON translation format, helping you keep track of all translation keys in use throughout your views and code.

🚀 Features

  • Scan specific directories for translation function calls
  • Supports trans(), __(), and @lang patterns
  • Exports translation keys to JSON files per locale
  • Merges with existing translations without overwriting existing values
  • Easy Artisan command to trigger extraction and export

📦 Installation

Step 1: Install via Composer

If using directly from GitHub:

composer require fzayne/lara-translation

Step 2: Publish Config

php artisan vendor:publish --tag=lara-translation-config

⚙️ Configuration

The package provides a simple way to customize the directories, patterns, and output file where translation keys are extracted and stored.

1. Directories

You can define the directories in which the package will search for translation keys. By default, the package looks for translation keys in the app/View and resource/views directories. You can add or modify these directories in the configuration file to include other locations as needed.

    'directories' => [
        app_path('View'),
        resource_path('views'),
    ],

2. Patterns

The package supports searching for specific translation functions or patterns within your files. The default patterns include common Laravel translation functions like trans(), __(), and @lang. You can customize this list to match any other translation function or pattern that you use in your application.

      'patterns' => [
        'trans',  
        '__',     
        '@lang',  
    ],

3. Output Path

Once the translation keys are extracted, they are saved to a file. By default, these keys are stored in the language files within the lang/ directory. You can configure a different output path where the generated files will be saved. This makes it easy to organize your translation keys wherever you need them.

This configuration allows you to easily control where the package searches for translation keys, what functions or patterns it looks for, and where the output files will be saved.

🛠 Usage

Run the Artisan command to export translation keys:

php artisan transkeys:export {locales?*}

Exemple:

php artisan transkeys:export en fr ar

This will create or update en.json, fr.json, and ar.json in your lang/ folder with all translation keys found.

License

This package is open-source and available under the MIT License.

You are free to use, modify, and distribute it, as long as you include the original copyright and license notice in your copies of the software.

Credits

This package was inspired by the work of KaziSTM, who provided valuable insights and ideas for extracting translation keys more efficiently. Special thanks to the open-source community for their contributions.

If you use or find this package useful, feel free to credit the original ideas and contributions.

fzayne/lara-translation 适用场景与选型建议

fzayne/lara-translation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 fzayne/lara-translation 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-13