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 | 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 4884x 4884x 4884x 4884x 4884x 4884x 4812x 4812x 4884x 7x 7x 7x 7x 7x 7x 7x 4813x 4813x 4813x 7x 7x 7x 7x 7x 7x 7x 1449x 1449x 7x 7x 7x 7x 7x 7x 7x 7x 849x 849x 849x 849x 7x 7x 7x 7x 7x 7x 7x 331x 331x 331x 331x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 226x 226x 7x 7x 7x | /*!
* WikiLambda LabelData class
*
* @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
* @license MIT
*/
'use strict';
const typeUtils = require( '../../mixins/typeUtils.js' ).methods;
/**
* LabelData class contains the information of a localized label.
* This is the type of object that's saved in the global store and
* is returned by the getter getLabelData to those components that
* need not only the string label of a key, but also the language
* of the available label.
*
* @class
* @property {string} zid ID of a ZPersistentObject, ZKey or ZArgumentDeclaration
* @property {string} label
* @property {string} lang ZID of the ZNaturalLanguage object that identifies the
* language the label is in
* @property {string} langCode language code corresponding to the lang ZID
* @property {string} langDir language directionality corresponding to the language
*/
class LabelData {
constructor( zid, label, lang, langCode = null ) {
this.zid = zid;
this.label = label;
this.lang = lang;
// Set language code and directionality
if ( langCode ) {
this.setLangCode( langCode );
}
}
/**
* Sets the language code and finds its directionality using ULS jquery library
*
* @param {string} langCode
*/
setLangCode( langCode ) {
this.langCode = langCode;
this.langDir = ( langCode && $.uls ) ? $.uls.data.getDir( langCode ) : '';
}
/**
* Returns whether the zid has no label (zid and label are equal)
*
* @return {boolean}
*/
get isUntitled() {
return this.zid === this.label;
}
/**
* Returns the label only if it's set. Else, returns the default string
* for untitled objects
*
* @return {string}
*/
get labelOrUntitled() {
return this.isUntitled ?
this.untitledString :
this.label;
}
/**
* Returns 'untitled' for Zids, or 'unlabelled' for others
*
* @return {string}
*/
get untitledString() {
return typeUtils.isValidZidFormat( this.zid ) ?
mw.message( 'wikilambda-editor-default-name' ).text() :
mw.message( 'wikilambda-about-widget-unlabelled-input' ).text();
}
/**
* Build a LabelData object from a non localized string.
*
* @param {string} text
* @param {string|undefined} langZid
* @param {string|undefined} langCode
* @return {LabelData}
*/
static fromString( text, langZid = null, langCode = null ) {
return new LabelData( null, text, langZid, langCode );
}
}
module.exports = exports = LabelData;
|