PART 1.2.7 – Translations

Theme translations

A theme dictionary can be added inside the i18n folder of your theme:

i18n/en_US.csv 

i18n/sv_SE.csv 

Templates

<h3><?php echo __(‘Create Backup’) ?></h3>

String containing variable: <h3><?php echo sprintf(__(‘Hello %s’), $yourVariable) ?></h3>

Knockout templates

When a string is added in the scope of an HTML element:

<span data-bind=“i18n: ‘Sign In'”></span>

 

When a string is added with no binding to an HTML element:

<!– ko i18n: ‘You have no items in your shopping cart.’ –><!– /ko –>

Strings in js

Define mage translate to be able to use it:

define ([‘jquery’, ‘mage/translate’], function ($) {…});

 

 Then use “$.mage.__” before the string to be translated:

$.mage.__(‘<string>’);

 

If a variable is included:

$.mage.__(‘Hello %1’).replace(‘%1’, yourVariable);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s