Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Multilingual plugin blogging error

Started by Muut Archive 11 years ago · 11 replies · 394 views
11 years ago

Hello everybody ♪

I have blog section with a collection of posts in FR, JA, and EN.
For each post, I have a blog.fr.md, a blog.ja.md and a blog.en.md.

If the post exist in the three languages, perfect.

When the post A exists in FR but not in JA and EN, the header of blog.ja.md and blog.en.md is set tovisible and hidden and so there is no display in navigation menu and in content.

Problem arrives at post level only with multilangual selector, langswitcher.

When I am reading a post A and I use the multilingual selector to change to JA or EN, I am redirected to the corresponding url adress of post A in JA or in EN ... [blog.ja.md and blog.en.md]

BUT As parameter is set to visible and hidden ... I get an error.

So my question:
How to program the multiligual selector langswitcher so that when post A is not AND visible AND hidden in JA and AN, JA and AN do not appear in the multilinguage selector langswitcher ?

Please, forgive my lack of technical knoledge to achive this issue by myself.

Here the code of the multilingual selector langswitcher for information.

---html
{% set langobj = grav['language'] %}
<li id="langswitcher" class="active"><a>[{{ langswitcher.current }}] <i class="fa fa-caret-down fa-lg"></i></a>
<ul>
{% for key, language in langswitcher.languages %}
{% if key == langswitcher.current %}
{% set lang_url = page.url %}
{% set active_class = 'active' %}
{% else %}
{% set lang_url = base_url_simple ~ langobj.getLanguageURLPrefix(key)~langswitcher.page_route ?: '/' %}
{% set active_class = '' %}
<li><a href="{{ lang_url }}" class="{{ active_class }}">[{{ key }}] {{ language.nativeName }}</a></li>
{% endif %}
{% endfor %}
</ul>
</li>


I guess it's possible to have that element thrue the call of a collection like in the documentation, but I am not able to write it correctly yet.

Thanks in advance for your help ☆

tidivoit

11 years ago

Instead of visible and hidden, try setting published: false

11 years ago

Same result... error

This a difficult issue.

Difficulty is to make langswitcher not displaying the choice of languages for posts that do not exist in those languages

Actually langswitcheronly redirect to other language, no matter if post exists or not...

11 years ago

@tidivoit I thought I couldn't help you, but actually I have an idea.

1.) Every page has a page.language returning the language code (more specifically what you provided in the filename e.g. blog.en.md -> en). You may check whether this code matches the one available from the langswitcher.

2.) The second choice is either to use page.translatedLanguages or page.untranslatedLanguages. The first returns you an array with all languages a page provides and the latter does the opposite and returns you, which languages the page doesn't provide.

With that you should be able to accomplish your goals :-)

11 years ago

Thanks you very much ♪

I'm going to try ☆

11 years ago

{{ page.language }} > works
{{ page.translatedLanguages }} > error
{{ page.translatedLanguage }}, {{ page.untranslatedLanguage }} > no error but no reaction either

Not sur I understand how to proceed though

11 years ago

Ok, thanks. Now I understood. As already written translatedLanguages and untranslatedLanguages are returning arrays. You can dump those values using {{ dump(page.translatedLanguages) }} or iterates over them with the snippets

---twig
{% for language, route in page.translatedLanguages %}
<p>language: {{ language }}<br />route: {{ route }}</p>
{% endfor %}

TWIG


or

---twig
{% for language in page.untranslatedLanguages %}
   <p>language: {{ language }}</p>
{% endfor %}
---
11 years ago

Thank you very much ♪
I'll see tomorrow ☆ and comme back to you ...
Good night

11 years ago

FYI: I'll be off for some days. Be there on Monday :-)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1118 9 years ago