feat(provider-deepl): omit placeholders plugin option #487
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Adds an optional boolean
omitPlaceholders
provider option for the DeepL Provider that handles text inside double curly brackets, that can be used as placeholders or variable text.Asked by #484 , but I also had the same need with collaborators on Strapi that want to mass translate text with those {{text}} inside.
Explanation
Replicated the process explained in the example provider by Deepl:
https://developers.deepl.com/docs/resources/examples-and-guides/placeholder-tags
https://github.com/DeepLcom/deepl-python/blob/main/examples/mustache/README.md
Steps:
When
omitPlaceholders
istrue
⬅️ Before the translation: it creates and fills a temporary
placeholderTexts
array that contains the text that should be kept, while replacing the text with a simple<m id=xx />
tag to keep the position of the placeholder in the text.➡️ After the translation: it replaces back the tags with the original text thanks to the index saved inside the tag id.