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

100% Statements 104/104
100% Branches 6/6
100% Functions 6/6
100% Lines 104/104

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 103 104 1051x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 18x 18x 18x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 72x 1x 1x 1x 1x 1x 1x 1x 18x 1x 1x 1x 1x 1x 1x 1x 18x 18x 18x 1x 1x 1x 1x 1x 1x 1x 18x 18x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 1x 1x 1x  
<!--
	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>
	<wl-function-editor-field class="ext-wikilambda-app-function-editor-language">
		<template #label>
			<label :id="languageFieldId">
				{{ languageLabel }}
			</label>
		</template>
		<template #body>
			<wl-z-object-selector
				class="ext-wikilambda-app-function-editor-language__add-language"
				:aria-labelledby="languageFieldId"
				:disabled="hasLanguage"
				:exclude-zids="functionLanguages"
				:selected-zid="zLanguage"
				:type="naturalLanguageType"
				@input="addNewLanguage"
			></wl-z-object-selector>
		</template>
	</wl-function-editor-field>
</template>
 
<script>
 
const { defineComponent } = require( 'vue' );
const Constants = require( '../../../Constants.js' ),
	FunctionEditorField = require( './FunctionEditorField.vue' ),
	ZObjectSelector = require( '../../base/ZObjectSelector.vue' ),
	{ mapGetters } = require( 'vuex' );
 
module.exports = exports = defineComponent( {
	name: 'wl-function-editor-language',
	components: {
		'wl-function-editor-field': FunctionEditorField,
		'wl-z-object-selector': ZObjectSelector
	},
	props: {
		zLanguage: {
			type: String,
			default: ''
		}
	},
	emits: [ 'change' ],
	data: function () {
		return {
			naturalLanguageType: Constants.Z_NATURAL_LANGUAGE
		};
	},
	computed: Object.assign( mapGetters( [
		'getMultilingualDataLanguages'
	] ), {
		/**
		 * Returns the available languages for the function definition,
		 * which includes Name, Description, Aliases and Input labels.
		 *
		 * @return {Array}
		 */
		functionLanguages: function () {
			return this.getMultilingualDataLanguages();
		},
		/**
		 * Returns the id for the language field
		 *
		 * @return {string}
		 */
		languageFieldId: function () {
			return 'ext-wikilambda-app-function-editor-language__label-id';
		},
		/**
		 * Returns the label for the language field
		 *
		 * @return {string}
		 */
		languageLabel: function () {
			// TODO (T335583): Replace i18n message with key label
			// return this.getLabelData( 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>