singlequote/laravel-locale-finder 问题修复 & 功能扩展

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

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

singlequote/laravel-locale-finder

Composer 安装命令:

composer require singlequote/laravel-locale-finder

包简介

README 文档

README

This package scans your project files (like Blade, PHP, and script files) for translation keys (__("...") or @lang("...")), automatically translates them into your specified languages using an external translation service, and saves them to the correct language files. It also helps maintain clean language files by removing keys that are no longer in use.

Latest Version on Packagist Total Downloads

Installation

Install the package via Composer. It's recommended to install it as a development dependency since it's typically only used during development.

composer require singlequote/laravel-locale-finder --dev

Publish config

You can change the behaviour of the package by editing the config file. Publish the config file with the command below.

php artisan vendor:publish --tag=locale-finder

Usage

The package searches for translations key in your blade files. For example {{ __("My translation") }}. Or @lang('My Translation'). After searching the package will try to translate the keys using the google translate package.

When removing translations from your view, the package will also remove the keys from the files.

The command can be used from the commandline

For example, find and translate all dutch translation keys

php artisan locale:find --locales=nl

or find and translate the dutch and german translations keys

php artisan locale:find --locales=nl,de

Translate all available locales

The all option will scan your lang folder and select the available .json files.

php artisan locale:find --locales=all

Change source

If you develop your application in a different language you can change the defualt source from en to something else.

php artisan locale:find --locales=nl --source=de

Disabling key translations

If you would like to just get the keys from your views, you can use the --notranslate option. This will fill the values with the default keys.

php artisan locale:find --locales=nl --notranslate

Exclude keys

If you want the package to only search for specific translation keys, you can use the --only option. This will exclude everthing outside the --only scope.

php artisan locale:find --locales=nl --only=app

The above will exclude every translation key that doesn't belong in the app directive.

For example:

__("app.this will be included");
__("users.i am not included");

Add multiple only keys to your command

php artisan locale:find --locales=nl --only=app,users

Using patterns

When using modules or large translation files, it can be a lot of work to fill the --only option with all keys. You can use the * pattern to include keys. For example if you execute the command below:

php artisan locale:find --locales=nl --only=user*
__("users.i am included");
__("user.i am also included");
__("username.i am also included!");
__("use.i am not included :-(");

Create missing php key files

When adding new translations keys such as __("newkey.some text") the file newkey.php should exists in order to add the translation keys. When using the --create option the package will auto generate these files.

php artisan locale:find --create

Beta

Modules

When using modules in your laravel package with their own lang folder, you would like to add the keys to the right files in the module folders.

So for example when we have a module called Horses and we loaded the translations using $this->loadTranslationsFrom(PATHTOTRANS, "horses"); in our Service provider. The key should be something like this : __("horses::") and with a translation __("horsed.colors.red") where colors.php is the file.

When using the --modules option, the package will auto detect the loaded translation files and adds the keys to the right files.

php artisan locale:find --modules

Contributing

Please see CONTRIBUTING for details.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Quotec, Traktieweg 8c 8304 BA, Emmeloord, Netherlands.

Credits

License

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

singlequote/laravel-locale-finder 适用场景与选型建议

singlequote/laravel-locale-finder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.57k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2022 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 singlequote/laravel-locale-finder 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 3.57k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-12