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
|
|
|
|
|
2021-05-13 00:16:45 +08:00
|
|
|
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.
|
2021-05-13 00:16:45 +08:00
|
|
|
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.
|
2021-05-13 00:16:45 +08:00
|
|
|
func Tf(ctx context.Context, format string, values ...interface{}) string {
|
|
|
|
return Instance().TranslateFormat(ctx, format, values...)
|
2020-08-08 16:46:52 +08:00
|
|
|
}
|
|
|
|
|
2021-10-21 18:22:47 +08:00
|
|
|
// TranslateFormat translates, formats and returns the `format` with configured language
|
|
|
|
// and given `values`.
|
2021-05-13 00:16:45 +08:00
|
|
|
func TranslateFormat(ctx context.Context, format string, values ...interface{}) string {
|
|
|
|
return Instance().TranslateFormat(ctx, format, values...)
|
2020-08-08 16:46:52 +08:00
|
|
|
}
|
|
|
|
|
2021-10-21 18:22:47 +08:00
|
|
|
// Translate translates `content` with configured language and returns the translated content.
|
2021-05-13 00:16:45 +08:00
|
|
|
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
|
|
|
|
2021-05-13 00:16:45 +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.
|
2021-05-13 00:16:45 +08:00
|
|
|
func GetContent(ctx context.Context, key string) string {
|
|
|
|
return Instance().GetContent(ctx, key)
|
2020-05-10 10:56:11 +08:00
|
|
|
}
|