

i18n Golang Web Application by gettext and html/template
source link: http://siongui.github.io/2016/01/19/i18n-go-web-application-by-gettext-html-template/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

PO and MO files
I will show how to use MO and PO files by example. In the example, we support two locale, zh_TW (Traditional Chinese) and vi_VN (Vietnamese). The zh_TW PO file are located at locale/zh_TW/LC_MESSAGES/messages.po and vi_VN PO file are located at locale/vi_VN/LC_MESSAGES/messages.po.
zh_TW PO file locale/zh_TW/LC_MESSAGES/messages.po:
messages.po | repository | view raw
# Chinese translations for PACKAGE package. # Copyright (C) 2013 THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # Automatically generated, 2013. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2013-06-04 10:20+0800\n" "PO-Revision-Date: 2013-03-10 05:19+0800\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "Language: zh_TW\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" msgid "Home" msgstr "首頁" msgid "Canon" msgstr "經典" msgid "About" msgstr "關於" msgid "Setting" msgstr "設定" msgid "Translation" msgstr "翻譯"
vi_VN PO file locale/vi_VN/LC_MESSAGES/messages.po:
messages.po | repository | view raw
# Vietnamese translations for PACKAGE package. # Copyright (C) 2013 THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # Automatically generated, 2013. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2013-06-06 23:05+0800\n" "PO-Revision-Date: 2013-06-06 22:50+0800\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "Language: vi\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" msgid "Home" msgstr "Trang chính" msgid "Canon" msgstr "Kinh điển" msgid "About" msgstr "Giới thiệu" msgid "Setting" msgstr "Thiết lập" msgid "Translation" msgstr "Dịch"
Generate corresponding MO files by msgfmt. Put MO files together with PO files. So we have two PO files and two MO files:
locale/zh_TW/LC_MESSAGES/messages.po locale/zh_TW/LC_MESSAGES/messages.mo locale/vi_VN/LC_MESSAGES/messages.po locale/vi_VN/LC_MESSAGES/messages.mo
Recommend
-
11
Golang中如何让html/template不转义html标签 youngsterxyf · 2014-11-05 09:48:11 · 13997 次点击 · 预计阅读时间 2 分钟 · 不到1分钟之前 开始浏览 ...
-
5
PO and MO files I will show how to use
-
12
[Python] Internationalization (i18n) of Python Application by GNU gettext Tools January...
-
6
Golang html/template versus Python Jinja2 (2) February 24, 2015 Print He...
-
10
Golang html/template versus Python Jinja2 (5) - Maps and Dictionaries March 07,...
-
13
Source Code HTML file for demo: index.html |
-
9
GNU gettext tools are great for creating i18n (web) applications. In this post, assume that PO and
-
11
[AngularJS] gettext-like i18n Solution May 28, 2016 Client side
-
7
GNU gettext tools are great for creating i18n (web) applications. In this post, we will show how to use gettext tools, which include x...
-
2
Astro boosts HTML file control, i18n support Astro 4.3 web framework improves control over HTML file output and adds experimental domain support for inte...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK