Jump to content

Topic on Extension talk:I18nTags/Flow

language code does not seem to work

5
Kghbln (talkcontribs)

Using a language code as the second parameter to languagename, as described on this page, do not seem to work anymore. To add that option again, replace the function languageName in I18nTags_body.php with this code:

	public static function languageName( &$parser, $code = '', $code2 = '' ) {
		global $wgLang;
		if ( !$code ) return '';
		$native = $code2 === 'native';
		$cldr   = is_callable(array( 'LanguageNames', 'getNames' ));
		if ( !$native && $cldr ) {
			$code2 = $code2 ? $code2 : $wgLang->getCode();
			$languages = LanguageNames::getNames( $code2,
				LanguageNames::FALLBACK_NORMAL,
				LanguageNames::LIST_MW_AND_CLDR
			);
		} else {
			$languages = Language::getLanguageNames( false );
		}

		return isset($languages[$code]) ? $languages[$code] : $code;
	}

To add the possibility to convert in the other direction (i.e. from a language name in some language to an ISO code, you need to edit three files: In I18nTags.php, add

	$parser->setFunctionHook( 'languagecode',  array($class, 'languageCode' ) );

in the function efI18nTagsInit, between wfLoadExtensionMessages. In I18nTags_body.php, add a new function like this:

	public static function languageCode( &$parser, $name = '', $lang = '' ) {
		global $wgLang;
		if ( !$name ) return '';
		$native = $lang === 'native';
		$cldr   = is_callable(array( 'LanguageNames', 'getNames' ));
		if ( !$native && $cldr ) {
			$lang = $lang ? $lang : $wgLang->getCode();
			$languages = LanguageNames::getNames( $lang,
				LanguageNames::FALLBACK_NORMAL,
				LanguageNames::LIST_MW_AND_CLDR
			);
		} else {
			$languages = Language::getLanguageNames( false );
		}

		$key = array_search($name, $languages);
		return $key ? $key : $name;
	}

and finally, in I18nTags.magic.php, add the line

	'languagecode' => array( 0, 'languagecode' ),

to the array with aliases of all languages used on your wiki, e.g. like this:

/** English (English) */
$magicWords['en'] = array(
	'languagename' => array( 0, 'languagename' ),
	'languagecode' => array( 0, 'languagecode' ),
);

This is how we use this extension at Säsongsmat.nu.

This post was posted by Kghbln, but signed as Rotsee.

Kghbln (talkcontribs)

Hmm, by judging from the amount of replies you received, I am not sure whether this extension is still maintained. Did you file a bug on bugzilla for this? You may as well provide your amendments as a patch. Cheers

Rotsee (talkcontribs)

No, I didn't yet, but I guess I should file a bug and submit a patch! rotsee (talk) 07:59, 4 October 2012 (UTC)

Kghbln (talkcontribs)

Probably you have developer access, too. In this case you could even commit the patch directly and have it reviewed and merged. I think this would even be the faster solution. I could have thought about this earlier. :( Cheers

Nikerabbit (talkcontribs)

It's unclear what is not working. Please provide minimal example.

Reply to "language code does not seem to work"