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

Translation of site title, description and metatag

Started by Muut Archive 11 years ago · 4 replies · 1705 views
11 years ago

In site configuration now I have this situation:

title: 'Stampa bollettini postali, avvisi di pagamento e modulistica'
metadata:
description: 'Web service per la produzione PDF con i dati ricevuti in formato CSV o Excel'

I need multilanguage. Is the solution below correct? Or is there one better?

site.yaml:
title: 'SITE_TITLE'
metadata:
description: 'METADATA.DESCRIPTION'

languages.yaml
en:
SITE_TITLE: title in english
METADATA.DESCRIPTION: metadata description in english
it:
SITE_TITLE: Stampa bollettini postali, avvisi di pagamento e modulistica
METADATA.DESCRIPTION: Web service per la produzione PDF con i dati ricevuti in formato CSV o Excel

11 years ago

Most themes do not translate metadata or the site title. You can do this, and add |t to the template where those values are printed. E.g. {{ site.title|e('html') }} -> {{ site.title|t|e('html') }} in partials/base.html.twig, and metadata in partials/metadata.html.twig

11 years ago

You can also put your language translations in user/languages/en.yaml, user/languages/fr.yaml, etc.

9 years ago

Here I'm tiring to translate site.yaml footer: description: of the deliver template !
So far i try to follow your advice it seam i miss something as it dos not work.

I change in the file :

In user/config/site.yaml

YAML
footer:
  description: 'Bla bla bla'

for

YAML
footer:
  description: 'SITE.FOOTER.DESCRIPTION'

In user/themes/deliver/templates/modular/footer.html.twig

TWIG
            </div>
            {% if site.footer.description %} 
                <p>{{ site.footer.description }}</p>
            {% endif %}
        </div>

for

TWIG
            </div>
            {% if site.footer.description|t %} 
                <p>{{ site.footer.description|t }}</p>
            {% endif %} 
        </div>

added user/languages/en.yaml

YAML
SITE:
  FOOTER:
    DESCRIPTION: 'My description'

added user/languages/fr.yaml

YAML
SITE:
  FOOTER:
    DESCRIPTION: 'Ma description'

What i get in the website is a text saying : SITE.FOOTER.DESCRIPTION

Which is obviously not what i want

What do I missed ? What do I do wrong ? Thank you very much for our help !

9 years ago

Never mind i find my 2 mistakes first i had a typo in user/languages folder second yaml file are case sensitive so i re wright file user/languages/fr.yaml

YAML
site:
  footer:
    description: 'Ma description'

finally it seam that "|t" is unnecessary in the if statement I so change user/themes/deliver/templates/modular/footer.html.twig

TWIG
</div>
            {% if site.footer.description %} 
                <p>{{ site.footer.description|t }}</p>
            {% endif %} 
        </div> 

Took me way to long to figure this out. I must be distracted. In the same time i can not say that GRAV tutorial are for beginner although so far I think it is the best tool for newbe if such thing exist in the world of webpage. Thanks for your comment to a new guy who know next to nothing to all those web tool.

👍 1

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1323 9 years ago
Archive · by Muut Archive, 9 years ago
2 919 9 years ago
Archive · by Muut Archive, 9 years ago
2 4048 9 years ago
Archive · by Muut Archive, 9 years ago
1 2923 9 years ago
Archive · by Muut Archive, 9 years ago
3 1106 9 years ago