dkfbasel / vuex-i18n

Localization plugin for vue.js 2.0 using vuex as store
MIT License
666 stars 56 forks source link

Using square brackets in identifier does not work #117

Open djtsov opened 4 years ago

djtsov commented 4 years ago

I want to use the square brackets for parameters in translation strings, for example, 'This is my [project]'. And for that aim I add the {identifier: ['[',']']} as the config parameter for initialize vuex-i18n. But unfortunately when I try to get a translation by this.$i18n.translate('mykey', {'project': 'test' }) , I get 'This is my [project]' instead 'This is my test'. But when I replace the square brackets to braces (e.g. 'This is my {project}') then all works as expected. P.S. When I use the square brackets(!) then the this.$i18n.translate('mykey', {'project': 'test' }) stops to work for strings used the braces 'This is my {project}', i.e. the identifier was changed for another symbol.

djtsov commented 4 years ago

As I understood, for using the the square brackets in regular expressions, it's needed to use follow identifier: ["\\[","\\]"]. But then this line works wrong: var key = placeholder.replace(identifiers[0], '').replace(identifiers[1], ''); because translate string contains the single brackets, but identifier[0] is '[' and identifier[1] is ']'.

tikiatua commented 4 years ago

Hi @djtsov

Thank you for your feedback. I will look into this. The syntax of the identifiers is probably not correct yet.