jonasschen/laravel-lang-monitor 问题修复 & 功能扩展

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

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

jonasschen/laravel-lang-monitor

Composer 安装命令:

composer require jonasschen/laravel-lang-monitor

包简介

Search for untranslated keys in your Laravel project

README 文档

README

Logo

Laravel Lang Monitor

New Now UI Version available!

Latest Version on Packagist Software License Total Downloads GitHub Actions

Automatically search for keys or phrases in your project that have no translations.

Using Laravel Lang Monitor, you can get all missing translations.

Installation

You can install the package via composer:

composer require jonasschen/laravel-lang-monitor --dev

Publish the config, asset and view files using the artisan CLI tool:

php artisan vendor:publish --provider="Jonasschen\LaravelLangMonitor\Providers\LangMonitorServiceProvider"

This command will publish the following files:

  • config/lang-monitor.php
  • public/vendor/lang-monitor/css/lang-monitor.css
  • public/vendor/lang-monitor/ico/lang-monitor.ico
  • public/vendor/lang-monitor/images/lang_monitor_logo_small.png
  • public/vendor/lang-monitor/js/lang-monitor.js
  • resources/views/vendor/lang-monitor/monitor.blade.php

Available configurations

  • abort_if_directory_doesnt_exist: If any configured directories of the "directories_to_search" array do not exist, the scanning process will be aborted, otherwise only an alert it will be logged in the console;
    • Default Value:
    'abort_if_directory_doesnt_exist' => false,
  • abort_if_lang_file_doesnt_exist: If any configured lang files of the "lang_files" array do not exist, the scanning process will be aborted, otherwise only an alert it will be logged in the console;
    • Default Value:
    'abort_if_lang_file_doesnt_exist' => false,
  • scan_for_unused_translations: If enabled, will check if all key translations are in use and log unused keys;
    • Default Value:
    'scan_for_unused_translations' => true,
  • directories_to_search: A list of directories where the package will perform the scanning process;
    • Default Value:
    'directories_to_search' => [
        'app', 
        'resources/views',
    ],
  • extensions_to_search: A list of file extensions that the package will consider to perform the scanning process;
    • Default Value:
    'extensions_to_search' => [
        'php', 
        'js',
    ],
  • lang_files: A list of lang files where the package will try to search the translation keys;
    • Default Value:
    'extensions_to_search' => [
        'resources/lang/en.json', 
    ],
  • locale: The locale of the main project language. It will be used to perform an improved sorting of the untranslated keys when exporting a result;
    • Default Value:
    'locale' => 'en.utf8',
  • middleware: Middleware stack wrapping all Lang Monitor routes. Adjust to control access to the UI.
    • Default Value:
    'middleware' => ['web'],
  • ui_path: URL path where the Lang Monitor UI will be available. Example: "lang-monitor" → https://your-app.test/lang-monitor;
    • Default Value:
    'ui_path' => 'lang-monitor',

Usage via browser

You can access the Lang Monitor UI by going to the URL below:

http://your-app.test/lang-monitor

You can customize the URL path by changing the "ui_path" option in the config file "/config/lang-monitor.php".

Lang Monitor UI

Usage via prompt

Use the command below, it is that easy!

php artisan lang_monitor:scan

Output example with missing translations

Key not found: [Nova senha] - Used in file [resources/views/auth/changepassword.blade.php:20]
Key not found: [Confirmar senha] - Used in file [resources/views/auth/changepassword.blade.php:22]
****************************************
*      LARAVEL LANG MONITOR REPORT     *
****************************************
* Found keys: 13564                    *
* Untranslated keys: 37                *
* Unique untranslated keys: 30         *
* Unused translations: 1474            *
****************************************

Output example without missing translations

********************************************************
*       Great! All translations are working fine.      *
********************************************************

Export untranslated keys to JSON file format

You can export a missing translation result for a file in a JSON format. Use the --export_missed_json_file option like this:

php artisan lang_monitor:scan --export_missed_json_file=storage/logs/untranslateds.json

Export untranslated keys to PHP file format

You can export a missing translation result for a file in a PHP format. Use the --export_missed_php_file option like this:

php artisan lang_monitor:scan --export_missed_php_file=storage/logs/untranslateds.php

Export untranslated keys to text file format

You can export a missing translation result for a file in a text format. Use the --export_missed_text_file option like this:

php artisan lang_monitor:scan --export_missed_txt_file=storage/logs/untranslateds.txt

Export unused keys to JSON file format

You can export unused keys result for a file in a JSON format. Use the --export_unused_json_file option like this:

php artisan lang_monitor:scan --export_unused_json_file=storage/logs/unuseds.json

Export unused keys to PHP file format

You can export unused keys result for a file in a PHP format. Use the --export_unused_php_file option like this:

php artisan lang_monitor:scan --export_unused_php_file=storage/logs/unuseds.php

Export unused keys to a text file format

You can export unused keys result for a file in a text format. Use the --export_unused_text_file option like this:

php artisan lang_monitor:scan --export_unused_txt_file=storage/logs/unuseds.txt

Upgrade guide

From version 2.x to 3.x

  • You will need to publish the config file again to publish the new asset and view files;
php artisan vendor:publish --provider="Jonasschen\LaravelLangMonitor\Providers\LangMonitorServiceProvider"
  • The "middleware" configuration option has been added, and its default value is "['web']". If you want to change this behavior, you will need to manually add the option to the configuration file: "/config/lang_monitor.php";
  • The "ui_path" configuration option has been added, and its default value is "lang-monitor". If you want to change this behavior, you will need to manually add the option to the configuration file: "/config/lang_monitor.php";
  • The "abort_if_directory_doesnt_exists" config option has been renamed to "abort_if_directory_doesnt_exist", and its default value is "false". If you don't manually rename it in your config file, this will be the new behavior;
  • The "abort_if_lang_file_doesnt_exists" config option has been renamed to "abort_if_lang_file_doesnt_exist", and its default value is "false". If you don't manually rename it in your config file, this will be the new behavior;

From version 2.0.x to 2.1.x

  • The "scan_for_unused_translations" configuration option has been added. Its default value is "false". If you want to change this behavior, you will need to manually add the option to the configuration file: "/config/lang_monitor.php";

Translation function support

This package supports @lang(), __() and trans() functions.

Lang file format support

This package supports .php files and .json files formats.

Consider Sponsoring

Help me maintain this project, please consider looking at the FUNDING file for more info.

Buy Me A Coffee

BTC

btc

ETH

eth

Changelog

Please see CHANGELOG for more information about recent changes.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email jonasschen@gmail.com instead of using the issue tracker. Please do not email any questions, open an issue if you have a question.

Credits

License

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

jonasschen/laravel-lang-monitor 适用场景与选型建议

jonasschen/laravel-lang-monitor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.37k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2023 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 jonasschen/laravel-lang-monitor 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-10