-
Notifications
You must be signed in to change notification settings - Fork 52
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
Expose the detected locale part #4
Comments
Sorry for the delayed response -- I have not had to use the i18n plugin for a while, and I think there may be better solutions out there, perhaps like https://github.com/SlexAxton/messageformat.js. So, is it that you want to get the locale that i18n has detected, around this line? If so, then I can see exposing a "getLocale()" function on the i18n module that would do that work (or used the cached value), then to get it, use i18n as a module and call that method. Is that enough? Or if you want to know what would be the first thing in the needed array on a per-load call to i18n, maybe that should be extracted as a function that maybe takes a callback? I'm a bit hesitant to add it to the value itself though, as it modifies the value as defined in the i18n modules. |
I like the i18n plugin because how simple it is to use and because of its lightweight footprint. Your first suggestion will pretty much always return For example, if
I think this is what I need.
I agree, this was just the easiest way to do it. I'm sure one can figure a better way though (callback-style or not, I don't know). Thank you. |
Let's say I want to write a requirejs plugin which would be based on i18n but including some more features like :
[{ code: "en", name: "English", root: true, current: false }, { code: "fr", name: "Français", current: true }, ...]
)Why ? Mainly in order to help providing a language picker (select menu, flags or whatever) in my applications.
Generating the array is easy but knowing which locale part has been detected by the i18n plugin is not currently possible because the value isn't exposed somehow.
In addition to making my life easier, I think appending that functionality to the official i18n requirejs plugin could be useful to other plugin developers too.
Adding something like
value._currentLocale = needed.slice(-1)[0]
just beforeonLoad(value)
(line 175) does the trick but I'm pretty sure one can find a better solution.Hopefully my english wasn't too bad and you get the point of this "issue". Thanks.
The text was updated successfully, but these errors were encountered: