stanislav-web / phalcon-translate
Phalcon Translate Service. Simple way to translate your costom part of templates :-)
Installs: 292
Dependents: 1
Suggesters: 3
Security: 0
Stars: 12
Watchers: 3
Forks: 3
Open Issues: 1
Language:HTML
Requires
- php: >=5.4.0
Suggests
- stanislav-web/phalcon-searcher: Phalcon Database Searcher. This is the search service is designed to search multiple SQL tables. Convenient to use autocomplete, search documents, search the whole site.
- stanislav-web/phalcon-ulogin: Phalcon ULogin. The authorization form uLogin through social networks
- stanislav-web/phalcon-uploader: Phalcon files uploader. Handling and downloading files for Phalcon projects. Allowed multiple files download, filters etc...
This package is not auto-updated.
Last update: 2024-12-21 17:27:57 UTC
README
Phalcon Translate Service. Simple way to translate your costom part of templates :-)
Changelog
- 1.3.1 [FIX] Default language use
- 1.3 [FIX] Support for Phalcon 2.x // [Minor fix] Translate Adapter Native offsetGet is not work on 2.0
- 1.2 [FIX, FEATURE] The ability to reuse a set of translations in various services
- 1.1 Added setDefault() method to watch undefined languages
Compatible
- PSR-1, PSR-2, PSR-4 Standards
System requirements
- PHP 5.4.x >
- Phalcon extension 1.3.x, 2.x
Install
First update your dependencies through composer. Add to your composer.json:
"require": { "stanislav-web/phalcon-translate": "1.*" }
php composer.phar install
OR
php composer.phar require stanislav-web/phalcon-translate 1.*
(Do not forget to include the composer autoloader)
Or manual require in your loader service
$loader->registerNamespaces([ 'Translate\Translator' => 'path to src' ]);
You can create an injectable service
$this->di['translate'] = function() { return new Translate\Translator(); };
Usage
recomended configuration for translate directory (as example)
/app/languages/{LANG}/{PART}.php
LANG meant "ru", "en", "de"
PART meant "menu", "header", "footer"
files for translation
<?php return [ 'MY ACCOUNT' => 'My Account', 'LOGIN' => 'Log in', 'LOGOUT' => 'Log out', 'WELCOME' => 'Welcome, %s! We glad to see you! You are %d', ];
configuration and use
// get translate service $translate = $this->di->get('translate'); // forward slash must be... // lang can get from headers or cookies $translate->setTranslatePath('/app/Modules/Frontend/languages/')->setLanguage('en'); // 1.1-stable Added setDefault() method to watch undefined languages $translate->setDefault('en'); // so now you have a directory for "English".. // Next you need to choise a part of translate. // I do something like this $this->view->setVars('t', $translate); // ... in my view or layout i get a part of translate echo $t->assign('menu')->translate('MY ACCOUNT'); // My Account // or use otherwise $this->partial('sidebar', ['t' => $t->assign('sidebar')]); echo $t->translate('LOGIN'); // translate by template variable printf($t->translate('WELLCOME'), 'User', 100); // Output: Welcome,User! We glad to see you! You are 100
##Issues