PHP code example of stanislav-web / phalcon-translate
1. Go to this page and download the library: Download stanislav-web/phalcon-translate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stanislav-web / phalcon-translate example snippets
$loader->registerNamespaces([
'Translate\Translator' => 'path to src'
]);
$this->di['translate'] = function() {
return new Translate\Translator();
};
return [
'MY ACCOUNT' => 'My Account',
'LOGIN' => 'Log in',
'LOGOUT' => 'Log out',
'WELCOME' => 'Welcome, %s! We glad to see you! You are %d',
];
// 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
python
php composer.phar install
python
php composer.phar
/app/languages/{LANG}/{PART}.php
LANG meant "ru", "en", "de"
PART meant "menu", "header", "footer"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.