Add how-to for foreign language month names

FYI @nicolinuxfr, added the month name example.
This commit is contained in:
Rick Cogley 2015-07-08 11:09:11 +09:00 committed by Bjørn Erik Pedersen
parent 617fa2fe65
commit a945412475

View file

@ -1,6 +1,6 @@
--- ---
author: "Rick Cogley" author: "Rick Cogley"
date: 2015-06-07 date: 2015-07-08
linktitle: Multilingual Site linktitle: Multilingual Site
menu: menu:
main: main:
@ -96,6 +96,35 @@ Now you can reference the strings in your templates. One way is to do it like in
The above shows both techniques, using an `if eq` and `else if eq` to check the locale, and using `index` to pull strings from the data file that matches the locale set in the site's config file. The above shows both techniques, using an `if eq` and `else if eq` to check the locale, and using `index` to pull strings from the data file that matches the locale set in the site's config file.
## Customize Dates
At the time of this writing, Golang does not yet have support for internationalized locales, but if you do some work, you can simulate it. For example, if you want to use French month names, you can add a data file like ``data/mois.yaml`` with this content:
~~~toml
1: "janvier"
2: "février"
3: "mars"
4: "avril"
5: "mai"
6: "juin"
7: "juillet"
8: "août"
9: "septembre"
10: "octobre"
11: "novembre"
12: "décembre"
~~~
... then index the non-English date names in your templates like so:
~~~html
<time class="post-date" datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}">
Article publié le {{ .Date.Day }} {{ index $.Site.Data.mois (printf "%d" .Date.Month) }} {{ .Date.Year }} (dernière modification le {{ .Lastmod.Day }} {{ index $.Site.Data.mois (printf "%d" .Lastmod.Month) }} {{ .Lastmod.Year }})
</time>
~~~
This technique extracts the day, month and year by specifying ``.Date.Day``, ``.Date.Month``, and ``.Date.Year``, and uses the month number as a key, when indexing the month name data file.
## Create Multilingual Content ## Create Multilingual Content
Now you can create markdown content in your languages, in the `content/en` and `content/ja` folders. The frontmatter stays the same on the key side, but the values would be set in each of the languages. Now you can create markdown content in your languages, in the `content/en` and `content/ja` folders. The frontmatter stays the same on the key side, but the values would be set in each of the languages.