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 all 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 {{.url}} 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
62 changes: 54 additions & 8 deletions cmd/minikube/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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 @@ -101,12 +102,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)
})

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 @@ -127,12 +173,13 @@ 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.")

groups := templates.CommandGroups{
{
Message: "Basic Commands:",
Message: translate.T("Basic Commands:"),
Commands: []*cobra.Command{
startCmd,
statusCmd,
Expand All @@ -142,14 +189,14 @@ func init() {
},
},
{
Message: "Images Commands:",
Message: translate.T("Images Commands:"),
Commands: []*cobra.Command{
dockerEnvCmd,
cacheCmd,
},
},
{
Message: "Configuration and Management Commands:",
Message: translate.T("Configuration and Management Commands:"),
Commands: []*cobra.Command{
configCmd.AddonsCmd,
configCmd.ConfigCmd,
Expand All @@ -158,22 +205,22 @@ func init() {
},
},
{
Message: "Networking and Connectivity Commands:",
Message: translate.T("Networking and Connectivity Commands:"),
Commands: []*cobra.Command{
serviceCmd,
tunnelCmd,
},
},
{
Message: "Advanced Commands:",
Message: translate.T("Advanced Commands:"),
Commands: []*cobra.Command{
mountCmd,
sshCmd,
kubectlCmd,
},
},
{
Message: "Troubleshooting Commands:",
Message: translate.T("Troubleshooting Commands:"),
Commands: []*cobra.Command{
sshKeyCmd,
ipCmd,
Expand All @@ -185,15 +232,14 @@ func init() {
}
groups.Add(RootCmd)

// any not grouped command will show in Other Commands group.
// Ungrouped commands will show up in the "Other Commands" section
RootCmd.AddCommand(completionCmd)
templates.ActsAsRootCommand(RootCmd, []string{"options"}, groups...)

pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
if err := viper.BindPFlags(RootCmd.PersistentFlags()); err != nil {
exit.WithError("Unable to bind flags", err)
}

cobra.OnInitialize(initConfig)

}
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,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 @@ -497,7 +497,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 @@ -769,7 +769,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 @@ -33,7 +33,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 @@ -51,7 +50,6 @@ func main() {
}
out.SetOutFile(os.Stdout)
out.SetErrFile(os.Stderr)
translate.DetermineLocale()
cmd.Execute()
}

Expand Down
4 changes: 2 additions & 2 deletions hack/jenkins/minikube_cross_build_and_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ git diff ${ghprbActualCommit} --name-only \
| grep -q deploy/iso/minikube && rebuild=1 || rebuild=0

if [[ "${rebuild}" -eq 1 ]]; then
echo "ISO changes detected ... rebuilding ISO"
make release-iso
echo "ISO changes detected ... rebuilding ISO"
make release-iso
fi

cp -r test/integration/testdata out/
Expand Down
2 changes: 1 addition & 1 deletion hack/jenkins/minikube_set_pending.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs=(
'Hyper-V_Windows'
'VirtualBox_Linux'
'VirtualBox_macOS'
'VirtualBox_Windows'
'VirtualBox_Windows'
# 'KVM-GPU_Linux' - Disabled
'KVM_Linux'
'none_Linux'
Expand Down
Loading