Skip to content

Issues with i18n config typing #10157

@delucis

Description

@delucis

Astro Info

Astro                    v4.4.0
Node                     v18.18.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

Any (n/a)

Describe the Bug

Using this issue to report two related issues with the types for the i18n config.

  1. The types for i18n.routing are inaccurately strict. For example, the following is valid configuration and shown in the Astro docs:

    import { defineConfig } from 'astro/config';
    
    export default defineConfig({
      i18n: {
        defaultLocale: 'en',
        locales: ['en', 'fr'],
        routing: {
          prefixDefaultLocale: true,
        },
      },
    });

    However, the above is considered a type error (you need an astro.config.ts or a // @ts-check comment to see this most likely). strategy and redirectToDefaultLocale are both typed as required in i18n.routing.

  2. When setting i18n configuration from an Astro integration via the updateConfig() method, it seems to expect one of the internal enum values like 'pathname-prefix-other-locales' rather than the proper configuration object. I suspect the issue is that updateConfig() is typed with AstroConfig instead of AstroUserConfig, which I think is inaccurate?

What's the expected result?

  1. The types should not require i18n.routing be set with all values.

  2. The updateConfig() integration method should accept the same shape as when setting the config directly.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-cosd7e?file=astro.config.ts

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

needs triageIssue needs to be triaged

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions