bambamboole/laravel-translation-dumper 问题修复 & 功能扩展

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

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

bambamboole/laravel-translation-dumper

Composer 安装命令:

composer require bambamboole/laravel-translation-dumper

包简介

A laravel package to dump missing translation keys into the translation files

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions codecov

This package provides an option to extend Laravels Translator to write missing translation keys to their respective translation files.
This is especially useful if you have dynamic translation keys where static dumpers do not work.

Requirements

  • PHP 8.2+
  • Laravel 11, 12 or 13

Installation

You can install the package via composer. Since this package should only be used in development, you should add the --dev flag.

composer require --dev bambamboole/laravel-translation-dumper

Usage

To enable the dumper, you have to set the environment variable `DUMP_TRANSLATIONS` to `true`.

Workflow

Just write your templates and use the __() helper as usual with your preferred translation key pattern. As soon as you visit the page, the missing translation keys, they will be written to the respective translation files in the structure that the first part of the key is the file name and the rest is the nested path of a PHP array. As value it takes the translation key itself prefixed by a configurable prefix.

By default a dotted key goes into a flat top level file (a.b.ca.php), unless a matching nested file already exists (a/b.php), in which case the key is written there.

Writing translations

Persistence is handled behind the TranslationWriter interface, and the package ships a FileTranslationWriter that reads, merges and writes the lang files (PHP via brick/varexporter, JSON with unescaped unicode/slashes, both with an exclusive lock). Bind your own implementation to TranslationWriter::class to persist elsewhere.

use Bambamboole\LaravelTranslationDumper\FileTranslationWriter;
use Bambamboole\LaravelTranslationDumper\TranslationDumper;

$dumper = new TranslationDumper(new FileTranslationWriter($filesystem, lang_path()), 'en');

Dumping into a specific (nested) file

Pass a group to write every translation into one file, creating it if needed — the group is the path under the locale directory, so it can be nested:

$dumper->dump([
    new Translation('subtitle', 'x-subtitle'),
    new Translation('status.open', 'x-status.open'),
], 'entities/salesOrder');
// -> lang/en/entities/salesOrder.php  (created), keys relative to the group

This pairs with i18next namespaces (entities/salesOrder), where the namespace is the group path: missing keys round-trip straight back into the matching nested file.

Dumping Laravel package namespaces

Laravel package translation keys use the package::file.line syntax after the package has registered its lang directory with loadTranslationsFrom($path, 'package'). Namespaced package keys are ignored by default. Enable the namespaces you want to dump in config/translation.php:

'dump_namespaces' => ['courier'],

With that enabled, a missing __('courier::messages.welcome') call writes to the registered package lang path, for example packages/courier/lang/en/messages.php. Keys without a namespace continue to be dumped without a package:: prefix.

Package namespace dumping is for PHP translation files (package::file.line). JSON translation paths registered with loadJsonTranslationsFrom() continue to use Laravel's JSON translation flow.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email manuel@christlieb.eu instead of using the issue tracker.

Credits

License

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

bambamboole/laravel-translation-dumper 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 34.18k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 14
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-16