-
Notifications
You must be signed in to change notification settings - Fork 45
Date Translation Liquid Tag
Jekyll Language Plugin also supports localized dates using the tdate
liquid filter which works in a similar fashion as the default liquid date
filter but using a language-specific date format as well as day and month name translations.
{{ expression | tdate: key_expression }}
The first argument, expression
, is a liquid expression evaluating to a Date
object, a date string or a timestamp. This is similar to the original date
filter.
The second argument, key_expression
, is an expression evaluating to the language key where the string used as the language-specific date format can be found. This can be a quoted string directly evaluating to the key or a liquid variable whose contents evaluate to the language key.
This liquid filter requires a date
subset for each language that it is being used with. This specific subset contains all day and month name translations as well as translated abbreviations.
Here is the date
subset for the English and German languages which can be copy-pasted and translated into other languages as well:
---
en:
date:
abbr_daynames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
daynames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
abbr_monthnames: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
monthnames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
de:
date:
abbr_daynames: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa']
daynames: ['Sonntag', 'Montag', 'Dienstag', 'Mitwoch', 'Donnerstag', 'Freitag', 'Samstag']
abbr_monthnames: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez']
monthnames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']
Provided there is a key post.date_format
for each language we can simply print a translated date using the following statement:
{{ post.date | tdate: 'post.date_format' }}