return mw.jqueryMsg.getMessageFunction()( msg.charAt( 0 ).toLowerCase() + msg.slice( 1 ) );
},
+ /**
+ * Get localized namespace name from canonical name or namespace number.
+ * Invoked by putting `{{ns:foo}}` into a message
+ *
+ * @param {Array} nodes List of nodes
+ * @return {string} Localized namespace name
+ */
+ ns: function ( nodes ) {
+ var ns = $.trim( textify( nodes[ 0 ] ) );
+ if ( !/^\d+$/.test( ns ) ) {
+ ns = mw.config.get( 'wgNamespaceIds' )[ ns.replace( / /g, '_' ).toLowerCase() ];
+ }
+ ns = mw.config.get( 'wgFormattedNamespaces' )[ ns ];
+ return ns || '';
+ },
+
/**
* Takes an unformatted number (arab, no group separators and . as decimal separator)
* and outputs it in the localized digit script and formatted with decimal
mw.language = this.originalMwLanguage;
},
config: {
- wgArticlePath: '/wiki/$1'
+ wgArticlePath: '/wiki/$1',
+ // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
+ wgNamespaceIds: {
+ template: 10,
+ template_talk: 11,
+ // Localised
+ szablon: 10,
+ dyskusja_szablonu: 11
+ },
+ // jscs:enable requireCamelCaseOrUpperCaseIdentifiers
+ wgFormattedNamespaces: {
+ // Localised
+ 10: 'Szablon',
+ 11: 'Dyskusja szablonu'
+ }
},
// Messages that are reused in multiple tests
messages: {
);
} );
+ QUnit.test( 'Ns', 4, function ( assert ) {
+ mw.messages.set( 'ns-template-talk', '{{ns:Template talk}}' );
+ assert.equal(
+ formatParse( 'ns-template-talk' ),
+ 'Dyskusja szablonu',
+ 'ns: returns localised namespace when used with a canonical namespace name'
+ );
+
+ mw.messages.set( 'ns-10', '{{ns:10}}' );
+ assert.equal(
+ formatParse( 'ns-10' ),
+ 'Szablon',
+ 'ns: returns localised namespace when used with a namespace number'
+ );
+
+ mw.messages.set( 'ns-unknown', '{{ns:doesnt-exist}}' );
+ assert.equal(
+ formatParse( 'ns-unknown' ),
+ '',
+ 'ns: returns empty string for unknown namespace name'
+ );
+
+ mw.messages.set( 'ns-in-a-link', '[[{{ns:template}}:Foo]]' );
+ assert.equal(
+ formatParse( 'ns-in-a-link' ),
+ '<a title="Szablon:Foo" href="/wiki/Szablon:Foo">Szablon:Foo</a>',
+ 'ns: works when used inside a wikilink'
+ );
+ } );
+
// Tests that getMessageFunction is used for non-plain messages with curly braces or
// square brackets, but not otherwise.
QUnit.test( 'mw.Message.prototype.parser monkey-patch', 22, function ( assert ) {