How to internationalize title in Flask?

57 Views Asked by At

I'm trying to internationalize a flask webpage and I did every variable but couldn't succeed at internationalizing the title.

My code is below:

{% extends "base.html" %}{% block title %}Test Title{% endblock %}{% block content %}

I already tried this:

{% extends "base.html" %}{% block title %}_(Test Title){% endblock %}{% block content %}

and this:

{% extends "base.html" %}{% block title %}_("Test Title"){% endblock %}{% block content %}

both of them didn't work. Can you help me?

1

There are 1 best solutions below

0
On BEST ANSWER

The third one proposition is the closest, because "Test Title" is a string so it needs quotes, but you must put it into double braces {{. When your string is surrounded by _( ) it becomes a variable and the template needs the double braces to display it.

The result is : {{ _("Test Title") }}