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

Page translation works, footer translation does not

Solved by pamtbaau View solution

Started by Daniel Dobiášovský 5 years ago · 4 replies · 841 views
5 years ago

I work with:
https://learn.getgrav.org/16/content/multi-language

I have pages:

TXT
form.en.md
form.cs.md
form.sk.md
...

Everything works as it should, but I also need to translate the footer of the website so that the text in it is translated, I wanted to solve it using the languages.yaml file, but I also need to insert links in the footer, which I can't do in the .yalm file.

The problem is as follows, the documentation says that I can work with a file in a template, for example: templates/default.sk.html.twig
So I assumed that with the file: templates/partials/footer.sk.html.twig

But I can't do that, the language isn't translated and the template still only works with basic files:

TXT
templates / default.html.twig
templates / partials / footer.html.twig

What am I doing wrong does this someone understand where I am making a mistake?

Thank you guys!

5 years ago

@Deight

I also need to insert links in the footer

  • How do your Twig snippet for the link look like?

which I can’t do in the .yalm file

  • What have you tried so far?
5 years ago

I don't know if I understand what you're asking?

I created a file: default.sk.twig
Into which I changed the path to the base:

TWIG
{% extends 'partials/base.sk.html.twig' %}

and i created a file: base.sk.html.twig
Into which I changed the path to the footer.

TWIG
     {% block footer%}
         {% include 'partials / footer.sk.html.twig'%}
     {% endblock%}

I tried:

HTML
FOOTER: '<a href="link" target="_blank">Contact</a>'

FOOTER: "<a href='link' target='_blank'>Contact</a>"

"[I'm an inline-style link](https://www.google.com)"
5 years ago Solution

@Deight, No need to use language specific templates.

  • Create file user/languages/sk.yaml and add:

    HTML
    FOOTER: '<a href="link" target="_blank">Kontakt</a>'
    
  • Create file user/languages/en.yaml and add:

    HTML
    FOOTER: '<a href="link" target="_blank">Contact</a>'
    
  • In template '/user/themes/your-child-theme/templates/partials/footer.html.twig` add:

    TWIG
    {{ 'FOOTER' | t | raw }}
    

Note that filter raw is required to insert html into the page.

👍 2
5 years ago

Don't get me wrong, but I really like you, 2 hours of rehearsals and you helped me a lot again, thank you!

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 80 9 hours ago
General · by pamtbaau, 14 hours ago
1 51 14 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago