-
Notifications
You must be signed in to change notification settings - Fork 58
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
Allow setting global storage #80
Allow setting global storage #80
Conversation
gotext.go
Outdated
@@ -142,6 +142,30 @@ func SetLibrary(lib string) { | |||
loadStorage(true) | |||
} | |||
|
|||
// GetGlobalLocalStorage is the locale storage getter for the package configuration. | |||
func GetGlobalLocalStorage() *Locale { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename to GetStorage/SetStorage here? To maintain naming convention from other getter/setters.... unless you though of a reason to not do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I found "Storage" to be a little bit too technical as this is the internal code, where what we are doing is really setting a locale. I’m fine changing it either way and understand the symmetry argument. As this is an advanced setting, I think people using it can dive into the upstream code :)
Thank you @didrocks ! Thanks for adding the tests as well. |
By setting globalConfig.storage object, it's up to the loading wrapper to set Locale.Domains map to desired manually loaded Translators like embedding po as []bytes or so, using dedicated files… Then, the project can use gotext.Get() or any root level methods transparently. This is very useful if you want to test your code from your own repo (using embedded po files if you detect the root of your projects), while still being able to build your project and deploy to an installation, which will load from /usr/share/… Fixes: leonelquinteros#52.
Ensure we override and set expected properties on the default config object.
7f54498
to
6638bd2
Compare
No worry! Thanks for creating and maintaining this project. I just rebased and pushed renaming the Setter and Getter as discussed on the previous comment. Let me know what you think about my answer on the second one. |
@didrocks Thanks! Yes, about setting other props... either case present their inconveniences, I'll take your approach as the author of the change... |
@leonelquinteros: Thanks a lot for merging and the prompt feedback! :) |
…4376) [](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/leonelquinteros/gotext](https://github.com/leonelquinteros/gotext) | `v1.5.2` -> `v1.6.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>leonelquinteros/gotext (github.com/leonelquinteros/gotext)</summary> ### [`v1.6.0`](https://github.com/leonelquinteros/gotext/releases/tag/v1.6.0) [Compare Source](https://github.com/leonelquinteros/gotext/compare/v1.5.2...v1.6.0) #### What's Changed - Allow locale to use a `fs.FS` by [@​kobergj](https://github.com/kobergj) in [https://github.com/leonelquinteros/gotext/pull/68](https://github.com/leonelquinteros/gotext/pull/68) - Runtime translation detection by [@​m-horky](https://github.com/m-horky) in [https://github.com/leonelquinteros/gotext/pull/69](https://github.com/leonelquinteros/gotext/pull/69) - feat: Add language getter for Locale by [@​taozhou-glean](https://github.com/taozhou-glean) in [https://github.com/leonelquinteros/gotext/pull/77](https://github.com/leonelquinteros/gotext/pull/77) - Allow setting global storage by [@​didrocks](https://github.com/didrocks) in [https://github.com/leonelquinteros/gotext/pull/80](https://github.com/leonelquinteros/gotext/pull/80) - Fix multiline export by [@​didrocks](https://github.com/didrocks) in [https://github.com/leonelquinteros/gotext/pull/82](https://github.com/leonelquinteros/gotext/pull/82) - Order locations in ascii order by [@​didrocks](https://github.com/didrocks) in [https://github.com/leonelquinteros/gotext/pull/83](https://github.com/leonelquinteros/gotext/pull/83) - Fix io/fs File leak by [@​diamondburned](https://github.com/diamondburned) in [https://github.com/leonelquinteros/gotext/pull/79](https://github.com/leonelquinteros/gotext/pull/79) - Add support for multiple languages by [@​m-horky](https://github.com/m-horky) in [https://github.com/leonelquinteros/gotext/pull/73](https://github.com/leonelquinteros/gotext/pull/73) - Revert "Add support for multiple languages" by [@​leonelquinteros](https://github.com/leonelquinteros) in [https://github.com/leonelquinteros/gotext/pull/84](https://github.com/leonelquinteros/gotext/pull/84) - Remove unused dependency by [@​der-lyse](https://github.com/der-lyse) in [https://github.com/leonelquinteros/gotext/pull/86](https://github.com/leonelquinteros/gotext/pull/86) - Fix typo in documentation by [@​der-lyse](https://github.com/der-lyse) in [https://github.com/leonelquinteros/gotext/pull/87](https://github.com/leonelquinteros/gotext/pull/87) - Add support for multiple languages by [@​m-horky](https://github.com/m-horky) in [https://github.com/leonelquinteros/gotext/pull/85](https://github.com/leonelquinteros/gotext/pull/85) #### New Contributors - [@​kobergj](https://github.com/kobergj) made their first contribution in [https://github.com/leonelquinteros/gotext/pull/68](https://github.com/leonelquinteros/gotext/pull/68) - [@​m-horky](https://github.com/m-horky) made their first contribution in [https://github.com/leonelquinteros/gotext/pull/69](https://github.com/leonelquinteros/gotext/pull/69) - [@​taozhou-glean](https://github.com/taozhou-glean) made their first contribution in [https://github.com/leonelquinteros/gotext/pull/77](https://github.com/leonelquinteros/gotext/pull/77) - [@​didrocks](https://github.com/didrocks) made their first contribution in [https://github.com/leonelquinteros/gotext/pull/80](https://github.com/leonelquinteros/gotext/pull/80) - [@​diamondburned](https://github.com/diamondburned) made their first contribution in [https://github.com/leonelquinteros/gotext/pull/79](https://github.com/leonelquinteros/gotext/pull/79) - [@​der-lyse](https://github.com/der-lyse) made their first contribution in [https://github.com/leonelquinteros/gotext/pull/86](https://github.com/leonelquinteros/gotext/pull/86) **Full Changelog**: leonelquinteros/gotext@v1.5.2...v1.6.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 6am on Monday" in timezone Europe/Paris, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/cozy/cozy-stack). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yOTMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjI5My4wIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->
Is this a fix, improvement or something else?
This is an improvement as discussed on #52 about adding Getter and Setter for global config storage object.
What does this change implement/fix?
By setting globalConfig.storage object, it's up to the loading wrapper to set Locale.Domains map to desired manually loaded Translators like embedding po as []bytes or so, using dedicated files…
Another approach is to call Configure(), and by accessing the global storage object, call
AddTranslator
on it by setting a local Translator object you created.Then, the project can use gotext.Get() or any root level methods transparently.
This is very useful if you want to test your code from your own repo (using embedded po files if you detect the root of your projects), while still being able to build your project and deploy to an installation, which will load from /usr/share/…
I have ...