MediaWiki:Gadget-LanguageUtils.js

Hello, you have come here looking for the meaning of the word MediaWiki:Gadget-LanguageUtils.js. In DICTIOUS you will not only get to know all the dictionary meanings for the word MediaWiki:Gadget-LanguageUtils.js, but we will also tell you about its etymology, its characteristics and you will know how to say MediaWiki:Gadget-LanguageUtils.js in singular and plural. Everything you need to know about the word MediaWiki:Gadget-LanguageUtils.js you have here. The definition of the word MediaWiki:Gadget-LanguageUtils.js will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofMediaWiki:Gadget-LanguageUtils.js, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.
// {{documentation}}
// implicit dependencies : ext.gadget.StorageUtils
/* jshint maxerr:1048576, strict:true, undef:true, latedef:true, es5:true, sub:true */

/* global mw, $ */

// <nowiki>

// usage:
// var lutils = new LanguageUtilsAsync();
// lutils.GetWiktionaryCodeByCanonicalName("Georgian").then(langcode => console.log(langcode));
// lutils.GetCanonicalNameByWiktionaryCode("ka").then(langname => console.log(langname));

window.LanguageUtilsAsync = function(){
	this.langNameToLangCode = new mw.Api().get({
		"action": "expandtemplates",
		"format": "json",
		"text": "{{#invoke:languages/javascript-interface|AllCanonicalToCode}}",
		"prop": "wikitext"
	}).then(function (response) {
		return JSON.parse(response.expandtemplates.wikitext);
	});

	this.langCodeToLangName = this.langNameToLangCode.then(function(name2code){
		var code2name = {};
		for (var name in name2code) 
		{
			code2name] = name;
		}
		return code2name;
	});
	
	
	this.GetWiktionaryCodeByCanonicalName = function(canonicalName){
		return this.langNameToLangCode.then(function(r){ return r;});
	};
	this.GetCanonicalNameByWiktionaryCode = function(langcode) {
		return this.langCodeToLangName.then(function(r){ return r;});
	};
};


window.LanguageUtils = function(){
	this.automaticTranslitLanguages = function(){
		return new mw.Api().get({
			"action": "expandtemplates",
			"format": "json",
			"text": "{{#invoke:languages/javascript-interface|GetLanguagesWithAutomaticTransliteration}}",
			"prop": "wikitext"
		}).then(function (response) {
			return JSON.parse(response.expandtemplates.wikitext);
		});
	};
	this.wiktionaryCodeToWikimediaCode = function(){
		return new mw.Api().get({
			"action": "expandtemplates",
			"format": "json",
			"text": "{{#invoke:languages/javascript-interface|AllWiktionaryCodeToWikimediaCode}}",
			"prop": "wikitext"
		}).then(function (response) {
			return JSON.parse(response.expandtemplates.wikitext);
		});
	};
	
	this.automaticTranslitCacheableStorage = new CacheableStorage("LanguageUtils-AutomaticTransliteration", this.automaticTranslitLanguages, 7, 1);
	this.wikimediaCodesCacheableStorage = new CacheableStorage("LanguageUtils-WikimediaCodes", this.wiktionaryCodeToWikimediaCode, 7, 1);
	
	this.HasAutomaticTransliteration = function(langcode) {
		var langs = this.automaticTranslitCacheableStorage.GetItem();
		if (langs){
			return langs || false;
		}
		return false;
	};
	this.GetWikimediaCodeByWiktionaryCode = function(langcode) {
		var wikimediaCodes = this.wikimediaCodesCacheableStorage.GetItem();
		if (wikimediaCodes && wikimediaCodes){
			return wikimediaCodes;
		}
		return null;
	};
};


window.ScriptUtils = function(){	
	this.getAllDataPromise = function(){
		return new mw.Api().get({
			"action": "expandtemplates",
			"format": "json",
			"text": "{{#invoke:languages/javascript-interface|AllLangcodeToScripts}}",
			"prop": "wikitext"
		}).then(function(r){return JSON.parse(r.expandtemplates.wikitext);});
	};
	
	this.cacheableStorage = new CacheableStorage("ScriptUtils", this.getAllDataPromise, 7, 1);
	this.GetScriptsByLangCode = function(langcode){
		var allData = this.cacheableStorage.GetItem();
		if (allData){
			var scripts = allData;
			return typeof scripts === "string" ?  : scripts;
		}
		return ;
	};
};

// </nowiki>