Add how-to for foreign language month names
authorRick Cogley <rick.cogley@esolia.co.jp>
Wed, 8 Jul 2015 02:09:11 +0000 (11:09 +0900)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 8 Jul 2015 05:38:52 +0000 (07:38 +0200)
FYI @nicolinuxfr, added the month name example.

docs/content/tutorials/create-a-multilingual-site.md

index 866f665b2fb426dc499d8e1cea991b80649aec51..7558277023d2f00b5f4b75efb49d862a4734dce2 100644 (file)
@@ -1,6 +1,6 @@
 ---
 author: "Rick Cogley"
-date: 2015-06-07
+date: 2015-07-08
 linktitle: Multilingual Site
 menu:
   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.
 
+## 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
 
 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.