package i18n
import "k8s.io/kubectl/pkg/util/i18n"
Index ¶
- Variables
- func Errorf(defaultValue string, args ...int) error
- func LoadTranslations(root string, getLanguageFn func() string) error
- func SetLoadTranslationsFunc(f func() error) error
- func T(defaultValue string, args ...int) string
Variables ¶
Functions ¶
func Errorf ¶
Errorf produces an error with a translated error string. Substitution is performed via the `T` function above, following the same rules.
func LoadTranslations ¶
LoadTranslations loads translation files. getLanguageFn should return a language string (e.g. 'en-US'). If getLanguageFn is nil, then the loadSystemLanguage function is used, which uses the 'LANG' environment variable.
func SetLoadTranslationsFunc ¶
SetLoadTranslationsFunc sets the function called to lazy load translations. It must be called in an init() func that occurs BEFORE any i18n.T() calls are made by any package. You can accomplish this by creating a separate package containing your init() func, and then importing that package BEFORE any other packages that call i18n.T().
Example Usage:
package myi18n import "k8s.io/kubectl/pkg/util/i18n" func init() { if err := i18n.SetLoadTranslationsFunc(loadCustomTranslations); err != nil { panic(err) } } func loadCustomTranslations() error { // Load your custom translations here... }
And then in your main or root command package, import your custom package like this:
import ( // Other imports that don't need i18n... _ "example.com/myapp/myi18n" // Other imports that do need i18n... )
func T ¶
T translates a string, possibly substituting arguments into it along the way. If len(args) is > 0, args1 is assumed to be the plural value and plural translation is used.
Source Files ¶
i18n.go
- Version
- v0.33.0 (latest)
- Published
- Apr 23, 2025
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 1 month ago –
Tools for package owners.