Charmil Localization
Localization has never been easier. Charmil provides out of the box support for the localization of your CLI.
#
How to use- Initialize factory in your command. Follow the Factory documentation
- LocalizeByID is a Factory function that takes a message Id stored in locales and also allows you to give templateEntries for your locales.
// using Localizer for localization of cobra commandcmd := &cobra.Command{ Use: cmdFactory.Localizer.LocalizeByID("sample.cmd.use"), Short: cmdFactory.Localizer.LocalizeByID("sample.cmd.short"), Example: cmdFactory.Localizer.LocalizeByID("sample.cmd.example"),}
// providing template entriescmdFactory.Localizer.LocalizeByID("sample.hi", {"Name": "John"})
#
Sample Locales fileYou must provide locales for the CLI to work. Here's a yaml-formatted sample.
# localization by idsample.cmd.use: description: "Use of sample" one: "sample"sample.cmd.short: description: "short description of sample command" one: "tell sample"sample.cmd.example: description: "Examples of sample command" one: "$ host sample"
# using templatessample.hi: description: "Say hi" one: "Hi {{.Name}}"