Support for dynamically constructed keys
See original GitHub issueIs your feature related to a specific framework or general for this extension I’m using i18next but I think this applies to any framework out there.
Is your feature request related to a problem? Please describe. I’m using some factory functions to easily construct repetitive features of my app. Constructing and assigning translation keys is one of the things that those constructors do. Naturally, there’s a disconnect in where I write down the translation key, where the namespace is derived from and where the translation function (which i18n-ally looks for) is finally called.
Example:
/// tour/alerts.js
…
const step = stepNamespace("alerts");
…
step("red-alert")
…
/// tour/index.js
…
export function stepNamespace(ns) {
if (ns) {
return function stepWithNS(id) {
return {
id: `${ns}-${id}`,
text: t(`steps.${ns}.${id}`)
};
};
} else {
return function stepWithoutNS(id) {
return {
id,
text: t(`steps.${id}`)
};
};
}
}
…
this code ultimately produces an object like { id: "alerts-red-alert", text: t("steps.alerts.red-alert") }
but it’s not possible to know that without running the code.
Describe the solution you’d like
The best case would be some code analysis or introspection that traces the input to t()
calls back to their source and figures out the keys. But I think this would be way too complex to really work beyond simple cases and be bullet-proof.
The second best would be being able to configure the plugin at the workspace level to look for specific patterns. For the example above I’d ask the plugin to look for the step
function call, and take its parameter as a translation key, while using the stepNamespace
call as the file-specific namespace source.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Just let me know if you have any questions. Thanks!
I may look into it depending on how easy (for me) it turns out to be. I’ve never worked on a vscode plugin before.