2017 © Pedro Peláez
 

module phalcon-translate

Translation module for Phalcon

image

transactpro/phalcon-translate

Translation module for Phalcon

  • Wednesday, August 31, 2016
  • by uLow
  • Repository
  • 3 Watchers
  • 7 Stars
  • 1,714 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 5 Versions
  • 5 % Grown

The README.md

Phalcon Translation Module

SensioLabsInsight, (*1)

Latest Version Total Downloads, (*2)

How it works:

This translation module is designed to be able to store/access any key in/from database. All translation map is accessible at any time without spawning new queries. There are three steps to match your key in translation map: - provided or default language - fallback language - key as it is, (*3)

Example #1:, (*4)

We have `test` key with value `Test value` in our translation map for English only. 

When we will ask for `test` with language key (`en` is enabled as fallback language):
    - en: `Test value`
    - de: `Test value`
    - ru: `Test value`
When we will ask for `test` with language key (without fallback language):
    - en: `Test value`
    - de: `test`
    - ru: `test`

Example #2:, (*5)

We have `test` key with value `Test value`/`Тестовое значение` in our translation map for English and Russian. 

When we will ask for `test` with language key (`en` is enabled as fallback language):
    - en: `Test value`
    - de: `Test value`
    - ru: `Тестовое значение`
    - without: `Test value`
When we will ask for `test` with language key (without fallback language):
    - en: `Test value`
    - de: `test`
    - ru: `Тестовое значение`
    - without: `Test value`

Installation

"require": {
    "transactpro/phalcon-translate": "~1.0"
}

Usage and Configuration

First of all you have to create translation table:

CREATE TABLE `translation` (
    `translation_id` INT(11) NOT NULL AUTO_INCREMENT,
    `language` VARCHAR(5) NOT NULL,
    `key_name` VARCHAR(48) NOT NULL,
    `value` TEXT NOT NULL,
    PRIMARY KEY (`translation_id`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM
AUTO_INCREMENT=1;

Set shared service translate to your Dependency Injection container, providing your translation model class name.

Example:, (*6)

$di->setShared('translate', function ($lang = false) use ($config, $di) {
    $adapter = new \TransactPro\Translation\Translate(
        TranslationModel::class,
        $lang
    );
    // setting default language that will be used when _() called without language parameter
    $adapter->setDefaultLanguage('en');
    // if fallback language is set, it will look in that translation map for value
    $adapter->setFallbackLanguage('de');
    /*
    * You can also provide them as options in third param array like:
    * [
    *   'default' => 'en',
    *   'fallback' => 'de'
    * ]
    */

    return $adapter;
});

You can add filter to your Volt or Twig.

Example:, (*7)

trans($key, $lang = null)
{
    $di = Di::getDefault();
    $translate = $di->getShared('translate');
    return $translate->_($key, $lang);
}

If your table (model) does not match to provided translation.sql

You can map your own columns as option set in third param array:, (*8)

$di->setShared('translate', function ($lang = false) use ($config, $di) {
    $adapter = new Translate(
        TranslationModel::class,
        $lang,
        [
          'languageColumn' => 'lang',
          'keyColumn' => 'lang-key',
          'valueColumn' => 'lang-value'
        ]
    );

    return $adapter;
});

The Versions

31/08 2016

dev-master

9999999-dev

Translation module for Phalcon

  Sources   Download

MIT

The Requires

  • ext-phalcon >=2.0

 

by Vitalijs Litvinovs

31/08 2016

1.0.2a

1.0.2.0-alpha

Translation module for Phalcon

  Sources   Download

MIT

The Requires

  • ext-phalcon >=2.0

 

by Vitalijs Litvinovs

28/10 2015

1.0.2

1.0.2.0

Translation module for Phalcon

  Sources   Download

The Requires

  • ext-phalcon ^2.0

 

by Vitalijs Litvinovs

14/07 2015

1.0.1

1.0.1.0

Translation module for Phalcon

  Sources   Download

The Requires

  • ext-phalcon ^2.0

 

by Vitalijs Litvinovs

14/07 2015

1.0.0

1.0.0.0

Translation module for Phalcon

  Sources   Download

The Requires

  • ext-phalcon ^2.0

 

by Vitalijs Litvinovs