All files / ext.wikilambda.edit/components/function/editor FunctionEditorLanguage.vue

100% Statements 22/22
100% Branches 0/0
100% Functions 7/7
100% Lines 22/22

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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102    18x 18x 18x 18x 18x                         22x                       85x               22x                   22x               22x                   5x       18x   18x     18x 18x 18x     18x     18x 18x       85x 85x                     18x
<!--
	WikiLambda Vue component for the selection of a ZNaturalLanguage object inside the Function editor.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-function-language-selector">
		<div class="ext-wikilambda-function-block__label">
			<label :id="languageFieldId">
				{{ languageLabel }}
			</label>
		</div>
		<div class="ext-wikilambda-function-block__body">
			<wl-z-object-selector
				class="ext-wikilambda-function-language-selector__add-language"
				:aria-labelledby="languageFieldId"
				:disabled="hasLanguage"
				:exclude-zids="functionLanguages"
				:selected-zid="zLanguage"
				:type="naturalLanguageType"
				@input="addNewLanguage"
			></wl-z-object-selector>
		</div>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const Constants = require( '../../../Constants.js' ),
	ZObjectSelector = require( '../../base/ZObjectSelector.vue' ),
	mapGetters = require( 'vuex' ).mapGetters;
 
module.exports = exports = defineComponent( {
	name: 'wl-function-editor-language',
	components: {
		'wl-z-object-selector': ZObjectSelector
	},
	props: {
		zLanguage: {
			type: String,
			default: ''
		}
	},
	emits: [ 'change' ],
	data: function () {
		return {
			naturalLanguageType: Constants.Z_NATURAL_LANGUAGE
		};
	},
	computed: Object.assign( mapGetters( [
		'getMetadataLanguages'
	] ), {
		/**
		 * Returns the available languages for the function definition,
		 * which includes Name, Description, Aliases and Input labels.
		 *
		 * @return {Array}
		 */
		functionLanguages: function () {
			return this.getMetadataLanguages( this.rowId );
		},
		/**
		 * Returns the id for the language field
		 *
		 * @return {string}
		 */
		languageFieldId: function () {
			return 'ext-wikilambda-function-language-selector__label-id';
		},
		/**
		 * Returns the label for the language field
		 *
		 * @return {string}
		 */
		languageLabel: function () {
			// TODO (T335583): Replace i18n message with key label
			// return this.getLabel( Constants.Z_MONOLINGUALSTRING_LANGUAGE );
			return this.$i18n( 'wikilambda-languagelabel' ).text();
		},
		/**
		 * Whether the language selector has a value or is empty
		 *
		 * @return {boolean}
		 */
		hasLanguage: function () {
			return !!this.zLanguage;
		}
	} ),
	methods: {
		/**
		 * Emits a change event when the selector is set to a new language.
		 *
		 * @param {string} lang
		 */
		addNewLanguage: function ( lang ) {
			this.$emit( 'change', lang );
		}
	}
} );
</script>