Why is the sensitivity of the yii2 internationalization module case sensitive?

I am currently working on the yii2 internationalization module, but have come across curious behavior and wandered around.

Why Yii::t('app','NEXT'), Yii::t('app','NEXT')and Yii::t('app','NEXT')require separate translations?

I save the translation in the database. Is there a way to make case insensitive transfers? Or is there a specific reason why this is so?

+4
source share
1 answer

, , "NEXT" "next" . , , - "І" "і", , .

, , ( ) .

,

- , , Yii::t().

namespace app\components; // your namespace here

class Translator {
    public static function t($category, $message, $params = [], $language = null)
    {
        return \Yii::t($category, strtolower($message), $params, $language);
    }
}

Yii::t('app', 'Next') Translator::t('app', 'Next'), ""


( ) :

I18N, web.php. , yii\i18n\I18N:

namespace app\components;

use yii\i18n\I18N;

class NewI18N extends I18N
{
    public function translate($category, $message, $params, $language)
    {
        return parent::translate($category, strtolower($message), $params, $language);
    }
}

.. web.php "i18n" :

'components' => [
    'i18n' => [
        'class' => 'app\components\NewI18N', // Here it is
        'translations' => [
            'app*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@app/messages',
            ],
        ],
    ],
...

! Translator, Yii::t(), .

+6

Source: https://habr.com/ru/post/1680140/


All Articles