All files / ext.wikilambda.edit/store/modules languages.js

66.66% Statements 6/9
100% Branches 2/2
40% Functions 2/5
66.66% Lines 6/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51              2x                     2x   2x 1x   1x                   1x                                  
/*!
 * WikiLambda Vue editor: Store module for language-related state, actions, mutations and getters
 *
 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
 * @license MIT
 */
 
module.exports = exports = {
	state: {
		currentZLanguage: mw.config.get( 'wgWikiLambda' ).zlangZid
	},
	getters: {
		/**
		 * Get the user preferred language, which is also the first element of zLangs.
		 *
		 * @return {string}
		 */
		getZLang: function () {
			var langs = mw.language.getFallbackLanguageChain();
 
			if ( langs.length > 0 ) {
				return langs[ 0 ];
			} else {
				return 'en';
			}
		},
 
		/**
		 * Get user's ZLang ZID
		 *
		 * @return {string}
		 */
		getUserZlangZID: function () {
			return mw.config.get( 'wgWikiLambda' ).zlangZid;
		},
		getCurrentZLanguage: function ( state ) {
			return state.currentZLanguage;
		}
	},
	mutations: {
		setCurrentZLanguage: function ( state, zLanguage ) {
			state.currentZLanguage = zLanguage;
		}
	},
	actions: {
		setCurrentZLanguage: function ( context, zLanguage ) {
			context.commit( 'setCurrentZLanguage', zLanguage );
		}
	}
};