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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Cant setup multilang site

Started by Banahan 5 months ago · 1 replies · 62 views
5 months ago

Hello fox
I’m all new to Grav, I realy like it.
But I’m facing an issu for the 10 past hours, I tryed to solved it using AI, but I hope regular old brain might help me better

My problem is about multilanguage FR | EN
Website is monacophotographer.com
I have been changing all the setting I could in sytem.yalm
I have created pages in both language, in the admin pannel I can see both language and select each language
in the folders I have tried mayny combinaison (only 2 at the same time)
default.md
default.en.md
default.fr.md

when I’m in a page in the menu, I can’t swop to the same page in the other language it keep on going back to the home in the default language
I have tried degeug with
PAGE LANGS: {{ page.languages|json_encode(constant(‘JSON_PRETTY_PRINT’)) }}
but I always get PAGE LANGS: null
it looks like both pages are not married together, but in the admin> page they are together.

I have put the change language menu ,
But it keeps putting the active URL in the other language menu
<ul class="lang-switch-manual">
{% for lang in config.system.languages.supported %}
<li>
{% if lang == grav.language.getActive %}
<span class="active" style="font-weight:bold;">{{ lang|upper }}</span>
{% else %}
{# TENTATIVE 1 : La méthode propre (Traductions liées) #}
{% set target = page.translations[lang] %}

TWIG
                {# TENTATIVE 2 (Secours) : On cherche par le dossier physique #}
                {# On reconstruit l'URL manuellement si Grav est perdu #}
                {% if not target %}
                     {# On suppose que la page FR a le slug du dossier ou son propre slug #}
                     {# C'est une astuce : on force le switch de langue sur l'URL courante #}
                     {# ATTENTION : Cela marchera uniquement si le slug est identique ou si on redirige vers la racine du dossier #}
                {% endif %}

                {% if target %}
                    <a href="{{ target.url }}">{{ lang|upper }}</a>
                {% else %}
                    {# DERNIER RECOURS : On renvoie vers l'accueil de la langue pour ne pas faire de lien mort #}
                    <a href="{{ base_url_simple }}/{{ lang }}">{{ lang|upper }}</a>
                {% endif %}
            {% endif %}
        </li>
        {% if not loop.last %}<li>|</li>{% endif %}
    {% endfor %}
</ul>

If any are used to multi language I hope you will be able to help
All the best
Lawrence

5 months ago

@Lawrence, please help the community help you and read /forum/general/the-art-of-asking-great-questions-t8554

In short:

  • show us you read the docs (e.g. https://learn.getgrav.org/17/content/multi-language).
  • what are you trying to achieve
  • provide proper information/facts like relevant configuration snippets
  • show list of extra installed plugins
  • versions of Grav and OS
  • properly format snippets of yaml, twig, php
  • explain shortly the purpose and expected outcome of a twig/php snippets instead of making us trying to understand the code.
  • are there any Grav errors?
  • are there any errors in the browser's devtools/console?

Asking the community for help starts with investing time in the question... That will hugely increase the probability someone will respond and an answer can be found.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 3 days ago
2 70 5 hours ago
General · by pamtbaau, 10 hours ago
1 45 9 hours ago
General · by Andy Miller, 22 hours ago
0 43 22 hours ago
General · by Marcel, 12 months ago
6 341 4 days ago
General · by Duc , 5 days ago
3 35 5 days ago