lokalise / i18n-ally

🌍 All in one i18n extension for VS Code
https://marketplace.visualstudio.com/items?itemName=lokalise.i18n-ally
MIT License
3.89k stars 307 forks source link

Support custom namespace delimiters #736

Open ziofat opened 2 years ago

ziofat commented 2 years ago

Is your feature related to a specific framework or general for this extension

i18next, but I think it is general

Is your feature request related to a problem? Please describe.

I am using this extension in multiple projects with i18next. In i18next, developer can specify a nsSeparator, like ":" or "|". But this extension always give me "." as suggestions. image which will not work in project.

Projects using : as delimiter can be parsed correctly in this extension, but those using | or other delimiters don't.

Describe the solution you'd like

I'd like to have a setting to change default namespace delimiters from . to :.

Or, I found this setting i18n-ally.regex.usageMatchAppend but I don't know how to make it correct.

In one of my porject we use $t('namespace:key.subKey') for translations. But \\$t\\(\\s*[\\'\"`]({namespace})\\:({key})[\\'\"`] cannot make the extension parse my code correctly.

Additional context

Related to #295

vanenshi commented 2 years ago

Looking forward to this. I also open an issue on the react-i18next that might solve the problem by customizing the nsSeprator on the typescript side: https://github.com/i18next/react-i18next/issues/1467

farukg commented 1 year ago

We also use i18next with options

{
  defaultNS: 'myDefaultNS',
  fallbackNS: ['myDefaultNS', 'myNS'],
  nsSeparator: '|',
  keySeparator: '.',
}

so we have the same issue that given myNS|someParent.someFinalKey effectively the key get prefixed with e.g. myNS| and I thought I could make it work at least for default namespaces which means someParent.someFinalKey.

And I tried setting a global default namespace using defaultNamespace which works. I realized we have also added NS despite it wasn't necessary, so I tried setting usageMatchRegex such that it skips the myNS| part. I had luck with "[^\\w\\d]t\\(['\"](?:[\w]\|)?(.)['\"]" but since I knew this is all very suboptimal, I tried to find a regex so it could match | with . which seems to be not possible. And I wouldn't be able to configure multiple default namespaces anyways.

The conclusion

I think it would be enough to allow configuring multiple key separators/delimiters or specify a regex for rather than a single character

Same goes for default namespaces or rather fallback namespaces. This project doesn't differentiate between namespaces and keys like i18next does even though it does and I see how those are very similar.

Sorry, if this was a lil tedious, I failed to structure this well but wanted to share my thoughts, TLDR is we need this too :)

dallyh commented 7 months ago

I could not find any information on this particular issue elsewhere then this issue and this: https://github.com/lokalise/i18n-ally/issues/443 issue. The issue I'm facing is with the namespace delimiter in the auto completion. This issue is still opened, so I'm asking if there are any plans on this, or if I just have something wrong, and the suggestions should be displayed corrently, when using the "i18next" framework. Thanks!

bon-alexis commented 5 months ago

Also interested in this being fixed!

Kirbo commented 1 month ago

Ping, here's one user also using i18next with nsSeparator: ":" and the suggestion suggests namespace.nested.key instead of namespace:nested.key or even t('nested.key', { ns: namespace }) or what have you. The current suggestions are just not (flexible) enough. image In this scenario, it should suggest me with the following:

or better yet:

As a user/developer, I'd rather have all these suggestions editable in a way, that user themselves could define each pattern for the suggestions. For example, I wouldn't most likely ever need other than the first two ({t('remove', { ns: 'common' })} and t('common:remove')) or perhaps not more than one.