i18next / i18next-localstorage-backend

This is a i18next cache layer to be used in the browser. It will load and cache resources from localStorage and can be used in combination with the chained backend.
MIT License
88 stars 43 forks source link

Dynamic versions #20

Closed dcporter44 closed 4 years ago

dcporter44 commented 4 years ago

It would be great if this library could have an option to allow for a version to be passed with the incoming XHR response. If the version of the response JSON is different from version of the localStorage JSON, then the localStorage data is updated. The order of events would be:

  1. i18next first loads from localStorage like normal.
  2. In background, i18next sends an XHR request to backend. If the version of the response is different from version stored in localStorage, then update localstorage with newest version and load newest version.

In this scenario the current version number would also be stored in localStorage. It would be compared against the XHR response's version. The XHR response could provide the version number in an HTTP header, or perhaps a dedicated string key in the file that is named something like "I18NEXT_VERSION_NUMBER".

This would be really useful as a developer so I don't have to manually change the version number on the frontend every time I have a new version on my server.

dcporter44 commented 4 years ago

Another alternative could be to provide an option called latestVersionNumberPath for getting the current version on the server. { latestVersionNumberPath: "https://api.mywebsite.com/get-my-version-number?lng={{lng}}" }

This would be triggered every time data is loaded from localStorage. If the response from this request has a different version number from the current version, then use fallback to XHR to get latest.

jamuhl commented 4 years ago

Sounds great. Just implementing this with current backends might be more tricky than it needs -> xhr-backend, localStorage-backend in combination with the chained-backend...

Not sure but somehow my guess is - this would be simpler to be implemented in one backend having both integrated the localStorage and xhr functionality...what do you think?

dcporter44 commented 4 years ago

Yeah, I'm not exactly clear on the relationship between chained-backend and localstorage-backend, so you would know more about the best way to implement this. Are you saying it would be simpler to make a whole new library for this?

jamuhl commented 4 years ago

take your time - have a look at those libs. yes, my guess is a simple plugin doing this would be simpler then patching all this 3 plugins to make it work

vorasudh commented 3 years ago

Is the issue closed because this functionality is already implemented in current versions?

adrai commented 3 years ago

@vorasudh yes, check the backend options in the readme