Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization support for help text #4814

Merged
merged 19 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d424c95
Translating help text
sharifelgamal Jul 19, 2019
97999dd
explicity set usage template so we can localize it
sharifelgamal Jul 19, 2019
a6b2d62
Merge branch 'master' of github.com:kubernetes/minikube into translat…
sharifelgamal Jul 22, 2019
16d92e6
cleaning up extract and translation files
sharifelgamal Jul 22, 2019
ec6e126
Add extraction for flags help text
sharifelgamal Jul 23, 2019
f8b5482
some comments for extract
sharifelgamal Jul 23, 2019
d25832a
refactor to account for new behavior
sharifelgamal Jul 23, 2019
98c6680
Make usage template translations more palatable.
sharifelgamal Jul 25, 2019
e81e052
remove commented code
sharifelgamal Jul 25, 2019
37d05bc
Merge branch 'master' of github.com:kubernetes/minikube into translat…
sharifelgamal Jul 26, 2019
e833452
Merge branch 'translating-snakes' of github.com:sharifelgamal/minikub…
sharifelgamal Jul 26, 2019
fb6ecc5
Merge branch 'master' of github.com:kubernetes/minikube into translat…
sharifelgamal Aug 2, 2019
4c8e315
Merge branch 'master' of github.com:kubernetes/minikube into translat…
sharifelgamal Aug 5, 2019
2147f4e
Merge branch 'master' of github.com:kubernetes/minikube into translat…
sharifelgamal Aug 7, 2019
da3c4a4
fix go mod
sharifelgamal Aug 7, 2019
3bbee54
Merge branch 'master' of github.com:kubernetes/minikube into translat…
sharifelgamal Aug 9, 2019
2c58438
pin to proper version in go.mod
sharifelgamal Aug 9, 2019
307947c
translate command grouping headers
sharifelgamal Aug 9, 2019
a215678
Merge branch 'master' of github.com:kubernetes/minikube into translat…
sharifelgamal Aug 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var profileListCmd = &cobra.Command{
validProfiles, invalidProfiles, err := config.ListProfiles()

if len(validProfiles) == 0 || err != nil {
exit.UsageT("No minikube profile was found. you could create one using: `minikube start`")
exit.UsageT("No minikube profile was found. You can create one using `minikube start`.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like "could" better than "can" it sounds more polite

}
for _, p := range validProfiles {
validData = append(validData, []string{p.Name, p.Config.MachineConfig.VMDriver, p.Config.KubernetesConfig.NodeIP, strconv.Itoa(p.Config.KubernetesConfig.NodePort), p.Config.KubernetesConfig.KubernetesVersion})
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var dashboardCmd = &cobra.Command{
if dashboardURLMode {
out.Ln(url)
} else {
out.ErrT(out.Celebrate, "Opening %s in your default browser...", out.V{"url": url})
out.T(out.Celebrate, "Opening {{.url}} in your default browser...", out.V{"url": url})
if err = browser.OpenURL(url); err != nil {
exit.WithCodeT(exit.Software, "failed to open browser: {{.error}}", out.V{"error": err})
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
// logsCmd represents the logs command
var logsCmd = &cobra.Command{
Use: "logs",
Short: "Gets the logs of the running instance, used for debugging minikube, not user code",
Short: "Gets the logs of the running instance, used for debugging minikube, not user code.",
Long: `Gets the logs of the running instance, used for debugging minikube, not user code.`,
Run: func(cmd *cobra.Command, args []string) {
cfg, err := config.Load()
Expand Down
48 changes: 47 additions & 1 deletion cmd/minikube/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/notify"
"k8s.io/minikube/pkg/minikube/translate"
)

var dirs = [...]string{
Expand Down Expand Up @@ -100,12 +101,57 @@ var RootCmd = &cobra.Command{
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
for _, c := range RootCmd.Commands() {
c.Short = translate.T(c.Short)
c.Long = translate.T(c.Long)
c.Flags().VisitAll(func(flag *pflag.Flag) {
flag.Usage = translate.T(flag.Usage)
})

c.SetUsageTemplate(usageTemplate())
}
RootCmd.Short = translate.T(RootCmd.Short)
RootCmd.Long = translate.T(RootCmd.Long)
RootCmd.Flags().VisitAll(func(flag *pflag.Flag) {
flag.Usage = translate.T(flag.Usage)
})
RootCmd.SetUsageTemplate(usageTemplate())
if err := RootCmd.Execute(); err != nil {
// Cobra already outputs the error, typically because the user provided an unknown command.
os.Exit(exit.BadUsage)
}
}

// usageTemplate just calls translate.T on the default usage template
// explicitly using the raw string instead of calling c.UsageTemplate()
// so the extractor can find this monstrosity of a string
func usageTemplate() string {
return fmt.Sprintf(`%s:{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}

%s:
{{.NameAndAliases}}{{end}}{{if .HasExample}}

%s:
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}

%s:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}

%s:
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}

%s:
{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}

%s:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}

%s{{end}}
`, translate.T("Usage"), translate.T("Aliases"), translate.T("Examples"), translate.T("Available Commands"), translate.T("Flags"), translate.T("Global Flags"), translate.T("Additional help topics"), translate.T(`Use "{{.CommandPath}} [command] --help" for more information about a command.`))
}

// Handle config values for flags used in external packages (e.g. glog)
// by setting them directly, using values from viper when not passed in as args
func setFlagsUsingViper() {
Expand All @@ -126,6 +172,7 @@ func setFlagsUsingViper() {
}

func init() {
translate.DetermineLocale()
RootCmd.PersistentFlags().StringP(config.MachineProfile, "p", constants.DefaultMachineName, `The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently.`)
RootCmd.PersistentFlags().StringP(configCmd.Bootstrapper, "b", constants.DefaultClusterBootstrapper, "The name of the cluster bootstrapper that will set up the kubernetes cluster.")
RootCmd.AddCommand(configCmd.ConfigCmd)
Expand All @@ -135,7 +182,6 @@ func init() {
if err := viper.BindPFlags(RootCmd.PersistentFlags()); err != nil {
exit.WithError("Unable to bind flags", err)
}

cobra.OnInitialize(initConfig)

}
Expand Down
8 changes: 4 additions & 4 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func showKubectlConnectInfo(kubeconfig *pkgutil.KubeConfigSetup) {
out.T(out.Kubectl, "To connect to this cluster, use: kubectl --context={{.name}}", out.V{"name": kubeconfig.ClusterName})
} else {
if !viper.GetBool(waitUntilHealthy) {
out.T(out.Ready, "kubectl has been configured configured to use {{.name}}", out.V{"name": cfg.GetMachineName()})
out.T(out.Ready, "kubectl has been configured to use {{.name}}", out.V{"name": cfg.GetMachineName()})
} else {
out.T(out.Ready, "Done! kubectl is now configured to use {{.name}}", out.V{"name": cfg.GetMachineName()})
}
Expand Down Expand Up @@ -442,7 +442,7 @@ func validateUser() {
func validateConfig() {
diskSizeMB := pkgutil.CalculateSizeInMB(viper.GetString(humanReadableDiskSize))
if diskSizeMB < pkgutil.CalculateSizeInMB(constants.MinimumDiskSize) {
exit.WithCodeT(exit.Config, "Requested disk size {{.size_in_mb}} is less than minimum of {{.size_in_mb2}}", out.V{"size_in_mb": diskSizeMB, "size_in_mb2": pkgutil.CalculateSizeInMB(constants.MinimumDiskSize)})
exit.WithCodeT(exit.Config, "Requested disk size {{.requested_size}} is less than minimum of {{.minimum_size}}", out.V{"requested_size": diskSizeMB, "minimum_size": pkgutil.CalculateSizeInMB(constants.MinimumDiskSize)})
}

err := autoSetOptions(viper.GetString(vmDriver))
Expand All @@ -452,7 +452,7 @@ func validateConfig() {

memorySizeMB := pkgutil.CalculateSizeInMB(viper.GetString(memory))
if memorySizeMB < pkgutil.CalculateSizeInMB(constants.MinimumMemorySize) {
exit.UsageT("Requested memory allocation {{.size_in_mb}} is less than the minimum allowed of {{.size_in_mb2}}", out.V{"size_in_mb": memorySizeMB, "size_in_mb2": pkgutil.CalculateSizeInMB(constants.MinimumMemorySize)})
exit.UsageT("Requested memory allocation {{.requested_size}} is less than the minimum allowed of {{.minimum_size}}", out.V{"requested_size": memorySizeMB, "minimum_size": pkgutil.CalculateSizeInMB(constants.MinimumMemorySize)})
}
if memorySizeMB < pkgutil.CalculateSizeInMB(constants.DefaultMemorySize) {
out.T(out.Notice, "Requested memory allocation ({{.memory}}MB) is less than the default memory allocation of {{.default_memorysize}}MB. Beware that minikube might not work correctly or crash unexpectedly.",
Expand Down Expand Up @@ -724,7 +724,7 @@ func validateKubernetesVersions(old *cfg.Config) (string, bool) {

nvs, err := semver.Make(strings.TrimPrefix(rawVersion, version.VersionPrefix))
if err != nil {
exit.WithCodeT(exit.Data, `Unable to parse "{{.kubenretes_version}}": {{.error}}`, out.V{"kubenretes_version": rawVersion, "error": err})
exit.WithCodeT(exit.Data, `Unable to parse "{{.kubernetes_version}}": {{.error}}`, out.V{"kubernetes_version": rawVersion, "error": err})
}
nv := version.VersionPrefix + nvs.String()

Expand Down
2 changes: 0 additions & 2 deletions cmd/minikube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/translate"
_ "k8s.io/minikube/pkg/provision"
)

Expand All @@ -47,7 +46,6 @@ func main() {
}
out.SetOutFile(os.Stdout)
out.SetErrFile(os.Stderr)
translate.DetermineLocale()
cmd.Execute()
}

Expand Down
Loading