intlify / vue-i18n

Vue I18n for Vue 3
https://vue-i18n.intlify.dev/
MIT License
2.21k stars 337 forks source link

Fetching a message without compilation #1884

Open thany opened 5 months ago

thany commented 5 months ago

Clear and concise description of the problem

We need regexes in our translation files, for localised validation of things. Regexes are already annoying to read, and having to put extra encoding in them makes them even less readable.

Suggested solution

A way to fetch a translation message, without attempting to "compile" it. It should ignore all special characters in it, and just return the string exactly as-is, without processing or compilation. This could be a switch in the TranslationOptions object that is given in the t function, since compilation appears to occur just-in-time, e.g. when a message is fetched.

Alternative

Like I said, it would require annoying encoding in a string that is already hard to read:

\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{8,14}$|0[89]0[069]d{4,7}$|07[078]d{6}$

Would need to become, well, I dunno what exactly. A even uglier monster 🙂 I'm not convinced that changing all regexes is a viable alternative, but it is technically an alternative.

I guess for now we should rather hardcode regexes into the application, but having a workaround should not demotivate finding a solution.

Additional context

Might be helpful to know that this had worked fine in version 8. We skipped 9, and when straight to 10 while upgrading to Vue 3.

Validations