WICG / WICG/webmonetization

Replace astro-i18next and HeadHrefLangs Component Due to Compatibility Issues

Open
#486 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

website
Dominant language
HTML
Stars
607
Forks
166
Avg merge
2d 7h
Merged PRs (30d)
7

Description

Bumping up the @astrojs/starlight dependency caused compatibility issues with the HeadHrefLangs component that is part of the astro-i18next module. Unfortunately, it seems this module is no longer being maintained. HeadHrefLangs is a component from astro-i18next that generated tags with hreflang attributes for SEO, specifying alternate language versions of a webpage.

astro-i18next also adds in other internationalization features like i18next configurations. There needs be investigation of the best way to keep all this functionality while keeping everything updated. This either means exploring other community libraries, or use Astro's Built-in i18n Support. This also has limitations which is why it needs more work to figure out the best path.

Error
TypeError
An error occurred.
Cannot read properties of undefined (reading 'map')
components/HeadHrefLangs.astro:10:19
Open in editor
---
import i18next from "i18next";
import { localizeUrl } from "../..";

const supportedLanguages = i18next.languages;
const currentUrl = Astro.url.href;
---

{
  supportedLanguages.map((supportedLanguage) => (
^
    <link
      rel="alternate"
      hreflang={supportedLanguage}
      href={localizeUrl(currentUrl, supportedLanguage)}
    />
  ))
}
Stack Trace
TypeError: Cannot read properties of undefined (reading 'map')
    at /home/sarah/sarah-webmo/webmonetization/node_modules/astro-i18next/src/components/HeadHrefLangs.astro:10:19
    at AstroComponentInstance.HeadHrefLangs [as factory] (/home/sarah/sarah-webmo/webmonetization/node_modules/astro/dist/runtime/server/astro-component.js:16:12)
    at AstroComponentInstance.init (/home/sarah/sarah-webmo/webmonetization/node_modules/astro/dist/runtime/server/render/astro/instance.js:32:29)
    at AstroComponentInstance.render (/home/sarah/sarah-webmo/webmonetization/node_modules/astro/dist/runtime/server/render/astro/instance.js:42:36)
    at Object.render (/home/sarah/sarah-webmo/webmonetization/node_modules/astro/dist/runtime/server/render/component.js:367:22)
    at Module.renderChild (/home/sarah/sarah-webmo/webmonetization/node_modules/astro/dist/runtime/server/render/any.js:31:17)
Current Workaround

The dependencies can be updated by removing the import { HeadHrefLangs } from "astro-i18next/components"; and <HeadHrefLangs /> lines from src/layouts/Base.astro. See chore: basic dependency bump #485

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/layouts/Base.astro and the astro-i18next HeadHrefLangs usage, then review the reported compatibility error and Astro's built-in i18n support. Compare that option with the linked community libraries while preserving the existing i18next functionality. Done means a maintained approach replaces the workaround and generates the required localized alternate-language links without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, internationalization
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.