gf/i18n/gi18n/gi18n.go

70 lines
2.6 KiB
Go
Raw Normal View History

2019-08-31 18:04:12 +08:00
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// Package gi18n implements internationalization and localization.
package gi18n
var (
2020-05-10 10:56:11 +08:00
// defaultManager is the default i18n instance for package functions.
2019-09-01 00:30:01 +08:00
defaultManager = Instance()
2019-08-31 18:04:12 +08:00
)
// SetPath sets the directory path storing i18n files.
func SetPath(path string) error {
2019-09-01 00:30:01 +08:00
return defaultManager.SetPath(path)
2019-08-31 18:04:12 +08:00
}
// SetLanguage sets the language for translator.
func SetLanguage(language string) {
2019-09-01 00:30:01 +08:00
defaultManager.SetLanguage(language)
2019-08-31 18:04:12 +08:00
}
// SetDelimiters sets the delimiters for translator.
func SetDelimiters(left, right string) {
2019-09-01 00:30:01 +08:00
defaultManager.SetDelimiters(left, right)
2019-08-31 18:04:12 +08:00
}
2020-05-10 10:56:11 +08:00
// T is alias of Translate for convenience.
2019-08-31 18:04:12 +08:00
func T(content string, language ...string) string {
2019-09-01 00:30:01 +08:00
return defaultManager.T(content, language...)
2019-08-31 18:04:12 +08:00
}
// 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...)
}
// TranslateFormat translates, formats and returns the <format> with configured language
// and given <values>.
func TranslateFormat(format string, values ...interface{}) string {
return defaultManager.TranslateFormat(format, values...)
}
// TranslateFormatLang translates, formats and returns the <format> with configured language
// and given <values>. The parameter <language> specifies custom translation language ignoring
// configured language. If <language> is given empty string, it uses the default configured
// language for the translation.
func TranslateFormatLang(format string, language string, values ...interface{}) string {
return defaultManager.TranslateFormatLang(format, language, values...)
}
// Translate translates <content> with configured language and returns the translated content.
2019-08-31 18:04:12 +08:00
// The parameter <language> specifies custom translation language ignoring configured language.
func Translate(content string, language ...string) string {
2019-09-01 00:30:01 +08:00
return defaultManager.Translate(content, language...)
2019-08-31 18:04:12 +08:00
}
2020-05-10 10:56:11 +08:00
// GetValue retrieves and returns the configured content for given key and specified language.
// It returns an empty string if not found.
func GetContent(key string, language ...string) string {
return defaultManager.GetContent(key, language...)
}