Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
systems:yii2:internationalization_i18n [2018/04/11 15:52]
smayr [Models]
systems:yii2:internationalization_i18n [2018/04/11 17:38] (current)
smayr [Controllers]
Line 215: Line 215:
 In the controller, all string to be displayed need to include the ''Yii::t(...)'' notation. eg: In the controller, all string to be displayed need to include the ''Yii::t(...)'' notation. eg:
 <code php> <code php>
 +// Basic Messages
 +echo Yii::t('app', 'User List');
 +
 // Messages can contain parameter placeholders which will be replaced  // Messages can contain parameter placeholders which will be replaced 
 // with the actual parameter values when calling Yii::t(). For example,  // with the actual parameter values when calling Yii::t(). For example, 
 // the following message translation request would replace  // the following message translation request would replace 
 // the {alias} placeholder in the original message with the actual alias value. // the {alias} placeholder in the original message with the actual alias value.
-Yii::t('app', "Unable to view user ID {id}'s profile.", ['{id}' => $id]);+echo Yii::t('app', "Unable to view user ID {id}'s profile.", ['id' => $id]); 
 + 
 +// Positional placeholders 
 +$price = 100; 
 +$count = 2; 
 +$subtotal = 200; 
 +echo \Yii::t('app', 'Price: {0}, Count: {1}, Subtotal: {2}', [$price, $count, $subtotal]); 
 +echo \Yii::t('app', 'Price: {0}', $price);
 </code> </code>
 +
 +See more formatting and placeholders: [[https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n|Tutorial i18n]]
 == Detecting Language Automatically == == Detecting Language Automatically ==