trying to set a different language for date times with Flask-Moment
Solution 1:
I just tried this and it works just fine for me. I also happen to be the author of Flask-Moment, and also the author of the book you are reading. :)
I went to file templates/base.html
and made the following change near the bottom of the file:
{% block scripts %}
{{ super() }}
{{ moment.include_moment() }}
{{ moment.lang('es') }} <--- I added this line
{% endblock %}
Then the application shows me a very funny output half in English and half in Spanish:
The local date and time is 4 de diciembre de 2014 22:02.
That was hace unos segundos.
Note how the month, the relative timing and even the 24-hour clock were changed to a Spanish style.
Solution 2:
I wanted to have a more dynamic behavior and after looking into the Flask-Moment source code I came up with the following solution to autodetect the browser language (which works nicely for me):
{% block scripts %}
{{ super() }}
{{ moment.include_moment() }}
{{ moment.locale(auto_detect=True) }}
{% endblock %}