// Copyright (c) 2015, XhiveFramework Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

// for translation
xhiveframework._ = function (txt, replace, context = null) {
	if (!txt) return txt;
	if (typeof txt != "string") return txt;

	let translated_text = "";

	let key = txt; // txt.replace(/\n/g, "");
	if (context) {
		translated_text = xhiveframework._messages[`${key}:${context}`];
	}

	if (!translated_text) {
		translated_text = xhiveframework._messages[key] || txt;
	}

	if (replace && typeof replace === "object") {
		translated_text = $.format(translated_text, replace);
	}
	return translated_text;
};

window.__ = xhiveframework._;

xhiveframework.get_languages = function () {
	if (!xhiveframework.languages) {
		xhiveframework.languages = [];
		$.each(xhiveframework.boot.lang_dict, function (lang, value) {
			xhiveframework.languages.push({ label: lang, value: value });
		});
		xhiveframework.languages = xhiveframework.languages.sort(function (a, b) {
			return a.value < b.value ? -1 : 1;
		});
	}
	return xhiveframework.languages;
};
