kkomelin/laravel-translatable-string-exporter
Composer 安装命令:
composer require kkomelin/laravel-translatable-string-exporter
包简介
Translatable String Exporter for Laravel
README 文档
README
You can use __('Translate me') or @lang('Translate me') with translations in JSON files to translate strings.
Translatable String Exporter is aimed to collect all translatable strings of an application and create corresponding translation files in JSON format to simplify the process of translation.
Versions
| Package | PHP |
|---|---|
<=1.15.1 |
5.6 |
>1.15.1 |
^7.2|^8.0 |
>1.18.0 |
^8.0 |
>1.25.0 |
^8.2 |
Even though we drop support for PHP versions in minor releases, Composer ensures that users with previous versions of PHP don't get not-yet-supported PHP code.
Installation
Normally, it's enough to install the package as a development dependency.
composer require kkomelin/laravel-translatable-string-exporter --dev
Configuration
To change project defaults, use the following command to create a configuration file in your config/ folder and make necessary changes in there:
php artisan vendor:publish --provider="KKomelin\TranslatableStringExporter\Providers\ExporterServiceProvider"
Usage
Export translatable strings
php artisan translatable:export <lang>
Where <lang> is a language code or a comma-separated list of language codes.
For example:
php artisan translatable:export es php artisan translatable:export es,bg,de
The command with the "es,bg,de" parameter passed will create es.json, bg.json, de.json files with translatable strings or update the existing files in the lang/ folder of your project.
Find untranslated strings in a language file (command)
To inspect an existing language file (find untranslated strings), use this command:
php artisan translatable:inspect-translations fr
The command only supports inspecting one language at a time.
To export translatable strings for a language and then inspect translations in it, use the following command:
php artisan translatable:inspect-translations fr --export-first
Find untranslated strings in a language file (IDE)
An alternative way to find untranslated strings in your language files is to search for entries with the same string for original and translated. You can do this in most editors using a regular expression.
In PhpStorm and VSCode, you can use this pattern: "([^"]*)": "\1"
Persistent strings
Some strings are not included in the export, because they are being dynamically generated. For example:
{{ __(sprintf('Dear customer, your order has been %s', $orderStatus)) }}
Where $orderStatus can be 'approved', 'paid', 'cancelled' and so on.
In this case, you can add the strings to the <lang>.json file manually. For example:
...,
"Dear customer, your order has been approved": "Dear customer, your order has been approved",
"Dear customer, your order has been paid": "Dear customer, your order has been paid",
...
In order for those, manually added, strings not to get removed the next time you run the export command, you should add them to a json file named persistent-strings.json. For example:
[
...,
"Dear customer, your order has been approved",
"Dear customer, your order has been paid",
...
]
License & Copyright
MIT, (c) 2017-present Konstantin Komelin and contributors
kkomelin/laravel-translatable-string-exporter 适用场景与选型建议
kkomelin/laravel-translatable-string-exporter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.48M 次下载、GitHub Stars 达 330, 最近一次更新时间为 2017 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「translation」 「translations」 「export」 「laravel」 「localization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kkomelin/laravel-translatable-string-exporter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kkomelin/laravel-translatable-string-exporter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kkomelin/laravel-translatable-string-exporter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Laravel Eloquent model trait for translatable resource
ext-json wrapper with sane defaults
Deepl Automated translations for Laravel lang files
A package to cast json fields, each sub-keys is castable
统计信息
- 总下载量: 1.48M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 331
- 点击次数: 24
- 依赖项目数: 12
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-22