-
Notifications
You must be signed in to change notification settings - Fork 57
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
Missing support for fallback translations #70
Comments
Hey @m-horky, this sounds like a good improvement. So, how would the implementation look like? Would you extend the support for this syntax ( I'm up to support this kind of definitions, they seem appropriate, unless there are specific docs in gettext suggesting otherwise. What do you think? |
I started writing my ideas here, but then I went to check whether they were possible to do and I managed to create a proof of concept. I'm not totally happy with it, especially the functionality of I opened draft PR #73 |
Hi @leonelquinteros, when you have the time, could you look at the mentioned PR and do some fast review? It is still draft as there surely are things to improve, but I'd like to know if its ideas were something that would fit into the library. |
GNU gettext contains a support for priority lists. The
LANGUAGE
environment variable can contain multiple languages (e.g.sv:de
orsk:cs:pl
) to provide alternative translation if the primary is not available, instead of falling back to themsgid
.The current implementation of gotext does not support this; when multiple languages are specified, only the first one is loaded, the rest of the locale string is discarded.
Proposal description
Update
config
struct and methods ingotext.go
(loadStorage
,Configure
,Get*
) to handle multipleLocale
objects instead of just one.Get*
methods, instead of reaching into the only domain, would iterate over loadedLocale
s and return the string in the first language in which it is translated, keeping themsgid
as the last option.Further considerations
LANGUAGE
variable, notLC_*
orLANG
, this should be the new only implementation; the change is internal and would not alter the behavior for those who are using just one language..IsTranslated*
from PR Runtime translation detection #69 could be used to load the first available one. An alternative to this could be to pick a translations on load, and serve this string when requested -- effectively a tradeoff between startup time and memory efficiency during runtime. I lean towards the former, as it should be easier to implement and maintain, with the current structure of the code.Comments
I can create a patch containing these changes.
The text was updated successfully, but these errors were encountered: