2017 © Pedro Peláez
 

library languages

image

rvadym/languages

  • Tuesday, February 11, 2014
  • by rvadym
  • Repository
  • 4 Watchers
  • 1 Stars
  • 170 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Language switcher add-on for atk4 with yaml file support. Add-on requires ATK version 4.3 or higher., (*1)


Installation:

  1. Add object to sandbox_addons.json and set such properties:, (*2)

    • "name": "rvadym/languages",
    • "addon_full_path": "../vendor/rvadym/languages",
    • "addon_symlink_name": "rvadym_languages",
    • "addon_public_symlink": "public/rvadym_languages"
  2. Configure add-on in config.php:, (*3)

All config settings must be placed into array :, (*4)

$config['rvadym']['languages'] = array(). If there is no option, it would set to default values., (*5)

You may use such options:, (*6)

  • 'languages' => array('en','ru','ua'), // list of used languages. Default: array('en')
  • 'default_language' => 'en', // Default: the first element of array 'languages'
  • 'switcher_type' => 'session', // 'session' or 'url'. Default: 'session'
  • 'translation_dir_path' => 'translations', // Directory of translation files. Relative to api dir path
  • 'store_type' => 'file', // file | db. Default: 'file'
  • 'model' ` => 'Translation', // if 'store_type' == db provide name of Model. Default: 'Translation'
  • 'view_class' => 'View_MyCustomView', // custom view class for switcher.
  • 'switcher_tag' => 'language_switcher_panel', // name of spot for template. Default: lang_switch
  • 'to_same_page' => true, // To set redirect to homepage after language changing set it to false.
  • 'var_name' => 'lang', // You can change name of $_GET variable. Same name will be used for session storage.
  • 'debug' => true, // Used to show untranslated words

Usage:

Place the line into frontend class init to add switcher :, (*7)

    $this->languages->addLangSwitcher($this);

You can also change look of switcher., (*8)

Extend your own switcher View from rvadym\languages\View_LanguageSwitcher and change template and method showSwitcher() . To use custom view for switcher you must set option in config.php or set second parameter of addLangSwitcher function (more priority)., (*9)

Value of View instances (View, H1, P etc.) would be translated automatically after set., (*10)

To translate value of wrapped elements like Text use "api->_('value')" or system message like confirmation:, (*11)

    $this->add('Text')->set($this->api->_('some value'));  //for text value
    $button->js('click')->univ()->confirm($this->api->_('Some process will be started. Continue?')));  //for confirmation

You can store translations in database or in yml files (use config 'store_type')., (*12)

To store in database you need to follow instructions above:, (*13)

  • use the sql model doc/languages.sql to create required tables
  • add every item from array languages as columns of databese table 'translation'. //Column 'en' is already set to table in script.

It would translate value of column 'value' to the value of chosen language column (like 'en')., (*14)

To customize model, extend it from Model_Translation., (*15)

Create page and extend it from rvadym\languages\page_langadmin to have a possibility to change translations, stored in database. Every tab on this page would be translated if it's value is added to translations., (*16)

//TODO: - make possible to select languages to be synchronized in langadmin page - make possible to use atk4-addons/dynamic_model to set language fields automatically during installation. - make UI view to use ui_name, (*17)

The Versions

11/02 2014

dev-master

9999999-dev https://github.com/rvadym/languages

  Sources   Download

atk4 language switcher