Closed vricosti closed 2 years ago
Maybe this would be a solution:
// "methodNamesRegExp" must be validated not to contain "(", ")" or ":" ... and more?
const methodNamesRegExp = 't[cm]?';
// default RegExp: /(?:[$\s.:"'`+\(\[\{]t[cm]?)\(\s*?(["'`])((?:[^\\]|\\.)*?)\1/g;
const regExpStr = `(?:[$\\s.:"'\`+\\(\\[\\{]${methodNamesRegExp})\\(\\s*?(["'\`])((?:[^\\\\]|\\\\.)*?)\\1`;
const methodRegExp = new RegExp(regExpStr, "g");
The methodNamesRegExp
would be the parameter passed to extractMethodMatches
.
Allowing a custom RegExp-part is a mighty thing - and error-prone. Maybe the mentioned RegExp validation is not enough.
Yeah we've grappled with adding custom Regex's before and because @pixari and I only have a small amount of time to maintain this project we've decided that it's best if we focus the scope of this project to the most common use cases of i18n, sorry! But feel free to fork the project!
Hi, @Spittal I understand your point about focusing on the most common use cases, and I would also hear you that this change may open a pandora box : "if this feature pass, why this one won't ?". However, I think the ability to allow other function names is not a huge addition, an would benefit a lot of projects. It would allow wrappers, and also defining keys elsewhere, like with a noop function. The other point is that the current regex is quite unreadable, and having a variable to represent the part matching the name may be cleaner.
I myself really need this feature, so if I may, I would like to ask this question : if I make a PR with unit tests, would it be rejected without review on the principle stated above, or would you rethink about it and may be reconsider your position on the subject ?
(I also know I can fork, but well, I may have the time to maintain a small modification, but not the time to keep track of changes on the mother project...)
I am not satisfied by the default behavior of vue-i18n and when a language has an empty translation I would like to display the key. So I wrote the following plugin:
So I am declaring a $T function but in this case vue-18n-extract does not work, would it be possible to add an option methodName for instance where we could specify the name of the method ?
The change would be something like:
I haven't tested yet but I have a branch here: feat/AddOptionToSpecifyMethodName