diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2018-01-25 13:36:04 +0000 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2018-01-25 13:36:04 +0000 |
commit | cba72369592c3ac29d304f9aa72c30bb5f6af412 (patch) | |
tree | 7ac43406704da0410382c1c36f27e357c58e3b55 | |
parent | 1f5af51b476a36a72759e7560c125c2b9602b145 (diff) | |
download | gitlab-ce-winh-sprintf-no-escape.tar.gz |
Document example for sprintf without escapingwinh-sprintf-no-escape
-rw-r--r-- | doc/development/i18n/externalization.md | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/doc/development/i18n/externalization.md b/doc/development/i18n/externalization.md index f493ad4ae66..b2a2eef216d 100644 --- a/doc/development/i18n/externalization.md +++ b/doc/development/i18n/externalization.md @@ -211,10 +211,18 @@ There is also and alternative method to [translate messages from validation erro - In JavaScript: ```js - import { __, sprintf } from '../../../locale'; + import { __, sprintf } from '~/locale'; sprintf(__('Hello %{username}'), { username: 'Joe' }) => 'Hello Joe' ``` +By default, `sprintf` escapes the placeholder values. +If you want to take care of that yourself, you can pass `false` as third argument. + + ```js + import { __, sprintf } from '~/locale'; + sprintf(__('This is %{value}'), { value: '<strong>bold</strong>' }, false) => 'This is <strong>bold</strong>' + ``` + The placeholders should match the code style of the respective source file. For example use `%{created_at}` in Ruby but `%{createdAt}` in JavaScript. |