You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> This plugin was inspired by[webpack-extract-translation-keys](https://github.com/grassator/webpack-extract-translation-keys). It works in a completely different way, but it shares the concept and some of the source code, so I leave the original copyright info in files.
3
+
> This plugin is based on[webpack-extract-translation-keys](https://github.com/grassator/webpack-extract-translation-keys). It works in a completely different way, but it shares the concept and some of the source code, so I leave the original copyright info in files.
4
4
5
5
Webpack provides an official plugin for managing translation using [i18n-webpack-plugin](https://github.com/webpack/i18n-webpack-plugin), but in only allows for build-time translations by replacing strings in the source code.
This should be a regular expression object or simply a string. Plugin will internally enforce "g" and "m" flags on the provided regexp.
123
123
124
-
The expression must have at least one outputting group block. By default the first group block one is considered to be the translation key.
124
+
The expression must have at least one outputting group block.
125
+
126
+
By default the first and third group block one is considered to be the translation key. That's because of the default `functionPattern` that matches two versions of `gettext` - with `"` and `'` quotes used.
127
+
125
128
You can change this to be any block by modifying the `groupIndex` option.
126
129
127
130
#### - `groupIndex`
128
131
129
-
Default value: 1
132
+
Default value: [1, 3]
130
133
131
-
Specifies which group block from `functionPattern` contains the translation key.
134
+
Specifies which group block from `functionPattern` contains the translation key. This can be integer or array of integers.
135
+
136
+
If multiple indexes are provided - the first group which returns a value will be used. At least one group must return value unless plugin will throw an error.
132
137
133
138
#### - `moduleFilter`
134
139
@@ -247,10 +252,12 @@ Enables mangling of translation keys. When enabled the `functionReplace` option
247
252
248
253
#### - `functionReplace`
249
254
250
-
Default value: `gettext($2$1$2`
255
+
Default value: `gettext($2$4$1$3$2$4`
251
256
252
257
This option specifies the replacement for the `functionPattern` when mangling translation keys. It is required if you use mangling.
253
258
259
+
Please note that if some group returns `undefined` it is changed to empty string, so you can easily use output from multiple groups even if they don't match anything in the string.
260
+
254
261
You can also use this option to change the function name if you like to.
newError("ExtractTranslationRegexPlugin: The provided `functionPattern` regular expression do not contain capture block. Please check your webpack.config.js file.")
0 commit comments