jekyll-date-basic-i18n
jekyll-date-basic-i18n copied to clipboard
Basic internationalization of dates in Jekyll (without plugin)
jekyll-date-basic-i18n
This code is a basic internationalization of dates in Jekyll without plugin. You just have to copy the include, a string file and make a correct call with the liquid tag
{% translated_date.html ... %}
Usage
Insert the following liquid tag in your code:
{% include translated_date.html date=A_DATE format=YOUR_FORMAT lang=THE_LANG_TO_USE %}
dateis the date to be used (ex:page.date)formatis the date format you want to use (ex:"%A %-d %B %Y") following the date filter syntax. If you omit this parameter the default will be:date_formatif set in the_config.yml"%b %-d, %Y"otherwise.
langis the language to use for the translation (ex:enorfr). You have to put a fileTHE_LANG_TO_USE.ymlin the_data/localesfolder. If you omitlangparameter the default will be:langset in the Front Matter of your post or page.langset in the_config.yml
This include will replace in the format string the %a (abbreviated day name), %A (full day name), %b (abbreviated month name) and %B (full month name), by the corresponding translation found in the _data/locales/[lang].yml file.
Example
{% include translated_date.html date=post.date format="%-d %B %Y" lang="pl" %}
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am "Add some feature") - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
If you find any issues, please feel free to contribute to repository issues
If you want to share your translation to others languages, make a Pull Request.
Context
This is the code I've designed when trying to localized my blog oncleben31.cc (Jekyll sources available at oncleben31/oncleben31-cc).
I've made it the more reusable possible with the idea to push it in minima, the default Jekyll theme. There is still an opened PR jekyll/minima#60 with this code and some strings to translate the theme.