You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was integrating i18next into my Astro site with Starlight and found that the TypeScript compiler will force the defaultNS field for any i18next instance to be 'starlight', which will make the t function type errors if the keys don't match.
Ah, thanks for the heads up. Not sure this was something we considered while working on this feature.
For what it’s worth, I think you should be able to use Starlight’s Astro.locals.t() throughout your site even on non-Starlight pages (assuming they use the same locale prefixes in the URLs), so it might be possible to avoid additional set-up of i18next.
Still, it would be good to avoid this if possible. Happy to review a PR if anyone knows how to solve this!
Like you mentioned, StackBlitz does not have proper type-checking but even after downloading the project locally, I am not able to reproduce the issue.
From quickly looking at the code, it seems that the repro does not include a declaration file for i18next so I added one in src/i18next.d.ts:
// src/i18next.d.tsimport"i18next";// Import the base translation fileimportenfrom"../public/locales/en/translation.json";declare module "i18next"{interfaceCustomTypeOptions{// Define the default namespacedefaultNS: "translation";resources: {// And the associated translationstranslation: typeofen;};}}
It imports translation for the default language and defines the associated type for the translation namespace.
After doing so, it seems that everything works as expected:
When using Astro.locals.t:
I get autocompletion for Starlight UI strings.
Unknown key are correctly highlighted as errors.
Keys from your custom translation file are correctly highlighted as errors.
When using your t function:
I get autocompletion for keys from public/locales/en/translation.json.
Unknown key are correctly highlighted as errors.
Keys from Starlight UI are correctly highlighted as errors.
What version of
starlight
are you using?0.30.0
What version of
astro
are you using?5.1.1
What package manager are you using?
pnpm
What operating system are you using?
Mac
What browser are you using?
Chrome
Describe the Bug
I was integrating i18next into my Astro site with Starlight and found that the TypeScript compiler will force the
defaultNS
field for any i18next instance to be'starlight'
, which will make the t function type errors if the keys don't match.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ytqftcmh?file=src%2Fpages%2Ftest.astro
Participation
The text was updated successfully, but these errors were encountered: