funktionswerk / hapi-i18n

Translation module for hapi based on mashpie's i18n module
MIT License
39 stars 22 forks source link

How to set the languages dynamically on setLocale #12

Closed sivabalan02 closed 7 years ago

sivabalan02 commented 7 years ago

Here is my code

const register = (server, options, next) => {
    server.register(
        {
            register     : require('hapi-i18n'),
            options      : {
                directory  : __dirname + "/../../locales/backend",
                locales    : ['en'],
            },
            defaultLocale: "ar"
        }
    );

    next();
};

register.attributes = {
    name: 'Internationalization'
};

module.exports = register;

Here in my options locales, comes from database as a dynamic. How can i achieve that.

funktionswerk commented 7 years ago

Hi sivabalan,

The options are passed to mashpie's i18n module (https://github.com/mashpie/i18n-node). I guess you have to contact him for dynamic support. Alternatively I can think of reading the translations from DB and write them to the locales directory before starting the app.

sivabalan02 commented 7 years ago

@funktionswerk because of the asynchronous i can't stop the flow. I tried to set the locale option from the db itself it doesn't work. And i also contacted i18n regarding this

funktionswerk commented 7 years ago

Can you:

  1. Connect to DB
  2. Read locales and write as JSON to locales directory
  3. Initialize hapi-i18n
  4. Start the server

?