Last modified: 2014-09-20 20:10:41 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T37752, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 35752 - Add parser function to verify that a string is a valid language code
Add parser function to verify that a string is a valid language code
Status: RESOLVED WONTFIX
Product: MediaWiki extensions
Classification: Unclassified
ParserFunctions (Other open bugs)
unspecified
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
: i18n
Depends on: 41477
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-06 07:51 UTC by Nemo
Modified: 2014-09-20 20:10 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Nemo 2012-04-06 07:51:56 UTC
It would be nice to avoid huge switches like on [[:m:Template:Other languages]] or [[:wm2012:Template:AddLanguageCategory]], and in general to maintain language codes centrally and ensure proper input of other parser functions such as #language.

Note that the example template can't be replaced by the tools in the Translate extension where the source language is not English.
Still, it can be argued that this feature is not worth a function and we should find a better way to do the things it would be used in. Compare bug 28596.
Comment 1 Siebrand Mazeland 2012-08-22 16:57:29 UTC
Could be a use case for Lua, but not as a parser function. Wikitext is not PHP.
Comment 2 Sam Reed (reedy) 2012-12-27 01:06:46 UTC
Of course, actually implementing this is rather easy... Something like:

	/**
	 * {{#validlanguage:string}}
	 *
	 * Reports whether language code is valid.
	 * @param $parser Parser
	 * @param $inStr string
	 * @return bool
	 */
	public static function runValidLanguagecode ( $parser, $inStr = '' ) {
		wfProfileIn( __METHOD__ );

		$inStr = self::killMarkers( $parser, (string)$inStr );
		$valid = Language::isValidCode( $inStr );

		wfProfileOut( __METHOD__ );
		return $valid;
	}

It could go in string functions and it could also go into core... That's the hard part
Comment 3 Nemo 2013-03-05 22:09:05 UTC
(In reply to comment #2)
> Of course, actually implementing this is rather easy... 

I'm not sure it was, but it should be now that bug 41477 was fixed.
Comment 4 Jackmcbarn 2014-09-20 19:35:32 UTC
(In reply to Siebrand Mazeland from comment #1)
> Could be a use case for Lua, but not as a parser function. Wikitext is not
> PHP.

Indeed. In fact, Lua already has mw.language.isValidCode (and a few variants) designed to do just this, so I see no reason we should add a parser function to do it.
Comment 5 Nemo 2014-09-20 20:10:41 UTC
(In reply to Jackmcbarn from comment #4)
> I see no reason we should add a
> parser function to do it.

Well, the reason is explained in comment 0. :-) However the use case was covered in Translate with bug 68385 now and templates based on this implementation would be hacky anyway, so thanks for closing this.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links