gf/i18n/gi18n/gi18n.go

53 lines
1.7 KiB
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2019-08-31 18:04:12 +08:00
//
// 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
import "context"
2019-08-31 18:04:12 +08:00
// SetPath sets the directory path storing i18n files.
func SetPath(path string) error {
2021-03-29 17:36:51 +08:00
return Instance().SetPath(path)
2019-08-31 18:04:12 +08:00
}
// SetLanguage sets the language for translator.
func SetLanguage(language string) {
2021-03-29 17:36:51 +08:00
Instance().SetLanguage(language)
2019-08-31 18:04:12 +08:00
}
// SetDelimiters sets the delimiters for translator.
func SetDelimiters(left, right string) {
2021-03-29 17:36:51 +08:00
Instance().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.
func T(ctx context.Context, content string) string {
return Instance().T(ctx, content)
2019-08-31 18:04:12 +08:00
}
2020-10-25 17:33:14 +08:00
// Tf is alias of TranslateFormat for convenience.
func Tf(ctx context.Context, format string, values ...interface{}) string {
return Instance().TranslateFormat(ctx, format, values...)
}
// TranslateFormat translates, formats and returns the <format> with configured language
// and given <values>.
func TranslateFormat(ctx context.Context, format string, values ...interface{}) string {
return Instance().TranslateFormat(ctx, format, values...)
}
// Translate translates <content> with configured language and returns the translated content.
func Translate(ctx context.Context, content string) string {
return Instance().Translate(ctx, content)
2019-08-31 18:04:12 +08:00
}
2020-05-10 10:56:11 +08:00
// GetContent retrieves and returns the configured content for given key and specified language.
2020-05-10 10:56:11 +08:00
// It returns an empty string if not found.
func GetContent(ctx context.Context, key string) string {
return Instance().GetContent(ctx, key)
2020-05-10 10:56:11 +08:00
}