ultrabug / mkdocs-static-i18n

MkDocs i18n plugin using static translation markdown files
https://ultrabug.github.io/mkdocs-static-i18n/
MIT License
237 stars 38 forks source link

Localization for `extra` and `theme` does not work #267

Closed Andygol closed 1 year ago

Andygol commented 1 year ago

I encountered the inability to apply localization to get the appropriate messages for the selected language.

I tried to reproduce the "Overriding MkDocs options per language" example, but didn't get the expected result.

Here is my code on which I tested - mkdocs-static-i18n.zip.

I've tried adding a localization for the cookie settings dialog, but no luck.

extra:
  consent:
    title: "title"
    description: "desc"
    actions:
      - accept

plugins:
  - i18n:
      docs_structure: suffix
      reconfigure_material: true
      languages:
        - locale: en
          link: 
          default: true
          name: English
          build: true
          extra:
            consent:
              title: Cookie consent
              description: >
                We use cookies to recognize your repeated visits…
image

I'm still not sure if this is some problem with the plugin itself, or if I did something wrong in mkdocs.yml.

Any help would be greatly appreciated.

PS Here is the mkdocs serve log

➜ mkdocs serve
INFO    -  Building documentation...
INFO    -  mkdocs_static_i18n: Building 'en' documentation to directory:
           /var/folders/9c/f1twq3r10fqf_5d2l7mdp3t00000gp/T/mkdocs_qqm8sjun
INFO    -  mkdocs_static_i18n: Overriding 'en' config 'copyright' with 'Copyright © 2016 - 2023 Martin
           Donath – <a href="#__consent">Change cookie settings</a>
           '
WARNING -  mkdocs_static_i18n: Unknown 'en' config override 'extra'
INFO    -  Cleaning site directory
INFO    -  mkdocs_static_i18n: Building 'uk' documentation to directory:
           /var/folders/9c/f1twq3r10fqf_5d2l7mdp3t00000gp/T/mkdocs_qqm8sjun/uk
INFO    -  mkdocs_static_i18n: Overriding 'uk' config 'copyright' with 'Copyright &copy; 2016 - 2023 Martin
           Donath – <a href="#__consent">Змінити нашлаштування репʼяшків</a>
           '
WARNING -  mkdocs_static_i18n: Unknown 'uk' config override 'extra'
WARNING -  mkdocs_static_i18n: Unknown 'uk' config override 'theme.palette'
INFO    -  Documentation built in 0.23 seconds
INFO    -  [15:52:11] Watching paths for changes: 'docs', 'mkdocs.yml'
INFO    -  [15:52:11] Serving on http://127.0.0.1:8000/
INFO    -  [15:52:15] Browser connected: http://127.0.0.1:8000/
Andygol commented 1 year ago

It appears that I've managed to change the theme color by adding a hyphen in front of primary: red. However, I'm still encountering issues with the localization for extra.consent.

        - locale: uk
          # link: /uk/
          name: Українська
          build: true
          theme:
            palette:
-              primary: red
+              - primary: red
          extra:
            consent:
              title: Репʼяшки
              description: >
                Ми використовуємо файли cookie, щоб розпізнавати ваші повторні…
image
Andygol commented 1 year ago

https://github.com/ultrabug/mkdocs-static-i18n/blob/b64fe342d1a74728af8588d5f366dae0d2382046/mkdocs_static_i18n/reconfigure.py#L85

It appears that only extra.alternate is being processed, while other items placed within the extra section are not. Could you please consider handling sub-items of extra in the same manner as sub-items of the theme section?

ultrabug commented 1 year ago

@Andygol let's separate the two problems here.

The plugin docs specify something important:

Any option you override here MUST be set (even to its default) on its main mkdocs.yml section before being overriden on one or more languages.

  1. Palette

The main mkdocs.yml palette config sets a list like this:

  palette: 

    # Palette toggle for light mode
    - media: "(prefers-color-scheme: light)"
      primary: default
      scheme: default
      toggle:
        icon: material/weather-sunny 
        name: Switch to dark mode

    # Palette toggle for dark mode
    - media: "(prefers-color-scheme: dark)"
      primary: blue grey
      scheme: slate
      toggle:
        icon: material/weather-night
        name: Switch to light mode

while you try to override a DICT

          theme:
            palette:
              primary: orange

How is the plugin supposed to know what you're trying to override here? the light or dark version of the original list?

The right way is to copy/paste the original part of the config and keep only what you want to change, it could look like this

        - locale: uk
          link: /uk/
          name: Українська
          build: true
          theme:
            palette:
              # Palette toggle for light mode
              - media: "(prefers-color-scheme: light)"
                primary: orange
                scheme: default
              # Palette toggle for dark mode
              - media: "(prefers-color-scheme: dark)"
                primary: blue grey
                scheme: slate

If you do that it works as intended, the light UK version is orange :)

ultrabug commented 1 year ago
  1. extra override

Indeed you found a bug! The proposed and tested fix is here: https://github.com/ultrabug/mkdocs-static-i18n/pull/273

Thanks

ultrabug commented 1 year ago

Fix available in version 1.1.1