getgrav / grav-theme-agency

Agency Theme for Grav
https://getgrav.org
MIT License
27 stars 36 forks source link

multilingual support for navigation bar #11

Closed cravussin closed 8 years ago

cravussin commented 8 years ago

Hello,

It seems that the theme doesn't support multilingual content, i.e. the navigation bar items (about, portfolio, etc...) cannot be displayed in another language. Any tips to work around that?

flaviocopes commented 8 years ago

Did you read how multilanguage works in Grav? https://learn.getgrav.org/content/multi-language

You need to setup language-specific pages, then their title will be used in the menu.

cravussin commented 8 years ago

Yes I read the documentation. In the agency theme the links that show up in the navbar are defined in site.yaml, under the "links:" section.

The site.yaml file does not support multilingual, that's why I opened an issue.

flaviocopes commented 8 years ago

Oh I see they are on-page links, not real pages.

It's not built with multilang in mind, you can do that by having in site.yaml


links:
  en:
    - title: MY_TRANSLATION_STRING
      url: '#services'

and edit themes/agency/templates/partials/navigation.html.twig line 29 so it translates the string, like

{{ link.title|t }}

instead of {{ link.title }}.

Then add that string translations in your user/languages/ (https://learn.getgrav.org/content/multi-language#translation-overrides)

cravussin commented 8 years ago

I'll try that and let you know, many thanks for the info.

cravussin commented 8 years ago

Unfortunately it doesn't seem to be working, all the items in the navbar have disappeared .. Here's the modified line is navigation.html.twig:

<li><a class="page-scroll" href="{{ domain }}{{ link.url }}" {% if link.url | contains('http') %}target="_blank"{% endif %}>{{ link.title|t }}</a></li>

Here's the links section of the site.yaml file:

links: fr:

It doesn't work with translation overrides neither.

flaviocopes commented 8 years ago

That's not what I suggested. That snippet you posted is not supposed to work. link.title is not existing. Use {{ dump(link) }} to check its content in the debug bar https://learn.getgrav.org/advanced/debugging#debug-bar

Also, the structure of the YAML is not right.

links:
  fr:
    title: Avantages
    url: '#avantages'

should do.

You would have link.fr.title maybe, which needs to be accessed in a different way in Twig, something like {{ link[grav.language.language].title }}

cravussin commented 8 years ago

I managed to make it work by using per language twig templates (templates/en/partials/navigation.html.twig) and using

{% for link in site.links.en %}

and 

{% for link in site.links.fr %} in the default template

I removed the translation filters.

Not the most elegant stuff but hey it works! 

--  On 30 juin 2016 at 13:12:14, Flavio Copes (notifications@github.com) wrote:

That's not what I suggested. That snippet you posted is not supposed to work. link.title is not existing. Use {{ dump(link) }} to check its content in the debug bar https://learn.getgrav.org/advanced/debugging#debug-bar

Also, the structure of the YAML is not right.

links: fr: title: Avantages url: '#avantages'

should do.

You would have link.fr.title maybe, which needs to be accessed in a different way in Twig, something like {{ link[grav.language.language].title }}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

johannesE commented 7 years ago

I just lost hours because of this. :/ Should've checked these issues earlier.