2017 © Pedro Peláez
 

yii2-extension yii2-babelfishfood

Language switching companion of the Yii2 Babelfish symbiote

image

oorrwullie/yii2-babelfishfood

Language switching companion of the Yii2 Babelfish symbiote

  • Wednesday, August 16, 2017
  • by mmelcor
  • Repository
  • 2 Watchers
  • 1 Stars
  • 33 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

Babel Fish Food

Language switching companion of the Yii2 Babelfish symbiote. It can also be used as a complete stand alone solution to get i18n support up and running quickly for any site built using the standard Yii2 advanced template., (*1)

Key Features

  • Pre-populated database of 115 languages and dialects to get started quickly. (You can add more using the CRUD or with migrations.) Simply change the active property of the language to add or drop support for the language.
  • Configured to use GetText po files out of the box. (Can be switched to add support for database based translations.)
  • Detects preferred language based on browser preferences.
  • Language switching widget displays languages in native format with native alphabet.
  • Widget saves language as a cookie for guests and in the User table for logged in users.
  • Complete CRUD implementation for administration of languages.

Installation

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

Either run, (*3)

php composer.phar require --prefer-dist oorrwullie/yii2-babelfishfood "*"

or add, (*4)

"oorrwullie/yii2-babelfishfood": "*"

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

Configuration

Once the extension is installed :, (*6)

Create the languages table and add language column to your database:, (*7)

php yii migrate --migrationPath=@vendor/oorrwullie/yii2-babelfishfood/migrations

You select supported languages using the active column for that language in the database. We recommend writing a migration to update your active languages, and turn off any of the default that you are not using., (*8)

Configure the component in common/config/main.php:, (*9)


'components' => [ 'babelfishfood' => [ 'class' => 'oorrwullie\babelfishfood\components\BFFComponent', 'cookieName' => 'language', // Name of the cookie. 'cookieDomain' => 'example.com', // Domain of the cookie. 'expireDays' => 64, // The expiration time of the cookie is 64 days. 'callback' => function() { if (!\Yii::$app->user->isGuest) { $user = \Yii::$app->user->identity; $user->language = \Yii::$app->language; $user->save(); } } ] ]

You need to bootstrap the component for each app you would like translations to work like so: In frontend/config/main.php, (*10)

'language' => 'en',
'bootstrap' => ['babelfishfood'],

Do the same in the backend if you would like to have the switcher there too., (*11)

Configure translation extraction:, (*12)

The i18n section needs to be filled in like so: in common/config/main.php, (*13)

'i18n' => [
    'translations' => [
    'menu*' => [
        'class' => 'yii\i18n\GettextMessageSource',
        'useMoFile' => false,
        'basePath' => '@common/messages',
    ],
    'home*' => [
        'class' => 'yii\i18n\GettextMessageSource',
        'useMoFile' => false,
        'basePath' => '@common/messages',
    ],
    'base*' => [
        'class' => 'yii\i18n\GettextMessageSource',
        'useMoFile' => false,
        'basePath' => '@common/messages',
    ],
    'global*' => [
        'class' => 'yii\i18n\GettextMessageSource',
        'useMoFile' => false,
        'basePath' => '@common/messages',
    ],
    ],
],

To use the built-in CRUD to administrate languages, add the following to backend/config/main.php:, (*14)

'modules' => [
    'bff' => [
    'class' => 'oorrwullie\babelfishfood\BabelFishFood',
    ],
],

Implementation

Designating text to be translated, (*15)

Wrap text to be translated like so:, (*16)

echo \Yii::t('app', 'This is a string to translate!');

To compile translations into po files, navigate to your project toot and run:, (*17)

./yii message/extract @oorrwullie/babelfishfood/config/i18n.php

The above command is a bit long. There is a bash script in oorrwullie/yii2-babelfishfood named i18n. You can copy that to your project root and update translations by running:, (*18)

./i18n

To use the widget in a view:, (*19)

<?= \oorrwullie\babelfishfood\BFF::widget(); ?>

You can change the label of the dropdown widget (defaults to "Languages: ") and languages can either be normal or uppercase (defaults to uppercase). For example:, (*20)

<?= \oorrwullie\babelfishfood\BFF::widget([
    'upperCase' => FALSE,
    'label' => '<i class="fa fa-language"></i>',
]); ?>

To use the CRUD:, (*21)

Navigate to your backend url + bff like so: www.example.com/backend/bff, (*22)

The Versions

16/08 2017

dev-add-insomnia-to-user-agents

dev-add-insomnia-to-user-agents

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

20/07 2017

dev-master

9999999-dev

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

20/07 2017

0.7.3

0.7.3.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

20/07 2017

0.7.4

0.7.4.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

20/07 2017

0.7.2

0.7.2.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

02/06 2017

0.7.1

0.7.1.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

18/05 2017

0.7.0

0.7.0.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

18/05 2017

0.7-beta

0.7.0.0-beta

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

14/02 2017

0.6.3

0.6.3.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

14/02 2017

0.6.2

0.6.2.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

14/02 2017

0.6.1

0.6.1.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

13/02 2017

0.6

0.6.0.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish

13/02 2017

0.5

0.5.0.0

Language switching companion of the Yii2 Babelfish symbiote

  Sources   Download

MIT

The Requires

 

by Kevin Payne

language extension yii2 widget translation i18n babelfish