Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [bug:i18n] Some issues with astro.config.{*s} and astro:i18n #13017

Open
5 tasks done
JakiChen opened this issue Jan 21, 2025 · 2 comments
Open
5 tasks done

🐛 [bug:i18n] Some issues with astro.config.{*s} and astro:i18n #13017

JakiChen opened this issue Jan 21, 2025 · 2 comments
Labels
needs repro Issue needs a reproduction

Comments

@JakiChen
Copy link

JakiChen commented Jan 21, 2025

Astro Info

Astro                    v5.1.8
Node                     v22.12.0
System                   macOS (x64)
Package Manager          yarn
Output                   server
Adapter                  @astrojs/vercel
Integrations             astro-robots
                         @astrojs/sitemap
                         @storyblok/astro

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

No response

Describe the Bug

Astro ( astro.config.{*s} ) Configuration

i18n: {
      locales: ['zh-CN', 'zh-HK', { path: 'english', codes: ['en-GB', 'en-US', 'en'] }],
      defaultLocale: 'zh-CN',
      domains: {
          'en-GB':'https://example.com.us'
    }
},
Details (Reference Configuration)
import { defineConfig } from 'astro/config';

import { env, vite, paths } from './config';
import { favicons, robots, sitemap } from './config/integrations';

import storyblok from '@storyblok/astro';

export default defineConfig({
  // site: env.SITE_URL,
  trailingSlash: 'ignore',
  //
  ...(await import('./config/vercel/server')).default,
  //
  integrations: [
    // favicons,
    robots,
    sitemap,
    storyblok({
      accessToken: env.STORYBLOK_TOKEN,
      apiOptions: {
        cache: {
          clear: 'auto',
          type: 'memory',
        },
        region: 'eu',
      },
      bridge: import.meta.env.DEV,
      livePreview: false,
      componentsDir: 'src/components',
      components: {},
    }),
  ],
  //
  outDir: './build',
  compressHTML: import.meta.env.PROD,
  scopedStyleStrategy: 'attribute',
  vite,
  build: {
    format: 'file',
    inlineStylesheets: 'never',
    assets: paths.build.assets,
  },
  image: {
    domains: ['a.storyblok.com'],
  },
  //
  i18n: {
    locales: ['zh-CN', 'zh-HK', { path: 'english', codes: ['en-GB', 'en-US', 'en'] }],
    defaultLocale: 'zh-CN',
    domains: {
      'english':'https://example.com.us'
    }
  },
});
Figures

(Figure 1)
Figure 1

(Figure 2)
Figure 2

( Figure 3)
Figure 3

Astro (astro:i18n) runtime

I am trying to extend some interfaces to AstroGlobal for dynamic generation of structured data.

Object.defineProperties(Astro, {
    canonicalURL: {
        value: new URL(pathname, Astro.site),
    },
    pathHasLocale: {
        value: pathname.startsWith(`/${currentLocale}/`) || pathHasLocale(pathname),
    },
});

Example 1: Dynamically generate itemListElement of BreadcrumbList

import type { AstroGlobal } from 'astro';
import type { ListItem } from 'schema-dts';
import { getTranslations, type Language } from '../../translations';

export const breadcrumbListElement = (context: AstroGlobal): ListItem[] => {
    const { site, url, props, currentLocale, pathHasLocale } = context;
    const i18n: { [key: string]: string } = getTranslations(currentLocale as Language);

    const segments = url.pathname.split('/').filter(Boolean);
    const items: ListItem[] = [];

    const addItem = (position: number, name: string, item?: string) => {
        items.push({ '@type': 'ListItem', position, name, item });
    };

    if (!pathHasLocale) {
        addItem(1, i18n.home, segments.length > 0 ? site?.toString() : undefined);
    }

    segments.forEach((segment, index) => {
        const name =
            index === 0 && pathHasLocale ? i18n.home : (i18n[segment] ?? props.title ?? segment);
        const item =
            index !== segments.length - 1
                ? `${site}${segments.slice(0, index + 1).join('/')}`
                : undefined;

        addItem(index + (pathHasLocale ? 1 : 2), name, item);
    });

    return items;
};

What's the expected result?

Main tasks

  • Fix bug - Issues in astro.config.{*s}

Minor tasks

  • Improve - Issues in asto:i18n: function pathHasLocale(path:string)

Link to Minimal Reproducible Example

https://github.com/withastro/astro/tree/main/examples/basics

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 21, 2025
@ascorbic
Copy link
Contributor

Please don't create sub-issues. Can you share a reproduction and a succinct description of the issue that you are reporting. This umbrella issue is hard to follow, and it's unclear what is the exact problem.

@ascorbic ascorbic added needs repro Issue needs a reproduction and removed needs triage Issue needs to be triaged labels Jan 21, 2025
Copy link
Contributor

Hello @JakiChen. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2025
@ematipico ematipico reopened this Jan 21, 2025
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 21, 2025
@ascorbic ascorbic removed the needs triage Issue needs to be triaged label Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue needs a reproduction
Projects
None yet
Development

No branches or pull requests

3 participants