aralroca / next-translate

Next.js plugin + i18n API for Next.js 🌍 - Load page translations and use them in an easy way!
MIT License
2.66k stars 206 forks source link

Can the translation variable delimiters be configured? #330

Closed josephfarina closed 3 years ago

josephfarina commented 3 years ago

It seems like translation variables are currently wrapped in {{variable}}. Is this configurable to something like %{variable}?

josephfarina commented 3 years ago

I'd be happy to make a PR to support this — if it is not already.

aralroca commented 3 years ago

@josephfarina for now the interpolation prefix and suffix are limited to only {{ and }}, here's the code:

I think it's good to give the opportunity to be configurable. So, if you want to go ahead with your PR, you are welcome to do so. Thank you very much!

josephfarina commented 3 years ago

Hey again @aralroca, do you have any suggestion of how to access the i18n.js config file here?

https://github.com/vinissimus/next-translate/blob/5f27c864189455382a5c98f20debc23208acd798/src/I18nProvider.js#L44-L45

IMO this option should be supported similar to how i18next does it with an interpolation.prefix and interpolation.suffix option in the config file:

https://www.i18next.com/translation-function/interpolation#additional-options

This is also a necessity for Smartling btw. They require the delim to be: %{ }

aralroca commented 3 years ago

@josephfarina You have made me realize that it is a bit cumbersome to use the settings inside I18nProvider. I've done a PR to fix this, so now you can consume the configuration:

https://github.com/vinissimus/next-translate/pull/369/files#diff-ea0a179cd243269347b1b4d033a6bfd270e19e2a319af583c8c318b1040d3bcaR112

josephfarina commented 3 years ago

Thanks @aralroca that made it really easy

aralroca commented 3 years ago

Nice! @josephfarina I prereleased 1.0.0-canary.4 with this change