<commit_before>const path = require('path');
const fs = require('fs');
const _ = require('lodash');
const settings = require('./settings');


class Translation {
    constructor(translations) {
        this.translations = translations;
        this.fixed_language = null;
    }

    getAvailableLanguages() {
        return Object.keys(this.translations);
    }

    get(key, params = {}) {
        const lang = this.getLanguage();
        let value = this.translations[lang];
        if(!value) {
            return null;
        }

        value = _.get(value, key);

        for(var param of Object.keys(params)) {
            value = value.replace(`{{${param}}}`, params[param]);
        }

        return value;
    }

    setLanguage(lang) {
        this.fixed_language = lang;
    }

    getLanguage() {
        return this.fixed_language || settings.getGeneralSettings().language;
    }

    static load(options = { path: '../', prefix: 'locale-', suffix: '.json' }) {
        const translations = {};
        const files = fs.readdirSync(options.path);
        files.filter(f => {
            return f.startsWith(options.prefix) && f.endsWith(options.suffix)
        }).forEach(f => {
            const lang = f.substring(options.prefix.length, f.length - options.suffix.length);
            translations[lang] = JSON.parse(fs.readFileSync(path.join(options.path, f)));
        });

        return new Translation(translations);
    }
}

var latest;

var translate = () => {
    return latest;
};

translate.setup = (settings, options) => {
    latest = new Translation(settings, options);
    return latest;
};

translate.load = (options) => {
    latest = Translation.load(options);
    return latest;
};

module.exports = translate;<commit_msg>Some more updates to translation setup<commit_after>const path = require('path');
const fs = require('fs');
const _ = require('lodash');
const settings = require('./settings');


class Translation {
    constructor(translations) {
        this.translations = translations;
        this.fixed_language = null;
    }

    getAvailableLanguages() {
        if(this.translations) {
            return Object.keys(this.translations);
        } else {
            return [];
        }
    }

    get(key, params = {}) {
        const lang = this.getLanguage();
        let value = this.translations[lang];
        if(!value) {
            return null;
        }

        value = _.get(value, key);

        for(var param of Object.keys(params)) {
            value = value.replace(`{{${param}}}`, params[param]);
        }

        return value;
    }

    setLanguage(lang) {
        this.fixed_language = lang;
    }

    getLanguage() {
        return this.fixed_language || settings.getGeneralSettings().language;
    }

    static load(options = { path: '../', prefix: 'locale-', suffix: '.json' }) {
        const translations = {};
        const files = fs.readdirSync(options.path);
        files.filter(f => {
            return f.startsWith(options.prefix) && f.endsWith(options.suffix)
        }).forEach(f => {
            const lang = f.substring(options.prefix.length, f.length - options.suffix.length);
            translations[lang] = JSON.parse(fs.readFileSync(path.join(options.path, f)));
        });

        return new Translation(translations);
    }
}

var latest;

var translate = () => {
    return latest;
};

translate.setup = (translations) => {
    latest = new Translation(translations);
    return latest;
};

translate.load = (options) => {
    latest = Translation.load(options);
    return latest;
};

module.exports = translate;
{'fraction_non_alphanumeric': 0.1439247163022419, 'fraction_numerical': 0.0, 'mean_word_length': 2.3998118532455317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3673799', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1002, 'n_words': 209}