-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
flag: make the "default" word localizable #42124
Comments
flag
module.
Thanks for the request. AFAIK almost nothing in the standard library is localizable, english is the default. So I think it would feel a little "out of place" maybe? |
@ALTree I understand, but this library is an user interface library. Heaving some log message in english is ok, but producing user interface that has only few non translated words is strange. Probably this should not be properly "translatable", but only made customizable. As we have |
It seems to me that programs that support localization should use the |
Alternatively, use an |
@ianlancetaylor Thank you for your advice. I think you are right. |
Here is an example of how we can do this: // Replace "default" with "par défaut" in `flag.PrintDefaults`
func PrintDefaultsFr() {
// save and restore the output (os.Stderr by default)
original := flag.CommandLine.Output()
defer flag.CommandLine.SetOutput(original)
// redirect the output to new buffer
buf := new(bytes.Buffer)
flag.CommandLine.SetOutput(buf)
// print the defaults in french
flag.PrintDefaults()
original.Write(bytes.ReplaceAll(buf.Bytes(), []byte("default"), []byte("par défaut")))
} |
In
flag
module we can write all help messages in any language, but the "default" keyword stays in english.It will be nice if the corresponding code could be made "translatable".
The text was updated successfully, but these errors were encountered: