Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Updated another way of string translation in js #8098

Merged
merged 7 commits into from
Nov 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ To ensure that the text you add in a `.js` file is collected by the i18n tool an
1. Link the `mage/translate` library:

```javascript
define (['jquery', 'mage/translate'], function ($) {...});
define (['jquery', 'mage/translate'], function ($, $t) {...});
```

1. Use the `$.mage.__('')` function when adding a string:
Expand All @@ -134,12 +134,24 @@ To ensure that the text you add in a `.js` file is collected by the i18n tool an
$.mage.__('<string>');
```

If your string contains a variable, to add a placeholder for this variable to the string stored in the dictionary, use the syntax similar to the following:
or

```javascript
$t('<string>');
```

If your string contains a variable, to add a placeholder for this variable to the string stored in the dictionary, use the following syntax:

```javascript
$.mage.__('Hello %1').replace('%1', yourVariable);
```

or

```javascript
$t('Hello %1').replace('%1', yourVariable);
```

In this example, the `'Hello %1'` string is added to the dictionary when the i18n tool is run.

[i18n tool]: {{page.baseurl}}/config-guide/cli/config-cli-subcommands-i18n.html
Expand Down