Internationalization tarantool data source allows use tarantool database for storing translate messages.
It will work as default message source
return [
'components' => [
'i18n' => [
'translations' => [
'*' => [
'class' => 'mhthnz\tarantool\i18n\MessageSource',
// 'db' => 'tarantool',
// 'enableCaching' => false,
// 'cache' => 'tarantoolCache',
],
],
],
],
]
Wildcard is allowed
return [
'components' => [
'i18n' => [
'translations' => [
'app*' => [
'class' => 'mhthnz\tarantool\i18n\MessageSource',
// 'db' => 'tarantool',
// 'enableCaching' => false,
// 'cache' => 'tarantoolCache',
],
],
],
],
]
- Set up tarantool migrations
- Then run i18n migrations
hostname@user:~$ php yii tarantool-migrate --migrationNamespaces=\\mhthnz\\tarantool\\i18n\\migrations
- Message table name
- Source message table name
- Table engine
Just create a new migration and inherit the migration class from \mhthnz\tarantool\i18n\migrations\m230401_092642_create_i18n_tables
:
class m230330_105111_create_i18n_tables extends \mhthnz\tarantool\i18n\migrations\m230401_092642_create_i18n_tables
{
public $engine = 'vinyl';
public $sourceMessageTable = '{{%another_source_message_table}}';
//.....
}
It works as other translation sources, check out docs link above
echo \Yii::t('app', 'translate msg');
// Using placeholders
$username = 'Alexander';
// display a translated message with username being "Alexander"
echo \Yii::t('app', 'Hello, {username}!', [
'username' => $username,
]);
// Specify another category
echo \Yii::t('app/user/registration', 'Thanks for registration!');
// Formatting placeholders
$price = 100;
echo \Yii::t('app', 'Price: {0,number,currency}', $price);
echo \Yii::t('app', 'Today is {0,date}', time());
// may produce "42 is spelled as forty-two"
echo \Yii::t('app', '{n,number} is spelled as {n,spellout}', ['n' => 42]);
$n = 3;
echo Yii::t('app', 'You are the {n,selectordinal,one{#st} two{#nd} few{#rd} other{#th}} visitor', ['n' => $n]);
// For English it outputs:
// You are the 3rd visitor