-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Overriding section names #11
Comments
Thank you for reporting this. It would be a good improvement. Do you have time to explore PR? I wonder if there is a more generic translation approach that could be explored here that would include any text in the gem like error messages etc. Another way would be to use the current implementation to replace the content like so: help do |sections|
@section_names.each do |name, header|
sections[name].content = sections[name].content.gsub(/#{header}/, @translations[name])
end
end |
I thought about that but struggled to come to something working.
It depends on how you wish to implement this. |
These are some "quick" thoughts. I believe this should be done in two steps. First extract all the strings from the gem source such as errors or section names and place them in messages = {
errors: {
invalid_argument: "value of `%{value}`...",
invalid_arity: "%{type} %{name} should appear..."
},
sections: {
arguments: "Arguments: ",
keywords: "Keywords: "
},
...
} Then we could have a top-level lookup method that would rely on def translate(key, **tokens)
backend.translate(key, **tokens)
end By default, the def translate(key, tokens)
message = messages[key]
if message && message.with_tokens?
message % tokens
else
message
end
end And we could also try to have Once we have messages extracted internally. Then, in the class that includes Either to directly override messages: translations["sections.arguments"] = "..."
translations["sections.keywords"] = "..." Or, allow configuration in a block that mimics translations do
backend :i18n
default_locale :en
load_path "config/locales/en.yml"
end Any translations provided via any of the two methods would be "merged" with the default messages before performing translation. As mentioned, these are some quick sketches of where we could take this. Any thoughts? |
Describe the problem
We can't translate section names.
How would the new feature work?
Adding an additional
section_names:
option toTTY::Option::Formatter#initialize
.Drawbacks
None I can think of.
Workaround
Hardcore ugly monkey patching, e.g. for French translation
The text was updated successfully, but these errors were encountered: