i18next / i18next-express-middleware

[deprecated] can be replaced with i18next-http-middleware
https://github.com/i18next/i18next-http-middleware
MIT License
206 stars 52 forks source link

Cache expiration, versioning? #131

Closed adyz closed 7 years ago

adyz commented 7 years ago

Hi,

Thanks for the great i18next ecosystem, works great!

I have one issue/misunderstanding with the cache layer.

I use i18next on my express server with i18next-express-middleware and i18next-node-remote-backend

var i18next_middleware = require('i18next-express-middleware');
var i18next_backend = require('i18next-node-remote-backend');

i18next
    .use(lngDetector)
    .use(i18next_backend)
    .init({
        debug: true,
        preload: ['ro', 'en', 'bg', 'hu', 'hr', 'pl', 'si', 'sk', 'cz'],
        fallbackLng: ['ro'],
        detection: {
            order: ['langbydomain', 'querystring', 'cookie']
        },
      backend: {
        loadPath: appShell.params.apiUrl + 'translate?key=all&&_format=json&language={{lng}}',
        crossDomain: true
      }
    });

All this works fine, but when I change the remote response that returns the translations, the i18next uses the cached resources and only a node restart will make the new translations visible.

On the client side I use the i18next-localstorage-cache package and it has the cache options with versions.

cache: {

                versions: {
                    'ro': 1.2,
                    'bg': 1.2,
                    'hu': 1.2,
                    'hr': 1.2,
                    'pl': 1.2,
                    'si': 1.2,
                    'sk': 1.2,
                    'cz': 1.2,
                    'en': 1.2
                },

                enabled: true,

                // prefix for stored languages
                prefix: 'i18next_res_',

                // expiration
                expirationTime: 7*24*60*60*1000

What do I do on the node/express side when I have a new version of the translated text.

Thank you, Adrian

jamuhl commented 7 years ago

yes once loaded there will be no load again.

there is one option: call https://www.i18next.com/api.html#reloadresources on interval or on any trigger which invalidates your translations