diff --git a/.example/i18n/gi18n/gi18n.go b/.example/i18n/gi18n/gi18n.go index 5787c6481..630d5a954 100644 --- a/.example/i18n/gi18n/gi18n.go +++ b/.example/i18n/gi18n/gi18n.go @@ -2,25 +2,14 @@ package main import ( "fmt" - - "github.com/gogf/gf/i18n/gi18n" + "github.com/gogf/gf/frame/g" ) func main() { - t := gi18n.New() - t.SetPath("/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/i18n/gi18n/i18n") - t.SetLanguage("en") - fmt.Println(t.Translate(`hello`)) - fmt.Println(t.Translate(`{#hello}{#world}!`)) - - t.SetLanguage("ja") - fmt.Println(t.Translate(`hello`)) - fmt.Println(t.Translate(`{#hello}{#world}!`)) - - t.SetLanguage("ru") - fmt.Println(t.Translate(`hello`)) - fmt.Println(t.Translate(`{#hello}{#world}!`)) - - fmt.Println(t.Translate(`hello`, "zh-CN")) - fmt.Println(t.Translate(`{#hello}{#world}!`, "zh-CN")) + var ( + orderId = 865271654 + orderAmount = 99.8 + ) + fmt.Println(g.I18n().Tfl(`en`, `{#OrderPaid}`, orderId, orderAmount)) + fmt.Println(g.I18n().Tfl(`zh-CN`, `{#OrderPaid}`, orderId, orderAmount)) } diff --git a/.example/i18n/gi18n/i18n/en.toml b/.example/i18n/gi18n/i18n/en.toml index 17df41597..67762d579 100644 --- a/.example/i18n/gi18n/i18n/en.toml +++ b/.example/i18n/gi18n/i18n/en.toml @@ -1,3 +1 @@ - -hello = "Hello" -world = "World" \ No newline at end of file +OrderPaid = "You have successfully complete order #%d payment, paid amount: ¥%0.2f." \ No newline at end of file diff --git a/.example/i18n/gi18n/i18n/zh-CN.toml b/.example/i18n/gi18n/i18n/zh-CN.toml index b3a52c527..80acf06de 100644 --- a/.example/i18n/gi18n/i18n/zh-CN.toml +++ b/.example/i18n/gi18n/i18n/zh-CN.toml @@ -1,2 +1 @@ -hello = "你好" -world = "世界" \ No newline at end of file +OrderPaid = "您已成功完成订单号 #%d 支付,支付金额¥%.2f。" \ No newline at end of file diff --git a/i18n/gi18n/gi18n.go b/i18n/gi18n/gi18n.go index f8f23de71..5cb8aea0b 100644 --- a/i18n/gi18n/gi18n.go +++ b/i18n/gi18n/gi18n.go @@ -32,14 +32,14 @@ func T(content string, language ...string) string { return defaultManager.T(content, language...) } -// TF is alias of TranslateFormat for convenience. -func TF(format string, values ...interface{}) string { +// Tf is alias of TranslateFormat for convenience. +func Tf(format string, values ...interface{}) string { return defaultManager.TranslateFormat(format, values...) } -// TFL is alias of TranslateFormatLang for convenience. -func TFL(format string, language string, values ...interface{}) string { - return defaultManager.TranslateFormatLang(format, language, values...) +// Tfl is alias of TranslateFormatLang for convenience. +func Tfl(language string, format string, values ...interface{}) string { + return defaultManager.TranslateFormatLang(language, format, values...) } // TranslateFormat translates, formats and returns the with configured language @@ -52,7 +52,7 @@ func TranslateFormat(format string, values ...interface{}) string { // and given . The parameter specifies custom translation language ignoring // configured language. If is given empty string, it uses the default configured // language for the translation. -func TranslateFormatLang(format string, language string, values ...interface{}) string { +func TranslateFormatLang(language string, format string, values ...interface{}) string { return defaultManager.TranslateFormatLang(format, language, values...) } diff --git a/i18n/gi18n/gi18n_manager.go b/i18n/gi18n/gi18n_manager.go index 5586f696f..e7105c5be 100644 --- a/i18n/gi18n/gi18n_manager.go +++ b/i18n/gi18n/gi18n_manager.go @@ -124,14 +124,14 @@ func (m *Manager) T(content string, language ...string) string { return m.Translate(content, language...) } -// TF is alias of TranslateFormat for convenience. -func (m *Manager) TF(format string, values ...interface{}) string { +// Tf is alias of TranslateFormat for convenience. +func (m *Manager) Tf(format string, values ...interface{}) string { return m.TranslateFormat(format, values...) } -// TFL is alias of TranslateFormatLang for convenience. -func (m *Manager) TFL(format string, language string, values ...interface{}) string { - return m.TranslateFormatLang(format, language, values...) +// Tfl is alias of TranslateFormatLang for convenience. +func (m *Manager) Tfl(language string, format string, values ...interface{}) string { + return m.TranslateFormatLang(language, format, values...) } // TranslateFormat translates, formats and returns the with configured language @@ -144,7 +144,7 @@ func (m *Manager) TranslateFormat(format string, values ...interface{}) string { // and given . The parameter specifies custom translation language ignoring // configured language. If is given empty string, it uses the default configured // language for the translation. -func (m *Manager) TranslateFormatLang(format string, language string, values ...interface{}) string { +func (m *Manager) TranslateFormatLang(language string, format string, values ...interface{}) string { return fmt.Sprintf(m.Translate(format, language), values...) } diff --git a/i18n/gi18n/gi18n_unit_test.go b/i18n/gi18n/gi18n_unit_test.go index ea725f7e0..8e73f2841 100644 --- a/i18n/gi18n/gi18n_unit_test.go +++ b/i18n/gi18n/gi18n_unit_test.go @@ -74,24 +74,24 @@ func Test_Basic(t *testing.T) { } func Test_TranslateFormat(t *testing.T) { - // TF + // Tf gtest.C(t, func(t *gtest.T) { i18n := gi18n.New(gi18n.Options{ Path: gdebug.TestDataPath("i18n"), }) i18n.SetLanguage("none") - t.Assert(i18n.TF("{#hello}{#world} %d", 2020), "{#hello}{#world} 2020") + t.Assert(i18n.Tf("{#hello}{#world} %d", 2020), "{#hello}{#world} 2020") i18n.SetLanguage("ja") - t.Assert(i18n.TF("{#hello}{#world} %d", 2020), "こんにちは世界 2020") + t.Assert(i18n.Tf("{#hello}{#world} %d", 2020), "こんにちは世界 2020") }) - // TFL + // Tfl gtest.C(t, func(t *gtest.T) { i18n := gi18n.New(gi18n.Options{ Path: gdebug.TestDataPath("i18n"), }) - t.Assert(i18n.TFL("{#hello}{#world} %d", "ja", 2020), "こんにちは世界 2020") - t.Assert(i18n.TFL("{#hello}{#world} %d", "zh-CN", 2020), "你好世界 2020") + t.Assert(i18n.Tfl("{#hello}{#world} %d", "ja", 2020), "こんにちは世界 2020") + t.Assert(i18n.Tfl("{#hello}{#world} %d", "zh-CN", 2020), "你好世界 2020") }) }