Skip to content

Feature request: Support nested objects/arrays in i18n with dot-path access via $t #229

@liolocs

Description

@liolocs

Description

  • Problem: i18n only supports flat string keys, forcing unwieldy names like onboarding_step_one_question_8_pets_type. This blocks structured translations, iteration in views, and readable files.

  • Proposal:

    • Allow locale files to define nested objects and arrays.
    • Make $t(path) return the resolved value (string/object/array).
    • Support dot-paths with array indices, e.g. $t('onboarding.steps.0.title').
    • Preserve backward compatibility for flat keys.

Current (workaround)

export default locale({
  onboarding_step_1_title: "Personal Information",
  onboarding_step_1_question_8_pets_type: "radio",
});

Desired (structured)

export default locale({
  onboarding: {
    steps: [
      { title: "Category setup", description: "..." },
      { title: "Income" },
      { title: "Expenses" },
      { title: "Forecasts" },
    ],
  },
});

Desired usage

{$t('onboarding.steps')}           // returns array
{$t('onboarding.steps.0.title')}   // "Category setup"

Benefits

  • Maintainability: Cleaner files; collapsible sections; easier to split by domain.
  • DX: Build dynamic UIs by iterating over arrays in locales.
  • Compatibility: Flat key lookups continue to work.

Acceptance criteria

  • Nested values: Objects/arrays loaded intact.
  • Return types: $t returns non-string values without coercion.
  • Pathing: Dot-paths with indices supported.
  • Parity: Interpolation/pluralization for deep strings still works.
  • Backwards compatibility: Existing flat string lookups unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions