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

Trailing Slash Setting Ignored #119

Closed
itsmatteomanf opened this issue Feb 5, 2023 · 4 comments
Closed

Trailing Slash Setting Ignored #119

itsmatteomanf opened this issue Feb 5, 2023 · 4 comments
Labels
bug Something isn't working released on @beta

Comments

@itsmatteomanf
Copy link

itsmatteomanf commented Feb 5, 2023

Describe the bug

In the <HeadHrefLangs /> output, regardless of the setting of the trailingSlash config in Astro (https://docs.astro.build/en/reference/configuration-reference/#trailingslash) the output is always without them.
This is contrasted to what the docs say and show (https://github.com/yassinedoghri/astro-i18next#headhreflangs-component).

To Reproduce

Deploy any website, with the package installed, setting whichever trailingSlash and/or site name you want, with or without trailing slash.

Expected behavior

Ideally it would offer a way to configure this (or use the main Astro setting, but I'd personally prefer the setting).

Context (please complete the following information):

  • astro-i18next version: [1.0.0-beta.17]
  • astro version: [2.0.6]
@Temez1
Copy link

Temez1 commented Feb 8, 2023

Same issue with localizePath().

Eg. homePath = localizePath("/")

produces "/es" (Spanish) and Astro.url.pathname is "/es/" in production builds. In dev mode the Astro.url.pathname is "/es".

I believe this has to do with the previous fix #77

@yassinedoghri yassinedoghri added the bug Something isn't working label Feb 10, 2023
@itsmatteomanf
Copy link
Author

This issue messes a lot with Google Indexing if you have all pages indexed with the trailing slash...

@ein-gg
Copy link

ein-gg commented Feb 21, 2023

I've got same problem.

localizeUrl do this things. In this commit this problem maden I think.


It's realy necessary to have similar with canonical hreflang structure.

Temporary manually fix for me:

1. Create HeadHreflangs.astro inside /src/components/ with this code inside:

---
import i18next from "i18next";
import { localizeUrl } from "astro-i18next";

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

const hreflangs = [];

supportedLanguages.map((supportedLanguage) => {
  const url = localizeUrl(currentUrl, supportedLanguage);

  hreflangs.push(
    `<link rel="alternate" hreflang="${supportedLanguage}" href="${
      url[url.length - 1] !== "/" ? url + "/" : url
    }" />`
  );
});

---

{
  hreflangs.map((hreflang) => {
    return <Fragment set:html={hreflang} />;
  })
}

2. Replace original import from astro-i18next/components to your component file.

import { HeadHrefLangs } from "astro-i18next/components";

For me it looks like:

import HeadHrefLangs from "../HeadHreflangs.astro";

3. Use it, and don't forget to return the original component when the problem is fixed.

yassinedoghri pushed a commit that referenced this issue Feb 26, 2023
# [1.0.0-beta.18](v1.0.0-beta.17...v1.0.0-beta.18) (2023-02-26)

### Bug Fixes

* handle localizePath trailing slash depending on astro's trailingSlash config ([880666c](880666c)), closes [#119](#119)

### Features

* **language-selector:** add languageMapping prop to rename languages of choice ([20d94e4](20d94e4)), closes [#116](#116)
@github-actions
Copy link

🎉 This issue has been resolved in version 1.0.0-beta.18 🎉

The release is available on:

Your semantic-release bot 📦🚀

AliLee0923 pushed a commit to AliLee0923/astro-i18N that referenced this issue Dec 2, 2023
# [1.0.0-beta.18](yassinedoghri/astro-i18next@v1.0.0-beta.17...v1.0.0-beta.18) (2023-02-26)

### Bug Fixes

* handle localizePath trailing slash depending on astro's trailingSlash config ([880666c](yassinedoghri/astro-i18next@880666c)), closes [#119](yassinedoghri/astro-i18next#119)

### Features

* **language-selector:** add languageMapping prop to rename languages of choice ([20d94e4](yassinedoghri/astro-i18next@20d94e4)), closes [#116](yassinedoghri/astro-i18next#116)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released on @beta
Projects
None yet
Development

No branches or pull requests

4 participants