Laravel 语言文件。捕获缺失的定义

问题描述 投票:0回答:3

我在我的应用程序中使用 Laravel 的语言功能。

我遇到的问题是,如果我调用不存在的语言行,则返回值是使用的键,例如

Lang::get('messages.doesNotExist');

returns 'messages.doesNotExist'

Laravel 是否提供任何方法来查找语言行是否丢失?例如将缺失的行记录到错误日志中?

我担心的是,除非用户向我标记,否则我可能不会意识到语言行丢失。

laravel-4 localization
3个回答
0
投票

来自文档(http://laravel.com/docs/localization#basic-usage):

判断语言文件是否包含一行

if (Lang::has('messages.doesNotExist'))
{
    //
}

0
投票

我是 Lost in Translation 的作者,它可以分析您的代码和本地化文件以查找丢失的翻译和未使用的密钥。安装并将其添加到服务提供商后(如自述文件中所述),您可以使用

locale:scan
artisan 命令生成本地化使用报告。如:

$ php artisan locale:scan
Preparing files
Looking in /git/lost-in-translation-wrapper/app and git/lost-in-translation-wrapper/resources
Searching translationkeys in 51 files
 51/51 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
Found 23 translations.
There are missing translations.
+----------------------------------------------+-------+-----------+---------+
| Key                                          | Group | Namespace | Missing |
+----------------------------------------------+-------+-----------+---------+
| failed                                       | auth  | *         | fr      |
| throttle                                     | auth  | *         | fr      |
| password                                     | auth  | *         | fr      |
| Email                                        | *     | *         | es, fr  |
| Password                                     | *     | *         | es, fr  |
| Confirm Password                             | *     | *         | es, fr  |
| Reset Password                               | *     | *         | es, fr  |
| Name                                         | *     | *         | es, fr  |
| Already registered?                          | *     | *         | es, fr  |
| Register                                     | *     | *         | es      |
| This is a secure area of the application     | *     | *         | es, fr  |
| Confirm                                      | *     | *         | es, fr  |
| Forgot your password? No problem             | *     | *         | es, fr  |
| Email Password Reset Link                    | *     | *         | es, fr  |
| Thanks for signing up! Before getting st ... | *     | *         | es, fr  |
| A new verification link has been sent to ... | *     | *         | es, fr  |
| Resend Verification Email                    | *     | *         | es, fr  |
| Log Out                                      | *     | *         | es, fr  |
| Remember me                                  | *     | *         | es, fr  |
| Forgot your password?                        | *     | *         | es, fr  |
| Log in                                       | *     | *         | es, fr  |
| Whoops! Something went wrong                 | *     | *         | es, fr  |
| Dashboard                                    | *     | *         | es, fr  |
+----------------------------------------------+-------+-----------+---------+
There are unused translations.
*.*.I love programming.
*.auth.invalid

0
投票

在 10.33.0 版本中,laravel 现在支持此功能:https://laravel.com/docs/10.x/localization#handling-missing-translation-strings

© www.soinside.com 2019 - 2024. All rights reserved.