question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for dynamically constructed keys

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
antfucommented, May 24, 2020

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.

Just let me know if you have any questions. Thanks!

1reaction
edgerunnercommented, May 24, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating object with dynamic keys - javascript - Stack Overflow
In the new ES2015 standard for JavaScript (formerly called ES6), objects can be created with computed keys: Object Initializer spec. The syntax is:...
Read more >
How to Destructure a Dynamic Key in JavaScript or Node.js
Using Destructuring With a Dynamic Key in JavaScript​​ js ORM for Node. js supports a configurable ID column for models.
Read more >
Working with dynamic field keys - ACF Support
I'm currently using ACF lite for custom theme development. To create feilds, ordinarily, I would build them using the ACF admin, export the ......
Read more >
Dynamic Keys - DZone
Wallaroo is designed to help you build stateful event processing services ... We call this feature “dynamic keys” and it expands Wallaroo's ...
Read more >
Predefined and dynamic key-values - Google Ad Manager Help
Dynamic key -values let you pass targeting values dynamically into an ad tag based on information you collect. For example, you can use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found