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

Broken relative links in docs and i18n translation #10907

Open
6 of 7 tasks
trofim24 opened this issue Feb 6, 2025 · 1 comment
Open
6 of 7 tasks

Broken relative links in docs and i18n translation #10907

trofim24 opened this issue Feb 6, 2025 · 1 comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: i18n Related to the i18n system

Comments

@trofim24
Copy link

trofim24 commented Feb 6, 2025

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

Problem with relative links in docs and i18n translation.

Reproducible demo

https://trofim24.github.io/

Steps to reproduce

  1. Create a new Docusaurus site with npx create-docusaurus@latest my-website classic -t command from instruction
  2. Go to created folder cd my-website
  3. Copy only one Markdown file and images use
    mkdir -p i18n/fr/docusaurus-plugin-content-docs/current/tutorial-extras/img
    cp -r docs/tutorial-extras/img/** i18n/fr/docusaurus-plugin-content-docs/current/tutorial-extras/img
    cp -r docs/tutorial-extras/translate-your-site.md i18n/fr/docusaurus-plugin-content-docs/current/tutorial-extras
    command from instruction
  4. Change docusaurus.config.js. Add 'fr' language to locales from instruction and add a navbar item of type localeDropdown from instruction:
    locales: ['en', 'fr']
    and
    { type: 'localeDropdown', position: 'left', },
  5. Run build use npm run build command from instruction

Also you can visit my build site to check broken link:
/fr/docs/tutorial-basics/congratulations
broken link

Expected behavior

The build is OK

Actual behavior

[WARNING] Docusaurus found broken links!

Please check the pages of your site in the list below, and make sure you don't reference any path that does not exist.
Note: it's possible to ignore broken links with the 'onBrokenLinks' Docusaurus configuration, and let the build pass.

Exhaustive list of all broken links found:

  • Broken link on source page path = /fr/docs/tutorial-basics/congratulations:
    -> linking to ../tutorial-extras/translate-your-site.md (resolved as: /fr/docs/tutorial-extras/translate-your-site.md)

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@trofim24 trofim24 added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Feb 6, 2025
@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Feb 6, 2025
@slorber
Copy link
Collaborator

slorber commented Feb 6, 2025

Yes, I think this is because you only copied one Markdown file.

https://github.com/trofim24/my-website/blob/master/i18n/fr/docusaurus-plugin-content-docs/current/tutorial-extras/translate-your-site.md

Image

It looks like our resolveMarkdownLinks remark plugin, responsible for resolving .md Markdown links to an absolute path, is not powerful enough. It isn't currently able to resolve relative links if the translated docs set is incomplete since we'll have to resolve relative links found in a file against multiple source dirs instead of just one.

Probably a bug involving this function: https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-utils/src/markdownLinks.ts
I suspect the sourceToPermalink map does not contain all the necessarily information to support this use-case.


This is likely a bug we need to investigate, not so easy to resolve. In the meantime I'd suggest that you translate the whole docs at once instead of partially. If you want to translate it partially, it would work better with absolute paths like [translate your site](/docs/tutorial-extras/translate-your-site)

@slorber slorber added the domain: i18n Related to the i18n system label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: i18n Related to the i18n system
Projects
None yet
Development

No branches or pull requests

2 participants