1
// Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
// This is a gettext-go exmaple.
11
"github.com/chai2010/gettext-go/examples/hi"
12
"github.com/chai2010/gettext-go/gettext"
17
gettext.BindTextdomain("hello", "local", nil)
18
gettext.Textdomain("hello")
20
// $(LC_MESSAGES) or $(LANG) or empty
21
fmt.Println(gettext.Gettext("Gettext in init."))
22
fmt.Println(gettext.PGettext("main.init", "Gettext in init."))
24
// Output(depends on local environment):
31
gettext.SetLocale("zh_CN")
34
fmt.Println(gettext.Gettext("Gettext in init."))
35
fmt.Println(gettext.PGettext("main.init", "Gettext in init."))
40
// 来自"Hi"包的问候: 你好, 世界!
41
// 来自"Hi"包的问候: 你好, 世界!
46
fmt.Println(gettext.Gettext("Hello, world!"))
47
fmt.Println(gettext.PGettext("main.main", "Hello, world!"))
52
// 来自"Hi"包的问候: 你好, 世界!
53
// 来自"Hi"包的问候: 你好, 世界!
55
// set traditional chinese
56
gettext.SetLocale("zh_TW")
58
// traditional chinese
60
fmt.Println(gettext.Gettext("Gettext in func."))
61
fmt.Println(gettext.PGettext("main.func", "Gettext in func."))
66
// 來自"Hi"包的問候: 你好, 世界!
67
// 來自"Hi"包的問候: 你好, 世界!
73
gettext.SetLocale("zh_CN")
74
fmt.Println("poems(simple chinese):")
75
fmt.Println(string(gettext.Getdata("poems.txt")))
76
gettext.SetLocale("zh_TW")
77
fmt.Println("poems(traditional chinese):")
78
fmt.Println(string(gettext.Getdata("poems.txt")))
79
gettext.SetLocale("??")
80
fmt.Println("poems(default is english):")
81
fmt.Println(string(gettext.Getdata("poems.txt")))