ultrabug / mkdocs-static-i18n

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

Blog post 'mkdocs.structure.files.File object' has no attribute 'alternates' #246

Open buttle opened 11 months ago

buttle commented 11 months ago

Hi,

I'm trying to set up a mkdocs-material blog with mkdocs-static-i18n.

I keep banging my head against this error.

...
mkdocs_static_i18n/custom_i18n_sitemap/sitemap.xml", line 34
...
jinja2.exceptions.UndefinedError: 'mkdocs.structure.files.File object' has no attribute 'alternates'

I'm not sure what's happening, or even if I need a sitemap.

I can work around it like this

    {%- if file.alternates is defined -%}
      {%- for i18n_locale, i18n_file in file.alternates.items() %}

          {%- if i18n_file.page.canonical_url %}
              {%- set i18n_href = i18n_file.page.canonical_url | e %}
          {%- elif i18n_file.page.abs_url %}
              {%- set i18n_href = i18n_file.page.abs_url | e %}
          {%- else %}
              {%- if i18n_file.url == "./" %}
                  {%- set i18n_href = config.site_url %}
              {%- else %}
                  {%- set i18n_href = config.site_url ~ i18n_file.url %}
              {%- endif %}
          {%- endif %}
          <xhtml:link rel="alternate" hreflang="{{ i18n_locale }}" href="{{ i18n_href }}"/>
      {%- endfor %}
    {%- endif -%}

But that's probably not very convincing.

I'm pretty sure this also happened with the version I had installed before 1.0.0

ultrabug commented 11 months ago

@buttle hi, can you share your versions of:

and any other plugin you use?

buttle commented 11 months ago

Here's my src https://gitlab.com/liberaforms/blog.liberaforms.org

I'm not sure if this is involved so I mention it here instead of opening another issue.

I navigate to http://127.0.0.1:8000/2022/06/11/version-212/ 200 switch lang http://127.0.0.1:8000/es/posts/releases/v2.1/ 404

Setting does not help

- blog:
    post_url_format: "{categories}/{slug}"`

results in http://127.0.0.1:8000/releases/version-212/ 200 switch http://127.0.0.1:8000/es/posts/releases/v2.1/ 404

Cheers.

ultrabug commented 11 months ago

@buttle FYI we are aware with Martin of mkdocs-material that newer blog plugin versions are not compatible with the i18n plugin anymore.

I'll have to find some time to fix that in a future release and will make sure this address your problems here too.

buttle commented 11 months ago

I know it can be hard to find time, so thanks for that. Much appreciated! :)