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

html sidebar item should be translatable #9575

Closed
6 of 7 tasks
fgalz opened this issue Nov 22, 2023 · 6 comments
Closed
6 of 7 tasks

html sidebar item should be translatable #9575

fgalz opened this issue Nov 22, 2023 · 6 comments
Labels
closed: duplicate This issue or pull request already exists in another issue or pull request domain: i18n Related to the i18n system feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@fgalz
Copy link

fgalz commented Nov 22, 2023

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

Docusaurus offers the possibility to add a "sidebar-title" using the HTML type. However, there is currently no option for a simple translation.

{
type: 'html',
className: 'sidebar-title',
value: 'Placeholder',
defaultStyle: true,
},

The function itself works again with the latest Canary version, but it can only be used in one language and is limited if you offer docs in several languages.

Reproducible demo

No response

Steps to reproduce

Add the sidebar-title, build it and check it. It's only available in the hardcoded language or rather the value that is set.

Expected behavior

The sidebar-title should be available in other languages as well, so there should be some sort of support for this.

Actual behavior

The sidebar-title (value) is hardcoded and therefore the same for all languages.

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used: Canary
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Self-service

  • I'd be willing to fix this bug myself.
@fgalz fgalz 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 Nov 22, 2023
@Josh-Cena Josh-Cena changed the title Missing sidebar-title translation support html sidebar item should be translatable Nov 22, 2023
@Josh-Cena Josh-Cena added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. domain: i18n Related to the i18n system and removed 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 Nov 22, 2023
@slorber
Copy link
Collaborator

slorber commented Nov 26, 2023

I'll consider it as a duplicate of #4542

Suggested workaround, not an ideal api but will work to translate html navbar items: #4542 (comment)

@slorber slorber closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
@slorber slorber added the closed: duplicate This issue or pull request already exists in another issue or pull request label Nov 26, 2023
@fgalz
Copy link
Author

fgalz commented Nov 27, 2023

Hi @slorber,

can this also be used directly in the sidebar.js or are there limitations in this regard? Would you mind explaining in a little more detail how this can be implemented?

I followed the following approach:

sidebar: [
    {
      type: 'html',
      className: 'sidebar-title',
      value: (() => {
        switch (process.env.DOCUSAURUS_CURRENT_LOCALE) {
          case "de": return "GERMAN SIDEBAR TITLE";
          default: return "ENGLISH SIDEBAR TITLE";
        }
      })(),
      defaultStyle: true,
    },
    {
      type: 'category',
      label: 'Category',
      items: [
        "placeholder",
        "placeholder",
        "placeholder",
      ]
    },

The sidebar title "ENGLISH SIDEBAR TITLE" (default value) is displayed without any issues. However, the default value is also displayed for the "de" case of the German version. Am I missing something? My knowledge in this matter is rather limited, so I am grateful for any tips! :)

@slorber
Copy link
Collaborator

slorber commented Nov 30, 2023

This works on our own website:

CleanShot 2023-11-30 at 15 14 27@2x

CleanShot 2023-11-30 at 15 14 56@2x

I just ran yarn start:website --locale de

If it doesn't work for you please create a runnable repro including the command you use to start in de lang

@Blumlaut
Copy link

Blumlaut commented Dec 3, 2023

Hi @slorber, we don't start the docs using a locale arg at all -- we use npm run docusaurus build to build it in both languages before deploying the docs.

As far as i could tell the sidebar code only gets run once when the en locale is generated, this doesn't seem to happen again for the de locale.

@slorber
Copy link
Collaborator

slorber commented Dec 7, 2023

Runnable proof that it does after running yarn build:
https://stackblitz.com/edit/github-zcvn3b?file=sidebars.js,docusaurus.config.js

Please create a minimal repro next time

CleanShot 2023-12-07 at 15 08 39@2x

@Blumlaut
Copy link

Blumlaut commented Jan 2, 2024

Thank you, it seems our issue was that instead of export default sidebars; we still had module.exports = sidebars; at the end of the sidebars config, updating this has indeed resulted in the expected behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: duplicate This issue or pull request already exists in another issue or pull request domain: i18n Related to the i18n system feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
Development

No branches or pull requests

4 participants