2017 © Pedro Peláez
 

yii2-extension yii2-dot-translation

Yii2: Component that translates short texts

image

pavlinter/yii2-dot-translation

Yii2: Component that translates short texts

  • Wednesday, February 28, 2018
  • by pavlinter
  • Repository
  • 1 Watchers
  • 2 Stars
  • 464 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

Yii2 Dot Trasnlation

Screen Shot, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist pavlinter/yii2-dot-translation "*"

or add, (*4)

"pavlinter/yii2-dot-translation": "*"

to the require section of your composer.json file., (*5)

Configuration

  • Run migration file, (*6)

    yii migrate --migrationPath=@vendor/pavlinter/yii2-dot-translation/migrations
    
  • Update config file, (*7)

'bootstrap' => [
   'i18n',
   ...
],
'components' => [
    'i18n' => [
        'class'=>'pavlinter\translation\I18N',
        //'translations' => [
            //'myCategory' => [
                //'class' => 'pavlinter\translation\DbMessageSource',
                //'forceTranslation' => true,
                //'autoInsert' => true, //if message key doesn't exist in the database, message key will be created automatically
                //'dotMode' => null, //default state: show or hide dot
            //],
        //],
        //default settings

        //'dialog' => 'bs', //Bootstrap Modal Or jQuery Dialog (bs or jq)
        //'access' => 'dots-control',  //user permissions or function(){ return true || false; }
        //'nl2br' => true,
        //'dotClass' => 'dot-translation',
        //'dotSymbol' => '•',
        //'nl2br' => true //nl2br filter text
        //languages table
        //'langTable' => '{{%languages}}', //string || null if table not exist
        //'langColCode' => 'code',
        //'langColLabel' => 'name',
        //'langColUpdatedAt' => 'updated_at', //string || null
        //'langWhere' => ['active' => 1], //$query->where(['active' => 1]);
        //'langOrder' => 'weight', //$query->orderBy('weight');

        //'enableCaching' => true, //for langTable cache
        //'durationCaching' => 0, //langTable cache
        //'router' => '/site/dot-translation', //'site' your controller
        //'langParam' => 'lang', // $_GET KEY
    ],
    ...
],
  • Update controller
//SiteController.php
public function actions()
{
    return [
        'dot-translation' => [
            'class' => 'pavlinter\translation\TranslationAction',
            //'adminLink' => null;  //array|string|function
            //'htmlEncode' => true, //encode new message
            //'access' => null, //default Yii::$app->i18n->access
        ],
        ...
    ];
}

Usage

Change language:, (*8)

/index.php?r=site/index&lang=ru

Example:, (*9)


echo Yii::t('app', 'Hello world.'); used global settings //individual adjustment echo Yii::t('app', 'Hi {username}.', ['username' => 'Bob', 'dot' => true]); //enable dot echo Yii::t('app', 'Hello world.', ['dot' => false , 'nl2br' => false]); //or 'br' => false //disable dot and disable nl2br filter echo Html::submitInput(Yii::t('app', 'Submit', ['dot' => false])); //disable dot echo Yii::$app->i18n->getPrevDot(); // show previous dot // Or echo Yii::t('app', 'Submit', ['dot' => '.']); //show only dot
Yii::$app->i18n->disableDot(); //force disable all dots

echo Yii::t('app', 'Submit'); //hidden dot
echo Yii::t('app', 'Submit', ['dot' => true]); //force enable dot

Yii::$app->i18n->resetDot(); //reset settings
Yii::$app->i18n->enableDot();//OR enable dot
//Add description variables to popup.
echo Yii::t('app', 'Count: ', ['dot' => true, 'var' => ['count' => 'Count email', 'owner']]);
//render languages
echo \yii\widgets\Menu::widget([
    'items' => Yii::$app->i18n->menuItems(),
    'encodeLabels' => false,
]);
//get array with current url
Yii::$app->i18n->getLanguages(true); //true|callable
/*
Array
(
    [1] => Array
    (
        [id] => 1
        [code] => en
        [name] => English
        [image] => /files/en.png
        [weight] => 130
        [active] => 1
        [updated_at] => 1424504802
        [url] => /en/site/index
    )
    ...
)
*/

The Versions

28/02 2018

dev-master

9999999-dev

Yii2: Component that translates short texts

  Sources   Download

BSD-3-Clause BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

28/02 2018

v2.1.0

2.1.0.0

Yii2: Component that translates short texts

  Sources   Download

BSD-3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

25/12 2017

v2.0.3

2.0.3.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

19/08 2017

v2.0.2

2.0.2.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

31/10 2016

v2.0.1

2.0.1.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

16/08 2016

v2.0.0

2.0.0.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

14/08 2016

2.0.0-beta1

2.0.0.0-beta1

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

17/06 2016

v1.4.0

1.4.0.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

21/02 2016

v1.3.0

1.3.0.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

02/10 2015

v1.2.3

1.2.3.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

14/09 2015

v1.2.2

1.2.2.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

29/07 2015

v1.2.1

1.2.1.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

16/03 2015

v1.2.0

1.2.0.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

14/02 2015

v1.1.1

1.1.1.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

09/02 2015

v1.1.0

1.1.0.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation

13/01 2015

v1.0.0

1.0.0.0

Yii2: Component that translates short texts

  Sources   Download

BSD 3-Clause

The Requires

 

by Pavels Radajevs

dot component yii2 translation