// Copyright (c) 2015, InfluxFramework LLC
// MIT License. See license.txt

// for translation
influxframework._ = 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 = influxframework._messages[`${key}:${context}`];
	}

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

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

window.__ = influxframework._;

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