mahmoud217tr / auto-files-localizer
自动生成 JSON 本地化文件的 Laravel 本地化包
1.1.0
2024-07-25 15:36 UTC
Requires
- php: ^8.0
- illuminate/config: ^9.0|^10.0|^11.0
- illuminate/console: ^9.0|^10.0|^11.0
- illuminate/contracts: ^10.0||^11.0
- illuminate/filesystem: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
- illuminate/translation: ^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.16
- symfony/finder: ^5.1|^6.0|^7.0
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
简单高效的本地化
自动生成 JSON 本地化文件的 Laravel 本地化包
目录
功能
- 支持 Laravel (8.X, 9.X, 10.X, 11.X)。
- 两种模式(动态模式,提取模式)。
- 快速且可靠。
安装
您可以通过 composer 安装此包
composer require mahmoud217tr/auto-files-localizer
配置
要发布包配置文件 config/auto-localizer.php
,请使用以下命令
php artisan vendor:publish --tag="auto-files-localizer-config"
使用
它将自动生成本地化 .json
文件,其中本地化新词按字母顺序排序。
此包有两种模式
动态模式
在此模式下,翻译将动态生成 (请求时),这意味着在调用翻译函数时,包将动态检测当前语言并将翻译添加到相应的 JSON
文件中。
注意
-
请注意,出于性能考虑,此模式不应在生产环境中使用,但如果您想通过配置文件更改此行为。
-
此模式不建议与
vite 开发
模式一起使用。如果您想使用它,请先使用npm run build
命令构建您的资源,然后激活自动翻译模式。否则,您的应用程序将陷入重新加载循环
激活
要在非生产环境中激活 dynamic
模式,只需将以下行添加到 .env
文件中
AUTO_LOCALIZER_ENABLED=true
这样,自动翻译器就会将翻译添加到相应的文件中,并按字母顺序排序。要禁用动态模式,只需将前面的值设置为 false
。
配置
此模式有以下配置
'dynamic' => [ # Controls if the dynamic mode should work or not on non-production environments 'enabled' => (bool) env('AUTO_LOCALIZER_ENABLED', false), # Controls if the dynamic mode should work or on production environment (compined with the previous option) 'production' => false, ],
提取模式
在此模式下,翻译将自动从 views
或 php
文件中提取,检测翻译函数,并将翻译添加到相应的 JSON
文件中。
命令
要为特定区域(例如 ar
)提取翻译,请运行以下命令
php artisan localizer:extract ar
前面的命令将翻译所有 未本地化
的短语以及所有 ar-localized
的短语。
配置
此模式有以下配置
'extraction' => [ # The directories where the translation scanner will scan 'directories' => [ 'resources/views', ], # The file patterns that the translation scanner will scan 'patterns' => [ '*.php' ], # The translation functions or directives that scanner will detect (you should add your custom functions here) 'functions' => [ '__', 'trans', '@lang', ], ],
测试
composer test
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG
贡献
有关详细信息,请参阅 CONTRIBUTING
安全漏洞
请审查 我们的安全策略,了解如何报告安全漏洞。
鸣谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件