Skip to content

@wxt-dev/i18n: named substitutions treat mustache-style {{tokens}} as required i18n arguments #2482

Closed

Description

@mengxi-ream

Package

@wxt-dev/i18n

Version

0.2.6 (latest on npm at the time of filing). This appears to be a regression from 0.2.5, which did not have the named substitution scanner, runtime support, or type overloads.

Description

0.2.6 introduced named substitutions using {name} placeholders. The generated type scanner also detects placeholders inside mustache-style application templates such as {{targetLanguage}}.

That makes messages containing app-level template tokens require named i18n substitutions even when the desired behavior is to retrieve the localized template string unchanged and store or use it later.

In our extension, these strings are custom AI prompt templates. The {{...}} tokens are intentionally preserved and substituted later by our own prompt renderer, not by i18n at template creation time.

Reproduction

Locale file:

actionTemplate:
  prompt: |-
    Translate {{selection}} into {{targetLanguage}}.

Generated structure in 0.2.6:

"actionTemplate.prompt": {
  substitutions: 0,
  plural: false,
  namedSubstitutions: ["selection", "targetLanguage"]
};

Then this TypeScript call fails:

i18n.t("actionTemplate.prompt")

With an error like:

Argument of type "actionTemplate.prompt" is not assignable to parameter of type never.

because the no-argument overload excludes keys with namedSubstitutions.

Expected Behavior

It should be possible to include literal or app-level brace templates in localized strings without forcing them to become @wxt-dev/i18n named substitutions.

Possible fixes:

  • Do not treat {{name}} as a named substitution, only single-brace {name}.
  • Or provide a documented escape syntax for literal braces or template tokens that is respected by both runtime substitution and generated types.

Actual Behavior

{{name}} is detected as {name}, so the generated types require a named substitution object. This is surprising for applications that already use double-brace template tokens and only want i18n to return the raw localized template text.

Workaround

Passing the token back through named substitutions can preserve the string, for example:

i18n.t("actionTemplate.prompt", {
  selection: "{selection}",
  targetLanguage: "{targetLanguage}",
})

But this is verbose, easy to miss, and couples app-level template tokens to the i18n substitution scanner.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions