PHP code example of davidpersson / li3_translate

1. Go to this page and download the library: Download davidpersson/li3_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/ */

    

davidpersson / li3_translate example snippets


// ...
class Artists extends \lithium\data\Model {

   use li3_behaviors\data\model\Behaviors;

   protected static $_actsAs = [
       'Translatable' => [
           'default' => 'ja',
           'locales' => ['en', 'it', 'ja'],
           'fields' => ['name']
       ]
   ];
	
   // ...

$user = Users::create([
	'profile' => 'Dreaded Rasta',
	'name' => 'Richard',
	'i18n.name.it' => 'Ricardo'
]);

$user = Users::create([
	'name' => 'Richard',
	'profile' => 'Dreaded Rasta',
	'i18n' => [
		'name' => [
			'it' => 'Ricardo'
		]
	]
]);

$user = Users::create([
	'profile' => 'Dreaded Rasta', 
	'name' => 'Richard'
]);
$user->translate('name', 'it', 'Ricardo');

$user = Users::find('first', ['conditions' => ['name' => 'Richard']]);

$user->save([
	'i18n.name.it' => 'Ricardo'
]);

// ... or ...

$user->translate('name', 'it', 'Ricardo');
$user->save();

$user = Users::find('first', [
	'conditions' => ['i18n.name.it' => 'Ricardo']
]);

$user = Users::find('all', [
	'order' => ['i18n.name.it' => 'ASC']
]);

$user = Users::find('first', [
	'conditions' => ['id' => 23],
	'translate' => 'it'
]);

$user->name; // returns 'Ricardo'.

$user = Users::find('first', [
	'conditions' => ['name' => 'Richard'], 
	'translate' => false
]);

$user->save(null, ['translate' => false]);

$user = Users::find('first', ['conditions' => ['name' => 'Richard']]);

$user->translate('name', 'it'); // returns 'Ricardo';
$user->translate('name'); // returns ['en' => 'Richard', 'it' => 'Ricardo'];
$user->name; // returns 'Richard', as the default locale is `en`.

$user = Users::create([
	'profile' => 'Dreaded Rasta', 
	'name' => 'Richard'
]);
$user->validate(['translate' => false]);