Extension talk:I18nTags

From MediaWiki.org
Jump to: navigation, search
Start a new discussion

Contents

Thread titleRepliesLast modified
language code does not seem to work016:35, 31 October 2011

language code does not seem to work

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.

//rotsee 12:07, 29 October 2011 (UTC)16:35, 31 October 2011
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox