smmahfujurrahman/localization 问题修复 & 功能扩展

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

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

smmahfujurrahman/localization

Composer 安装命令:

composer require smmahfujurrahman/localization

包简介

A Laravel package providing Artisan commands to extract, auto-translate, wrap, and sort Blade translation strings with Google Translate support.

README 文档

README

Latest Stable Version Total Downloads License

A Laravel package that provides three Artisan commands to fully automate your translation workflow:

Command What it does
localization:extract Scans all Blade files for __() / @lang() calls and extracts keys to a JSON file. Optionally auto-translates via Google Translate.
localization:wrap Scans all Blade files and wraps un-translated static text with __() automatically.
localization:sort Sorts any translation JSON file alphabetically by key.

Requirements

  • PHP 8.1+
  • Laravel 10, 11, or 12
  • Internet connection (for localization:extract with a target language)

Installation

composer require smmahfujurrahman/localization

Laravel auto-discovers the service provider. No manual registration needed.

Publish Configuration (Recommended)

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

This creates config/localization.php where you can customise all paths and settings:

return [
    // Directory scanned by localization:wrap (default: resources/views)
    'views_path' => resource_path('views'),

    // Directory used by localization:extract and localization:sort
    // null = auto-detect (/lang on Laravel 9+, /resources/lang on older)
    'lang_path' => null,

    // Microsecond delay between Google Translate API calls (default: 100ms)
    'translate_delay' => 100000,

    // Backup directory prefix for localization:wrap (null = auto-generate)
    'backup_path' => null,

    // Filename for the empty key template (no language argument)
    'template_filename' => 'template_empty.json',

    // Source language for Google Translate (null = auto-detect)
    'source_language' => 'en',
];

Usage

localization:extract — Extract & Auto-Translate

Scan all Blade views and extract every __('...') and @lang('...') key into a JSON file.

# Create an empty template (lang/template_empty.json)
php artisan localization:extract

# Auto-translate to French (creates lang/fr.json)
php artisan localization:extract fr

# Auto-translate to Arabic
php artisan localization:extract ar

# Auto-translate to Bengali
php artisan localization:extract bn

# Auto-translate to German
php artisan localization:extract de

Smart re-run: If a target language file already exists, keys that already have a translation are preserved — only new/missing keys are translated. You can re-run safely without overwriting manual edits.

localization:wrap — Wrap Un-Translated Text

Automatically find static English text in your Blade files and wrap it with __().

# Always preview first!
php artisan localization:wrap --dry-run

# Apply changes to all Blade files
php artisan localization:wrap

A timestamped backup of your views directory is created automatically before any files are modified.

Handles 21 patterns including:

  • Simple tag text: <p>Dashboard</p><p>{{ __('Dashboard') }}</p>
  • Dynamic variables: <span>{{ $type }} Management</span><span>{{ __(':type Management', ['type' => $type]) }}</span>
  • HTML attributes: placeholder, title, alt, label
  • Fallback values: {{ $var ?? 'Default' }}{{ $var ?? __('Default') }}
  • Button text, long paragraphs, emoji text, and more

localization:sort — Sort a Translation File

Sort any JSON translation file alphabetically by key for easier management.

php artisan localization:sort ar.json
php artisan localization:sort fr.json
php artisan localization:sort en.json

Typical Workflow

# Step 1: Wrap any un-translated text in your Blade files (dry run first)
php artisan localization:wrap --dry-run
php artisan localization:wrap

# Step 2: Extract all translation keys
php artisan localization:extract

# Step 3: Auto-translate to your target languages
php artisan localization:extract ar
php artisan localization:extract fr
php artisan localization:extract bn

# Step 4: Sort the files for easier management
php artisan localization:sort ar.json
php artisan localization:sort fr.json

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributor

Support

For support and questions:

smmahfujurrahman/localization 适用场景与选型建议

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

它主要适用于以下技术方向: 「i18n」 「translation」 「laravel」 「localization」 「extract」 「blade」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-25