const files = import.meta.glob(`./locale/*.yml`);
const modules = import.meta.glob(`../pages/**/locale/*.yml`);

const translations = {};

for (const file in files) {
    const lang = file.split('/').at(2).split('.')[0];

    files[file]()
        .then((g) => {
            translations[lang] = g.default;
        })
        .finally(() => {
            const actualLang = lang + '.yml';
            for (const module in modules) {
                if (!module.endsWith(actualLang)) continue;
                modules[module]().then((t) => {
                    Object.assign(translations[lang], t.default);
                })
            }
    });
}

export const localeEquivalence = {
    en: 'en-GB',
};

export default translations;
