diff options
author | Clement Ho <clemmakesapps@gmail.com> | 2018-04-11 17:55:28 +0000 |
---|---|---|
committer | Clement Ho <clemmakesapps@gmail.com> | 2018-04-11 17:55:28 +0000 |
commit | 8206cae781f4b69fc165638d8cc964d92df70740 (patch) | |
tree | a93caba430e2edf7e5654a402f3e1664570d66c2 | |
parent | ac2271f861d19b8a676614e5db68b1dbb3f74bea (diff) | |
parent | a58ddd7a9474a32a356ce8caf533e00e90ed64c6 (diff) | |
download | gitlab-ce-8206cae781f4b69fc165638d8cc964d92df70740.tar.gz |
Merge branch 'winh-sprintf-no-escape-docs' into 'master'
Document example for sprintf without escaping
See merge request gitlab-org/gitlab-ce!16712
-rw-r--r-- | doc/development/i18n/externalization.md | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/doc/development/i18n/externalization.md b/doc/development/i18n/externalization.md index 856ef882453..b1bec84a2f3 100644 --- a/doc/development/i18n/externalization.md +++ b/doc/development/i18n/externalization.md @@ -131,6 +131,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 @@ -141,11 +144,19 @@ There is also and alternative method to [translate messages from validation erro ```js import { __, sprintf } from '~/locale'; - sprintf(__('Hello %{username}'), { username: 'Joe' }) => 'Hello Joe' + + 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 <strong>bold</strong>' + sprintf(__('This is %{value}'), { value: '<strong>bold</strong>' }, false); // => 'This is <strong>bold</strong>' + ``` ### Plurals |