PHP code example of gossi / propel-l10n-behavior

1. Go to this page and download the library: Download gossi/propel-l10n-behavior 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/ */

    

gossi / propel-l10n-behavior example snippets


PropelL10n::setLocale('de');

echo PropelL10n::getLocale(); // de

$book = new Book();
$book->setLocale('ja');

$book->setLocale(null);

PropelL10n::setLocale('it');
$book = BookQuery::create() // locale: it
	->setLocale('ja') // locale: ja
	->findOneByTitle('Herr der Ringe', null, 'de') // locale: de
;
$book->setLocale('ja');
$book->setTitle('Lord of the Rings', 'en');

PropelL10n::setFallback('de');

echo PropelL10n::getFallback(); // de

// get and set one dependency
PropelL10n::addDependency('de-CH', 'de');
echo PropelL10n::getDependency('de-CH'); // de

// get and set all dependencies
PropelL10n::setDependencies([
	'de'	=> 'en',
	'de-CH' => 'de',
	'de-AT' => 'de'
]);
print_r(PropelL10n::getDependencies()); // outputs the array from above

// check if dependencies exist
PropelL10n::hasDependency('de'); // true
PropelL10n::hasDepdedency('ja'); // false

// count depdencies for a given locale
PropelL10n::setDependencies(['de' => 'en', 'de-CH' => 'de']);
PropelL10n::countDependencies('de-CH'); // 2

PropelL10n::setLocale('de'); // this is mostly the language a user decided to use
PropelL10n::setFallback('en'); // that's the default language of your app
PropelL10n::setDependencies([ // that's the locales you have available
	'de'	=> 'en'
	'de-CH' => 'de',
	'de-AT' => 'de',
	'ja' => 'en'
]);

$book = new Book();
$book->setTitle('Lord of the Rings');
$book->setLocale('de');
$book->setTitle('Herr der Ringe');
$book->setLocale(null);

echo $book->getTitle(); // Lord of the Rings - using the default locale (`en`)
echo $book->getTitle('de-DE'); // Herr der Ringe
$book->setLocale('de-DE');
echo $book->getTitle(); // Herr der Ringe
echo $book->getTitle('ja-JP'); // Lord of the Rings - using fallback locale (`en`)

// default locale: de

// contains all books with a german title starting with 'Harry Potter'
$books = BookQuery::create()
	->filterByTitle('Harry Potter%')
	->find();
$books = ...; 

// the book lord of the rings as searched with an english title name
$book = BookQuery::create()
	->findOneByTitle('Lord of the Rings', null, 'en');
$book = ...; 

// all harry potter books searched with the japanese title
$books = BookQuery::create()
	->setLocale('ja') 				// overwrites query default locale
	->findByTitle('Harī Pottā%');
$books = ...;

// find lord of the rings with the japanese title, overwrite locale with the filter method
$book = BookQuery::create()
	->findOneByTitle('Yubiwa Monogatari', null, 'ja');
$book = ...;