Skip to content

Commit

Permalink
Create locales module
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobmarin committed May 30, 2021
1 parent 057dc09 commit e0c156d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
44 changes: 44 additions & 0 deletions lib/locales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const axios = require('axios');
const conf = require('./conf');
const logger = require('./logger');

const { config } = conf;

module.exports = {
get: async (options) => {
const { lang } = config.browser;
logger.info(`Fetching ${lang} locale`);
const host = options.host || config.url.host;
const version = options.version || config.url.version;
const client = `${host}/${config.url.basename}`;
const url = `${client}/locale?locale=${lang}`;
let locale;
await axios.get(url).then(async response => {
switch (version) {
case '2.2':
const { messages } = response.data;
if (messages) {
locale = messages;
} else {
logger.error(`Missing locale messages`);
}
break;
case '2.3':
const { normalizedLocale } = response.data;
const json = `${client}/locales/${normalizedLocale}.json`;
await axios.get(json).then(response => {
locale = response.data;
}).catch(error => {
logger.error(error);
});
break;
default:
logger.error(`Invalid BigBlueButton's server version: ${version}`);
}
}).catch(error => {
logger.error(error);
});

return locale;
},
};
3 changes: 2 additions & 1 deletion lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const util = require('./util');
const pool = require('./pool');
const conf = require('./conf');
const logger = require('./logger');
const locales = require('./locales');

const { api, bot, url, misc } = conf.config;

Expand Down Expand Up @@ -37,7 +38,7 @@ const run = async (actions, options = {}) => {
if (!success) return null;

// Fetch the UI labels from locale
const locale = await util.locale(options);
const locale = await locales.get(options);

let browsers = [];
for (let i = 0; i < pool.population; i++) {
Expand Down
37 changes: 0 additions & 37 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const axios = require('axios');
const faker = require('faker');
const conf = require('./conf');
const logger = require('./logger');
Expand Down Expand Up @@ -203,40 +202,4 @@ module.exports = {

return hidden;
},
locale: async (options) => {
const { lang } = config.browser;
logger.info(`Fetching ${lang} locale`);
const host = options.host || config.url.host;
const version = options.version || config.url.version;
const client = `${host}/${config.url.basename}`;
const url = `${client}/locale?locale=${lang}`;
let locale;
await axios.get(url).then(async response => {
switch (version) {
case '2.2':
const { messages } = response.data;
if (messages) {
locale = messages;
} else {
logger.error(`Missing locale messages`);
}
break;
case '2.3':
const { normalizedLocale } = response.data;
const json = `${client}/locales/${normalizedLocale}.json`;
await axios.get(json).then(response => {
locale = response.data;
}).catch(error => {
logger.error(error);
});
break;
default:
logger.error(`Invalid BigBlueButton's server version: ${version}`);
}
}).catch(error => {
logger.error(error);
});

return locale;
},
};

0 comments on commit e0c156d

Please sign in to comment.