hilla icon indicating copy to clipboard operation
hilla copied to clipboard

[I18n] Support for translating a pattern-matched key

Open platosha opened this issue 6 months ago • 0 comments

Currently, users can only provide static strings in ViewConfig as the view title, menu link text, and so on.

When internationalization is in use, a common use case is to use translated view titles. Therefore we should support it.

One idea is to support and document using template literal for translation keys, which would be matched with the patten in the respective bundle:

// AboutView.tsx:
export const viewConfig: ViewConfig = {
  title: i18n`viewtitle.about`,
};

function AboutView({}) {
  return <h1>{translate(i18n`viewtitle.about`)}</h1>;
}

// @layout.tsx:
effect(() => {
  document.title = translate(findKey('viewtitle.*', documentTitleSignal.value));
});

findKey allows finding an i18n literal key declared elsewhere by using strings. It should throw if the second argument is not matching the pattern.

platosha avatar May 13 '25 11:05 platosha