Skip to content

Return Missing Key/Path Instead of undefined @solid-primitives/i18n #765

@franciscomerdot

Description

@franciscomerdot

Describe The Problem To Be Solved

Currently, when a translation key does not exist in the dictionary, the translator returns undefined (resulting in UI blanks). This can be confusing because it silently fails, and developers might not realize they're missing a key. While the translator itself has type-checking to alert us about non-registered keys, it would be safer and more intuitive if the translator returned the missing key/path itself (e.g., "missing.key" as the fallback) when the entry is not found.

For reference, the relevant code is in index.ts line 267.

Current Behavior

  • When a key is missing, the translator returns undefined (resulting in UI blanks), which can go unnoticed during development.

Why This Is Important

  • Helps developers catch missing translation keys more reliably.
  • Prevents silent UI issues where undefined appears or is rendered blank.
  • A consistent fallback makes it easier to diagnose and fix translation gaps.

Additional Context

  • This change would align with the behavior of many other i18n libraries that display an obvious placeholder (like the key itself) when a translation is missing.
  • Developers often expect some clear indicator rather than a silent undefined.

Suggest A Solution

Expected Behavior

  • If a key is missing in the dictionary, return the key/path as the fallback instead of undefined.
  • Example: t("missing.key") should return "missing.key" rather than undefined.

Possible Solutions

  1. Modify the logic at the mentioned line 267 to return the requested key/path when the lookup fails.
  2. Provide a configuration option (e.g., a missingKeyHandler) for projects that might prefer a different fallback behavior.

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