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

the footnote label "Footnotes" should be able to be translated #9502

Closed
2 of 7 tasks
tats-u opened this issue Nov 3, 2023 · 12 comments · Fixed by #9674
Closed
2 of 7 tasks

the footnote label "Footnotes" should be able to be translated #9502

tats-u opened this issue Nov 3, 2023 · 12 comments · Fixed by #9674
Labels
domain: i18n Related to the i18n system domain: markdown Related to Markdown parsing or syntax feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@tats-u
Copy link
Contributor

tats-u commented Nov 3, 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

By the upgrade of the MDX plugin, the border of the document body and the footnotees has been changed from <hr> to the English-fixed heading. I couldn't find a way to change the language of the heading.

Some remark and related plugins can customize the "Footnotes" label by the option passed to mdast-util-to-hast.toHast.

https://github.com/remarkjs/remark-rehype#fields
https://github.com/remarkjs/remark-rehype#example-footnotes-in-languages-other-than-english
https://github.com/remarkjs/remark-html#options
https://github.com/syntax-tree/mdast-util-to-hast#footnotes
https://github.com/micromark/micromark-extension-gfm-footnote#label

Reproducible demo

WIP

Steps to reproduce

  1. Set the language of your document as other than English
  2. Add a footnote to a page in docs
  3. docusaurus start
  4. Open the page in your browser

Expected behavior

The footnote label is that in the language of your language (e.g. "脚注" in Japanese)

Actual behavior

Always "Footnotes" regardless of your language

Your environment

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

Self-service

  • I'd be willing to fix this bug myself.
    ↑ If easy to fix, but doesn't seem
@tats-u tats-u 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 3, 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 domain: markdown Related to Markdown parsing or syntax 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 3, 2023
@tats-u
Copy link
Contributor Author

tats-u commented Nov 6, 2023

We have to read defaultLocales and locales in docusaurus.config.* from processor.ts and pass correct MDX options to gfm in response to these Docusaurus config values.

@slorber
Copy link
Collaborator

slorber commented Nov 26, 2023

cc @wooorm can we pass footnoteLabel option to remark-gfm?

It doesn't look to be supported atm in remark-gfm and micromark-gfm (outside of gtmHtml). Is there a high-level option to configure it easily?


@tats-u until we solve it, I think you can translate it in userland thanks to a rehype plugin

CleanShot 2023-11-26 at 15 36 20@2x

@wooorm
Copy link
Contributor

wooorm commented Nov 26, 2023

remark-rehype has the options. Should be in both projects' docs!

@slorber
Copy link
Collaborator

slorber commented Nov 26, 2023

Thanks!

Ref: https://github.com/remarkjs/remark-rehype#example-footnotes-in-languages-other-than-english

So it looks like a possible solution:

compile(
  {value: '…'},
  {remarkRehypeOptions: {footnoteLabel: 'Fußnoten'}}
)

I guess we could expose the whole MDX option object and deep merge it for maximum flexibility (although it expose the ability to break things? 🤔 ), or eventually just the remarkRehypeOptions option

@slorber slorber closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
@slorber slorber reopened this Nov 26, 2023
@tats-u
Copy link
Contributor Author

tats-u commented Nov 26, 2023

remark-rehype has the options. Should be in both projects' docs!

So it looks like a possible solution:

This is it. I have noticed it too several days ago but forgotten to tell it to correct my misuses guess. I am sorry for that.

I wonder if we should generate processor instances (the return value of (import ("mdx-js/mdx")).createProcessor) for each language.

const processorOptions: ProcessorOptions & Options = {
...options,
remarkPlugins,
rehypePlugins,
providerImportSource: '@mdx-js/react',
};
const mdxProcessor = createMdxProcessor({
...processorOptions,
format,
});

Shall we add an additional argument language: string to createProcessorFactory? It is going to be transformed to a footnote label for the language that it presents. The most simplest transformer is a hashmap (lazy initialization may be needed).

    const processorOptions: ProcessorOptions & Options = {
      ...options,
      remarkPlugins,
      rehypePlugins,
      remarkRehypeOptions: {
        // this function translaveFootnoteLabel must be defined at another place by ourselves
        footnoteLabel: translateFootnoteLabel(language),
      },
      providerImportSource: '@mdx-js/react',
    };

@slorber
Copy link
Collaborator

slorber commented Dec 27, 2023

PR to track: #9674

@tats-u
Copy link
Contributor Author

tats-u commented Dec 28, 2023

It would be the best if the translated footnote label strings were out of the box.

@tats-u
Copy link
Contributor Author

tats-u commented Dec 28, 2023

Can we use process.env.DOCUSAURUS_CURRENT_LOCALE in packages/docusaurus-mdx-loader/src/processor.ts?
If so we will be able to prepare default footnote labels easily.

@slorber
Copy link
Collaborator

slorber commented Jan 2, 2024

It would be the best if the translated footnote label strings were out of the box.

Agree, not sure where to store those translations though, maybe we could rename the docusaurus-theme-translation to just docusaurus-translations and put some default core translations there in a core.json file? 🤔

Our problem is that we probably want external contributors to find and translate those strings, and introducing another folder to translate is not going to help.

Can we use process.env.DOCUSAURUS_CURRENT_LOCALE in packages/docusaurus-mdx-loader/src/processor.ts? If so we will be able to prepare default footnote labels easily.

I'd prefer to pass the locale as mdx loader parameter instead of relying on this env variable for now. It's more explicit and testable.

But if we store translations there, who will be responsible to translate those strings?

cc @wooorm, any interest to maintain an official repo with footnote label translations? 🤪 I guess other MDX-based projects could benefit from this.

@wooorm
Copy link
Contributor

wooorm commented Jan 5, 2024

It’s not specific to MDX, it’s more a GFM markdown thing. I can also see other websites wanting different labels. This value is what GH uses but on your own blog something else might be better.

Now, docusaurus probably already has certain other values that it translates, to me this is a better place to maintain and configure this?

@slorber
Copy link
Collaborator

slorber commented Jan 5, 2024

@wooorm yes we have other values that we translate, and it makes sense to let site owners decide on the final label they want for their site.

However providing localized labels out of the box as a fallback would be convenient for the whole community. But it would remain the responsibility of individual projects and users to override those fallback labels if they are not good enough.

@wooorm
Copy link
Contributor

wooorm commented Jan 9, 2024

Just feels weird setting up an i18n system in micromark-extension-gfm-footnote or mdast-util-to-hast where folks can PR different files, say i18n/pt.js and such, and other folks use one key "label" from there. Perhaps also needs a template language and to deal with plurals for backlinks?

That doesn't feel very "out of the box" for me.

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

Successfully merging a pull request may close this issue.

4 participants