• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

stevegrunwell/lost-in-translation: Uncover missing translations and localization ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

stevegrunwell/lost-in-translation

开源软件地址(OpenSource Url):

https://github.com/stevegrunwell/lost-in-translation

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

Lost in Translation

Build Status Coverage Status

Lost in Translation is designed to help developers locate instances of localization strings within a Laravel application that haven't been provided translations.

Installation

Lost in Translation can be installed into your Laravel project via Composer:

$ composer require stevegrunwell/lost-in-translation

By default, this will replace the default TranslationServiceProvider class with a sub-class that adds additional logic when a translation isn't found. To resume default behavior (even in a production environment), see the "Configuration" section below.

Configuration

By default, Lost in Translation will catch missing translations in two ways:

  1. In environments where APP_DEBUG is true, a LostInTranslation\MissingTranslationException will be found if the application attempts to load a translation that hasn't been defined.
  2. Missing translations will be written to storage/logs/lost-in-translation.log.

Either of these can be disabled via the package's configuration, making Lost in Translation safe to use in production. These values can be set using the following environment variables:

TRANS_LOG_MISSING
Determines whether or not missing translations should be logged. Default is "true".
TRANS_ERROR_ON_MISSING
Should MissingTranslationException exceptions be thrown when a translation is missing? Default is "false".

To override package configuration, run the following to copy the configuration to your app's config/ directory:

$ php artisan vendor:publish --provider="LostInTranslation\Providers\TranslationServiceProvider"

This will create a new file in config/lostintranslation.php, where default values for your application can be set.

Extending

When a missing translation is found, the a LostInTranslation\MissingTranslationFound event will be dispatched. This event makes it easy to do something (send an email, open a GitHub issue, etc.)when a missing translation is encountered.

First, create a new event listener in your application; in this example, we're using app/Listeners/NotifyOfMissingTranslation.php:

<?php

namespace App\Listeners;

use LostInTranslation\Events\MissingTranslationFound;

class NotifyOfMissingTranslation
{
    /**
     * Handle the event.
     *
     * @param MissingTranslationFound $event
     *
     * @return void
     */
    public function handle(MissingTranslationFound $event)
    {
        // Do something with the event.
    }
}

The MissingTranslationFound event has four public properties of note:

  1. $key - The translation key that was not found.
  2. $replacements - Any replacements that were passed to the translation call.
  3. $locale - The locale that was being used.
  4. $fallback - The fallback locale, if defined.

Then, in app/Providers/EventServiceProvider.php, add the following to register NotifyOfMissingTranslation as a callback when a MissingTranslationFound event occurs:

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'LostInTranslation\Events\MissingTranslationFound' => [
        'App\Listeners\NotifyOfMissingTranslation',
    ],
];

For more on event listeners, please see the Laravel Events documentation.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
infinity1096/eskf_localization发布时间:2022-08-16
下一篇:
sharathadavanne/seld-dcase2021: Baseline method for sound event localization tas ...发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap