Skip to content

Commit f6bd6f8

Browse files
authored
Merge pull request #601 from jrafanie/clarify-string-extraction-methods-require-string-literals
Further clarify __() and friends expect string literals
2 parents adc0d77 + e13d33f commit f6bd6f8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

i18n.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,20 @@ will result in the whole
121121

122122
block being collected during string extraction by `yarn run gettext:extract`. Correctly, the `translate` directive should be placed inside the `span` element.
123123

124-
* **Don't use dynamic content inside `__()`**. For example, the following javascript code won't be collected correctly by `yarn run gettext:extract`.
124+
* **Don't use dynamic content inside `__()`**. The argument to `__()` should be a string literal. GNU gettext and libraries built on top of it, such as the Ruby and JavaScript gettext extractors, perform string extraction statically, so expressions, concatenation, interpolation, and other dynamically built values will not be collected correctly by `yarn run gettext:extract`.
125+
126+
For example, the following javascript code won't be collected correctly:
125127

126128
```javascript
127129
s = __(sprintf("My name is %s.", me.name));
130+
message = __('xyz' + 'abc');
128131
```
129132

130-
The above should correctly be:
133+
These examples should correctly be:
131134

132135
```javascript
133136
s = sprintf(__("My name is %s."), me.name);
137+
message = __("xyzabc");
134138
```
135139

136140
* **Don't apply the `translate` filter on a dynamic content**. The string inside would not be correctly extracted during string collection. For example the following won't be collected correctly by `yarn run gettext:extract`.

0 commit comments

Comments
 (0)