diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-01-03 12:12:55 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-03 12:12:55 -0500 |
commit | 8e304b83c685dde17a00d402877a21303b7c11f2 (patch) | |
tree | 0b2123575502c3e3cb5127582b03e9c196c9891d /test/test-translator.js | |
parent | eda8534e195d653ee0dea36f70caed0d8d49acf1 (diff) |
Translator regex replacements (#1199)
* Add support for regex replacements during the translation process
* Allow assignment of textReplacements
* Rename
* Set up test data
* Write expected data
* Set up options
* Prevent infinite loop if regex matches empty string
* Implement setting controller
* Add support for testing pattern replacements
Diffstat (limited to 'test/test-translator.js')
-rw-r--r-- | test/test-translator.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/test-translator.js b/test/test-translator.js index 892448a5..cee7fe16 100644 --- a/test/test-translator.js +++ b/test/test-translator.js @@ -107,6 +107,16 @@ function buildOptions(optionsPresets, optionsArray, dictionaryTitle) { } } + // Construct regex + if (Array.isArray(options.textReplacements)) { + options.textReplacements = options.textReplacements.map((value) => { + if (Array.isArray(value)) { + value = value.map(({pattern, flags, replacement}) => ({pattern: new RegExp(pattern, flags), replacement})); + } + return value; + }); + } + // Update structure const placeholder = '${title}'; if (options.mainDictionary === placeholder) { |