定制 eg-mohamed/laravel-missing-translations 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

eg-mohamed/laravel-missing-translations

Composer 安装命令:

composer require eg-mohamed/laravel-missing-translations

包简介

Scan Laravel project files and append missing translation keys to JSON locale files

README 文档

README

bannar.svg Latest Version on Packagist Total Downloads

A Laravel dev-tool that scans your project for translation function calls and appends any missing keys to your JSON locale files. No more manually hunting for untranslated strings.

Supported Laravel versions: 11, 12, and 13.

Supports __(), trans(), trans_choice(), @lang(), @choice(), Lang::get/has/choice(), and Filament fields, columns, entries, and actions.

Installation

Install as a dev dependency:

composer require eg-mohamed/laravel-missing-translations --dev

Publish the config file:

php artisan vendor:publish --tag="missing-translations-config"

Configuration

// config/laravel-missing-translations.php

return [
    // Directories to scan
    'paths' => [app_path(), resource_path('views')],

    // File extensions to include
    'extensions' => ['php', 'blade.php'],

    // Directories to exclude from scanning
    'exclude_paths' => [],

    // Sort keys alphabetically in the JSON output
    'sort_keys' => true,

    // Skip dotted keys like 'auth.failed' (PHP array-based translations)
    'exclude_dot_keys' => false,

    // Translation functions to detect
    'include_functions' => ['__', 'trans', 'trans_choice', '@lang', '@choice', 'Lang::get', 'Lang::has', 'Lang::choice'],

    // Regex patterns for keys to skip
    'exclude_patterns' => [],

    // Ignore package-namespaced keys like 'filament-shield::resource.role' (anything containing '::')
    'ignore_package_keys' => true,

    // Flags passed to json_encode when writing locale files
    'json_flags' => JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE,

    // Filament field, column, entry, and action scanning
    'filament' => [
        'enabled' => true,

        // Instance methods whose first string literal argument is user-facing text
        'methods' => [
            'label', 'placeholder', 'helperText', 'hint', 'hintTooltip',
            'description', 'heading', 'subheading', 'title',
            'modalHeading', 'modalDescription', 'modalSubmitActionLabel', 'modalCancelActionLabel',
            'emptyStateHeading', 'emptyStateDescription', 'tooltip',
            'prefix', 'suffix', 'navigationLabel', 'navigationGroup',
            'pluralLabel', 'singularLabel', 'breadcrumb',
        ],

        // Component classes whose ::make('Label') first argument is a display label
        // Field-name-style strings like ::make('email') are automatically excluded
        'static_methods' => ['Tab', 'Section', 'Fieldset', 'Group', 'Step'],
    ],
];

Usage

Scan and write missing keys

php artisan missing-translations en

This scans your project, compares found keys against lang/en.json, and appends any missing ones with an empty string value.

If no locale argument is provided and --all is not used, the command falls back to config('app.locale') automatically:

php artisan missing-translations

Preview without writing

php artisan missing-translations en --dry-run

Displays a table of missing keys without modifying any files. Also shows summary statistics:

Keys scanned: 42 | Existing: 38 | Missing: 4
Dry run mode: no changes written.

Process all existing locale files at once

php artisan missing-translations --all

Runs the scan against every lang/*.json file found in your project. If no JSON files exist, a helpful message is shown instead of a generic error.

Remove unused keys

php artisan missing-translations en --remove-unused

Finds keys that exist in lang/en.json but are no longer referenced in any scanned file, displays them, and removes them. Combine with --dry-run to preview without making changes:

php artisan missing-translations en --remove-unused --dry-run

JSON output for CI pipelines

php artisan missing-translations en --json

Outputs results as JSON to stdout instead of the table format. Useful for CI pipelines — e.g. fail a build if missing translations count > 0:

{
    "locale": "en",
    "existing_count": 38,
    "missing_count": 4,
    "missing_keys": [
        "New Key One",
        "New Key Two"
    ]
}

With --remove-unused:

{
    "locale": "en",
    "existing_count": 38,
    "missing_count": 4,
    "missing_keys": ["New Key One"],
    "unused_count": 2,
    "unused_keys": ["Old Key", "Stale Key"]
}

Filament Support

When filament.enabled is true, the scanner also detects plain string literals passed directly to Filament component methods — no __() wrapper required.

Fields, columns, entries, and actions are all covered:

TextInput::make('email')
    ->label('Email Address')           // detected
    ->placeholder('Enter your email')  // detected
    ->helperText('Never shared');      // detected

TextColumn::make('status')
    ->label('Current Status')          // detected
    ->tooltip('Last updated today');   // detected

Action::make('approve')
    ->label('Approve')                 // detected
    ->modalHeading('Confirm Approval') // detected
    ->modalSubmitActionLabel('Yes, approve'); // detected

Structural components like Section, Tab, Fieldset, Group, and Step are scanned when their ::make() argument looks like a display label (contains a space or starts with an uppercase letter):

Section::make('Personal Information') // detected — looks like a label
Tab::make('Account Settings')         // detected
TextInput::make('email')              // NOT detected — looks like a field name

Auto-generated labels are captured too. When a Filament field, column, or entry has no explicit ->label(), Filament generates a label from the field name (e.g. scheduled_timeScheduled time, amountAmount). The scanner picks these up automatically:

TextColumn::make('scheduled_time')->time()->sortable(),
// captured as: "Scheduled time"

TextColumn::make('amount')->numeric()->sortable(),
// captured as: "Amount"

TextInput::make('firstName'),
// captured as: "First name"

The auto-label pass is skipped whenever the chain contains ->label(...) or ->translateLabel(...).

Relationship dot-notation is handled the same way Filament does it:

  • Columns use the second-to-last segment: charityCase.titleCharity case, user.profile.nameProfile
  • Fields and entries use the last segment: user.nameName

Keys wrapped in __() are never double-counted. If you write ->label(__('Email Address')), the key is captured by the standard __() scanner only.

Extend the method list in config to add any custom Filament methods or third-party component methods:

'filament' => [
    'methods' => [
        ...
        'columnLabel',
        'groupLabel',
    ],
],

How it works

  1. Uses Symfony Finder to crawl configured paths for files matching configured extensions
  2. Extracts translation keys via regex from all supported function calls
  3. When Filament scanning is enabled, also extracts plain string literals from label-like methods and structural component names
  4. Diffs found keys against the existing locale JSON file
  5. Appends missing keys with an empty string value, leaving existing translations untouched
  6. Re-running the command is safe — no duplicates are ever added
  7. File writes use LOCK_EX to prevent corruption from concurrent runs

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

eg-mohamed/laravel-missing-translations 适用场景与选型建议

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

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

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

围绕 eg-mohamed/laravel-missing-translations 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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