0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-05 03:05:03 +00:00
VueTube/NUXT/plugins/language.js
Kenny b99b7f63a0 fix: 🚑 Fix Language Pack Memory Leak
Since language packs were added, there was a memory leak where each time you load a page containing a translated language, the active language pack would be loaded into memory (RAM) each time, after the initial load. For example, starting the app loads the memory pack into memory first, then if you open settings, it would load the pack twice. Language packs are only a few mb or kb so it wasn't major but it is fixed now.
2022-06-17 20:04:33 -04:00

34 lines
1.1 KiB
JavaScript

const packs = {
bulgarian: require('./languages/bulgarian'),
english: require('./languages/english'),
"french-fr": require('./languages/french-fr'),
german: require('./languages/german'),
italian: require('./languages/italian'),
macedonian: require('./languages/macedonian'),
malay: require('./languages/malay'),
dutch: require('./languages/dutch'),
polish: require('./languages/polish'),
spanish: require('./languages/spanish'),
"chinese-traditional": require('./languages/chinese-traditional'),
"chinese-simplified": require('./languages/chinese-simplified'),
"brazilian-portuguese": require('./languages/brazilian-portuguese'),
indonesian: require('./languages/indonesian'),
}
function module(subPack, listPacks) {
//--- List All Packs ---//
if (listPacks === true) return packs;
//--- Return Language Pack ---//
const selectedLanguage = localStorage.getItem("language") || "english";
const languagePack = packs[selectedLanguage];
if (!subPack) return languagePack;
return languagePack[subPack];
}
export default ({ app }, inject) => {
inject("lang", module);
};