github.com/gogf/gf/v2@v2.7.4/i18n/gi18n/gi18n.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 // Package gi18n implements internationalization and localization. 8 package gi18n 9 10 import "context" 11 12 // SetPath sets the directory path storing i18n files. 13 func SetPath(path string) error { 14 return Instance().SetPath(path) 15 } 16 17 // SetLanguage sets the language for translator. 18 func SetLanguage(language string) { 19 Instance().SetLanguage(language) 20 } 21 22 // SetDelimiters sets the delimiters for translator. 23 func SetDelimiters(left, right string) { 24 Instance().SetDelimiters(left, right) 25 } 26 27 // T is alias of Translate for convenience. 28 func T(ctx context.Context, content string) string { 29 return Instance().T(ctx, content) 30 } 31 32 // Tf is alias of TranslateFormat for convenience. 33 func Tf(ctx context.Context, format string, values ...interface{}) string { 34 return Instance().TranslateFormat(ctx, format, values...) 35 } 36 37 // TranslateFormat translates, formats and returns the `format` with configured language 38 // and given `values`. 39 func TranslateFormat(ctx context.Context, format string, values ...interface{}) string { 40 return Instance().TranslateFormat(ctx, format, values...) 41 } 42 43 // Translate translates `content` with configured language and returns the translated content. 44 func Translate(ctx context.Context, content string) string { 45 return Instance().Translate(ctx, content) 46 } 47 48 // GetContent retrieves and returns the configured content for given key and specified language. 49 // It returns an empty string if not found. 50 func GetContent(ctx context.Context, key string) string { 51 return Instance().GetContent(ctx, key) 52 }