Reactive Translations
Make Translated text reactive so that when switching lang, text is reload on the fly Fixes: #77
This commit is contained in:
		@ -10,9 +10,10 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { getCookie, setCookie } from './utils.js';
 | 
					import { getCookie, setCookie } from './utils.js';
 | 
				
			||||||
 | 
					import { reactive } from 'vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const default_lang = "EN";
 | 
					const default_lang = "EN";
 | 
				
			||||||
let langs;
 | 
					const langs = reactive({});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -27,8 +28,8 @@ let langs;
 | 
				
			|||||||
export default function i18n(key, options) {
 | 
					export default function i18n(key, options) {
 | 
				
			||||||
	let ret = langs[key];
 | 
						let ret = langs[key];
 | 
				
			||||||
	if(options != null){
 | 
						if(options != null){
 | 
				
			||||||
		for (let key in options) {
 | 
							for (let option in options) {
 | 
				
			||||||
			ret = ret.replaceAll("$" + key, options[key]);
 | 
								ret = ret.replaceAll("$" + option, options[option]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return ret;
 | 
						return ret;
 | 
				
			||||||
@ -47,14 +48,12 @@ export async function loadLangs(lang){
 | 
				
			|||||||
	const content = await (await fetch(filename)).text();
 | 
						const content = await (await fetch(filename)).text();
 | 
				
			||||||
	const lines = content.split("\n");
 | 
						const lines = content.split("\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let filteredLines = {};
 | 
					 | 
				
			||||||
	for (let line of lines) {
 | 
						for (let line of lines) {
 | 
				
			||||||
		if(!line.trim().startsWith("#") && line.trim() != ""){
 | 
							if(!line.trim().startsWith("#") && line.trim() != ""){
 | 
				
			||||||
			let split = line.indexOf("=")
 | 
								let split = line.indexOf("=")
 | 
				
			||||||
			filteredLines[line.substr(0, split)] = line.substr(split+1, line.length);
 | 
								langs[line.substr(0, split)] = line.substr(split+1, line.length);
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	langs = filteredLines;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
await loadLangs();
 | 
					await loadLangs();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user