Yes my theme contains this file (I’m building a theme from scratch at the moment) and I’m doing this with other translated variables.
My problem right now is, my base.html.twig contains an {% include 'partials/metadata.html.twig' %} which I assume pulls data from site.yaml first and then from the individual pages.
I would like to pass my translated strings (from languages.yaml or anywhere else if needed) to this twig function.
Maybe the language barrier made my initial questioning confusing. I hope this clears it up better.
@kroetenstuhl, Grav overrides metadata properties from site.yaml with metadata properties from the header of the page.
If you want meta properties to be translated, you can copy /system/templates/partials/metadata.html.twig into your theme’s folder /user/themes/mytheme/templates/partials and then edit that file.
Change all {{ meta.xyz | e }} into {{ meta.xyz | t | e }}
and {{ meta.content|raw }} into {{ meta.content | t | raw }}
Any meta property that has a value which is available in languages.yaml it will be translated. If the property has not translation, the value will be used verbatim.
Nothing of relevance. Am I missing something here? Do I need to declare the meta tags in there as well? Or do you mean there could be something that overrides my “site wide” ones? - In the latter case, no, none are overridíng from there.
I have tried once a simple
metadata:
description: hello
just to test if the twig template even works. The template doesn’t seem to be the problem, the meta tag is showing up when using frontmatter.
I deleted everything else from it for the testing, so all that is left now is:
en:
metadata:
'description': Hello
de:
metadata:
'description': Hallo
{% for meta in page.metadata %}
<meta {% if meta.name %}name="{{ meta.name|t|e }}" {% endif %}{% if meta.http_equiv %}http-equiv="{{ meta.http_equiv|t|e }}" {% endif %}{% if meta.charset %}charset="{{ meta.charset|t|e }}" {% endif %}{% if meta.property %}property="{{ meta.property|t|e }}" {% endif %}{% if meta.content %}content="{{ meta.content|t|raw }}" {% endif %}/>
{% endfor %}
EDIT: My site.yaml contains one statement, which would be a question for a new topic I suspect. I wanted to get rid of the generator tag, couldn’t find a way, so I just override it with something cryptic:
@kroetenstuhl, Maybe there is some misconception going on…
When using the translation filter |t in Twig, the dot-separated string, or variable containing a dot-separated string, is looked up in languages.yaml for the current language.
In you case:
{{ 'metadata.description' | t }}
will match the following in languages.yaml:
en:
metadata:
description: Hello
and print “Hello”
That means, that the values for the metadata inside site.yaml must match a string inside language.yaml.
In your case, your site.yaml (or frontmatter of page) should contain:
metadata:
description: metadata.description
Note:
Yaml rarely needs quotes. Only in case a confusion might occur.