summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2018-01-25 13:36:04 +0000
committerWinnie Hellmann <winnie@gitlab.com>2018-02-14 21:45:32 +0100
commit66b97d1875008048c5d2ef971912fe4341e9905f (patch)
tree1b7a8c288e264bced83cc2583d4c7955ea5c0e9d
parentdd633bc1888453a07474d045eca91a9e66302ce0 (diff)
downloadgitlab-ce-winh-sprintf-no-escape-docs.tar.gz
Document example for sprintf without escapingwinh-sprintf-no-escape-docs
-rw-r--r--doc/development/i18n/externalization.md19
1 files changed, 15 insertions, 4 deletions
diff --git a/doc/development/i18n/externalization.md b/doc/development/i18n/externalization.md
index c0a325a83e9..f521cb24fc7 100644
--- a/doc/development/i18n/externalization.md
+++ b/doc/development/i18n/externalization.md
@@ -207,6 +207,9 @@ There is also and alternative method to [translate messages from validation erro
### Interpolation
+Placeholders in translated text should match the code style of the respective source file.
+For example use `%{created_at}` in Ruby but `%{createdAt}` in JavaScript.
+
- In Ruby/HAML:
```ruby
@@ -216,12 +219,20 @@ There is also and alternative method to [translate messages from validation erro
- In JavaScript:
```js
- import { __, sprintf } from '../../../locale';
- sprintf(__('Hello %{username}'), { username: 'Joe' }) => 'Hello Joe'
+ import { __, sprintf } from '~/locale';
+
+ sprintf(__('Hello %{username}'), { username: 'Joe' }); // => 'Hello Joe'
```
-The placeholders should match the code style of the respective source file.
-For example use `%{created_at}` in Ruby but `%{createdAt}` in JavaScript.
+ 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>' }); // => 'This is &lt;strong&gt;bold&lt;/strong&gt;'
+ sprintf(__('This is %{value}'), { value: '<strong>bold</strong>' }, false); // => 'This is <strong>bold</strong>'
+ ```
### Plurals