Jump to content

User:BraneJ/Serbian Variants

From Meta, a Wikimedia project coordination wiki
Content in this page is out of date!

Update: This is now bug #3993. Also, it was brought to my attention that Mediawiki developers use tabs instead of spaces. Personally, I disagree with that, but as they say "When in Rome...". Accordingly, this files are retabbed and page is a bit uglier than it used to be ;).

Introduction

[edit]

These are the files/changes that are part of my "quick 'n' not so much dirty anymore" Serbian language variants hack - diff titles are only partial content of the file (you don't say :)), rest are complete files. Note that LanguageSr.php becomes LanguageSr_ec.php before any other changes. Lines in Names.php are there so that user can choose a variant in user settings, and those in Language.php so that users of other languages don't see the <variantname-XX> on tabs, and variant names in LanguageSr_ec.php are for navigation tabs. All files go into the languages subfolder.

Previously, this was done as an extension, but I have since learned a bit ;), so now no changes to any settings are needed, only (re)placement of the files.

Diff between LanguageSr.php and LanguageSr_ec.php

[edit]

Rename LanguageSr.php to LanguageSr_ec.php and change the variable and class names:

--- LanguageSr.php	2005-08-19 20:54:41.000000000 +0200
+++ LanguageSr_ec.php	2005-11-15 18:44:16.000000000 +0100
@@ -13,7 +13,7 @@
 # are magical, so don't change or move them!  The Namespace class
 # encapsulates some of the magic-ness.
 #
-/* private */ $wgNamespaceNamesSr = array(
+/* private */ $wgNamespaceNamesSr_ec = array(
 	NS_MEDIA            => "Media",
 	NS_SPECIAL          => "Посебно",
 	NS_MAIN             => "",
@@ -34,15 +34,15 @@
 	NS_CATEGORY_TALK    => 'Разговор_о_категорији',
 ) + $wgNamespaceNamesEn;
 
-/* private */ $wgQuickbarSettingsSr = array(
+/* private */ $wgQuickbarSettingsSr_ec = array(
  "Никаква", "Причвршћена лево", "Причвршћена десно", "Плутајућа лево"
 );
 
-/* private */ $wgSkinNamesSr = array(
+/* private */ $wgSkinNamesSr_ec = array(
  "Обична", "Носталгија", "Келнско плаво", "Педингтон", "Монпарнас"
 ) + $wgSkinNamesEn;
 
-/* private */ $wgDateFormatsSr = array(
+/* private */ $wgDateFormatsSr_ec = array(
 	'Није битно',
 	'06:12, 5. јануар 2001.',
 	'06:12, 5 јануар 2001',
@@ -61,7 +61,7 @@
 
 
 /* NOT USED IN STABLE VERSION */
-/* private */ $wgMagicWordsSr = array(
+/* private */ $wgMagicWordsSr_ec = array(
 #   ID                                 CASE  SYNONYMS
 	MAG_REDIRECT             => array( 0,    "#преусмери"              ),
 	MAG_NOTOC                => array( 0,    "__БЕЗСАДРЖАЈА__"              ),
@@ -78,7 +78,13 @@
 	MAG_MSGNW                => array( 1,    "{{НВПОР:$1}}"           )
 );
 
-/* private */ $wgAllMessagesSr = array(
+/* private */ $wgAllMessagesSr_ec = array(
+# Називи варијанти - не дирати! (сем ако не желите да мењате)
+'variantname-sr-ec' => 'екавски',
+'variantname-sr-jc' => 'ијекавски',
+'variantname-sr-el' => 'ekavski',
+'variantname-sr-jl' => 'ijekavski',
+'variantname-sr' => 'disable',
 
 # User Toggles
 #
@@ -981,17 +987,17 @@
 # Internationalisation code
 #--------------------------------------------------------------------------
 
-class LanguageSr extends LanguageUtf8 {
+class LanguageSr_ec extends LanguageUtf8 {
 
 	function getNamespaces() {
-	global $wgNamespaceNamesSr;
-	return $wgNamespaceNamesSr;
+	global $wgNamespaceNamesSr_ec;
+	return $wgNamespaceNamesSr_ec;
 	}
 
 	function getNsIndex( $text ) {
-	global $wgNamespaceNamesSr;
+	global $wgNamespaceNamesSr_ec;
 
-	foreach ( $wgNamespaceNamesSr as $i => $n ) {
+	foreach ( $wgNamespaceNamesSr_ec as $i => $n ) {
 		if ( 0 == strcasecmp( $n, $text ) ) { return $i; }
 	}
 	if( 0 == strcasecmp( "Special", $text ) ) { return -1; }
@@ -1001,24 +1007,24 @@
 	}
 
 	function getQuickbarSettings() {
-	global $wgQuickbarSettingsSr;
-	return $wgQuickbarSettingsSr;
+	global $wgQuickbarSettingsSr_ec;
+	return $wgQuickbarSettingsSr_ec;
 	}
 
 	function getSkinNames() {
-	global $wgSkinNamesSr;
-	return $wgSkinNamesSr;
+	global $wgSkinNamesSr_ec;
+	return $wgSkinNamesSr_ec;
 	}
 
 	function getDateFormats() {
-	global $wgDateFormatsSr;
-	return $wgDateFormatsSr;
+	global $wgDateFormatsSr_ec;
+	return $wgDateFormatsSr_ec;
 	}
 
 	function getMessage( $key ) {
-		global $wgAllMessagesSr;
-		if(array_key_exists($key, $wgAllMessagesSr))
-			return $wgAllMessagesSr[$key];
+		global $wgAllMessagesSr_ec;
+		if(array_key_exists($key, $wgAllMessagesSr_ec))
+			return $wgAllMessagesSr_ec[$key];
 		else
 			return parent::getMessage($key);
 	}

LanguageSr.php

[edit]
<?php
/**
  * @package MediaWiki
  * @subpackage Language
  */

/*
	There are two levels of conversion for Serbian: the script level
	(Cyrillics <-> Latin), and the variant level (ekavian
	<->iyekavian). The two are orthogonal. So we really only need two
	dictionaries: one for Cyrillics and Latin, and one for ekavian and
	iyekavian.
*/
require_once( "LanguageConverter.php" );
require_once( "LanguageSr_ec.php" );
require_once( "LanguageSr_el.php" );
require_once( "LanguageSr_jc.php" );
require_once( "LanguageSr_jl.php" );

class SrConverter extends LanguageConverter {
	var $mToLatin = array(
		'а' => 'a', 'б' => 'b',  'в' => 'v', 'г' => 'g',  'д' => 'd',
		'ђ' => 'đ', 'е' => 'e',  'ж' => 'ž', 'з' => 'z',  'и' => 'i',
		'ј' => 'j', 'к' => 'k',  'л' => 'l', 'љ' => 'lj', 'м' => 'm',
		'н' => 'n', 'њ' => 'nj', 'о' => 'o', 'п' => 'p',  'р' => 'r',
		'с' => 's', 'т' => 't',  'ћ' => 'ć', 'у' => 'u',  'ф' => 'f',
		'х' => 'h', 'ц' => 'c',  'ч' => 'č', 'џ' => 'dž', 'ш' => 'š',

		'А' => 'A', 'Б' => 'B',  'В' => 'V', 'Г' => 'G',  'Д' => 'D',
		'Ђ' => 'Đ', 'Е' => 'E',  'Ж' => 'Ž', 'З' => 'Z',  'И' => 'I',
		'Ј' => 'J', 'К' => 'K',  'Л' => 'L', 'Љ' => 'Lj', 'М' => 'M',
		'Н' => 'N', 'Њ' => 'Nj', 'О' => 'O', 'П' => 'P',  'Р' => 'R',
		'С' => 'S', 'Т' => 'T',  'Ћ' => 'Ć', 'У' => 'U',  'Ф' => 'F',
		'Х' => 'H', 'Ц' => 'C',  'Ч' => 'Č', 'Џ' => 'Dž', 'Ш' => 'Š',
	);

	var $mToCyrillics = array(
		'a' => 'а', 'b'  => 'б', 'c' => 'ц', 'č' => 'ч', 'ć'  => 'ћ',
		'd' => 'д', 'dž' => 'џ', 'đ' => 'ђ', 'e' => 'е', 'f'  => 'ф',
		'g' => 'г', 'h'  => 'х', 'i' => 'и', 'j' => 'ј', 'k'  => 'к',
		'l' => 'л', 'lj' => 'љ', 'm' => 'м', 'n' => 'н', 'nj' => 'њ',
		'o' => 'о', 'p'  => 'п', 'r' => 'р', 's' => 'с', 'š'  => 'ш',
		't' => 'т', 'u'  => 'у', 'v' => 'в', 'z' => 'з', 'ž'  => 'ж',

		'A' => 'А', 'B'  => 'Б', 'C' => 'Ц', 'Č' => 'Ч', 'Ć'  => 'Ћ',
		'D' => 'Д', 'Dž' => 'Џ', 'Đ' => 'Ђ', 'E' => 'Е', 'F'  => 'Ф',
		'G' => 'Г', 'H'  => 'Х', 'I' => 'И', 'J' => 'Ј', 'K'  => 'К',
		'L' => 'Л', 'LJ' => 'Љ', 'M' => 'М', 'N' => 'Н', 'NJ' => 'Њ',
		'O' => 'О', 'P'  => 'П', 'R' => 'Р', 'S' => 'С', 'Š'  => 'Ш',
		'T' => 'Т', 'U'  => 'У', 'V' => 'В', 'Z' => 'З', 'Ž'  => 'Ж',

		'DŽ' => 'Џ', 'd!ž' => 'дж', 'D!ž'=> 'Дж', 'D!Ž'=> 'ДЖ',
		'Lj' => 'Љ', 'l!j' => 'лј', 'L!j'=> 'Лј', 'L!J'=> 'ЛЈ',
		'Nj' => 'Њ', 'n!j' => 'нј', 'N!j'=> 'Нј', 'N!J'=> 'НЈ'
	);

	function loadDefaultTables() {
		$this->mTables = array();
		$this->mTables['sr-ec'] = $this->mToCyrillics;
		$this->mTables['sr-jc'] = $this->mToCyrillics;
		$this->mTables['sr-el'] = $this->mToLatin;
		$this->mTables['sr-jl'] = $this->mToLatin;
		$this->mTables['sr'] = array();
	}

	/* rules should be defined as -{ekavian | iyekavian}- -or-
		-{code:text | code:text |...}-
	*/
	function parseManualRule($rule, $flags) {

		$choices = explode($this->mMarkup['varsep'], $rule);
		$carray = array();
		if(sizeof($choices) == 1) {
			if(in_array('W', $flags)) {
				$carray['sr'] = $this->autoConvert($choices[0], 'sr-ec');
				$carray['sr-ec'] = $this->autoConvert($choices[0], 'sr-ec');
				$carray['sr-jc'] = $this->autoConvert($choices[0], 'sr-jc');
				$carray['sr-el'] = $this->autoConvert($choices[0], 'sr-el');
				$carray['sr-jl'] = $this->autoConvert($choices[0], 'sr-jl');
			}
			foreach($this->mVariants as $v) {
				$carray[$v] = $choices[0];
			}
			return $carray;
		}

		/* detect which format is used, also trim the choices*/
		$n=0;
		foreach($choices as $c=>$t) {
			if(strpos($t, $this->mMarkup['codesep']) !== false)
				$n++;
			$choices[$c] = trim($t);
		}
		/* the -{code:text | ...}- format */
		if($n == sizeof($choices)) {
			foreach($choices as $c) {
				list($code, $text) = explode($this->mMarkup['codesep'], $c);
				$carray[trim($code)] = trim($text);
			}
			return $carray;
		}

		/* the two choice format -{choice1; choice2}-*/
		if(sizeof($choices == 2) && $n==0) {
			if(in_array('S', $flags)) {
				// conversion between Cyrillics and Latin
				$carray['sr'] = $carray['sr-ec'] =$carray['sr-jc'] = $choices[0];
				$carray['sr-el'] =$carray['sr-jl'] = $choices[1];
			}
			else {
				$carray['sr'] = $this->autoConvert($choices[0], 'sr-ec');
				$carray['sr-ec'] = $this->autoConvert($choices[0], 'sr-ec');
				$carray['sr-jc'] = $this->autoConvert($choices[1], 'sr-jc');
				$carray['sr-el'] = $this->autoConvert($choices[0], 'sr-el');
				$carray['sr-jl'] = $this->autoConvert($choices[1], 'sr-jl');
			}
			return $carray;
		}
		return $carray;
	}

}

class LanguageSr extends LanguageSr_ec {
	function LanguageSr() {
		global $wgHooks;
		$variants         = array('sr', 'sr-ec', 'sr-jc', 'sr-el', 'sr-jl');
		$variantfallbacks = array(
			'sr'    => 'sr-ec',
			'sr-ec' => 'sr-jc',
			'sr-jc' => 'sr-ec',
			'sr-el' => 'sr-jl',
			'sr-jl' => 'sr-el'
		);
		$marker = array();//fon't mess with these :)
		$flags = array(
			'S' => 'S', 'писмо' => 'S', 'pismo' => 'S',
			'W' => 'W', 'реч'   => 'W', 'reč'   => 'W', 'ријеч' => 'W', 'riječ' => 'W'
		);
		$this->mConverter = new SrConverter(
			$this, 'sr', $variants, $variantfallbacks, $marker, $flags);
		$wgHooks['ArticleSaveComplete'][] = $this->mConverter;
		$wgHooks['SkinTemplateContentActions'][] = array($this, 'mContActions');
	}
	function getVariantname( $code ) {
		return wfMsg( "variantname-$code" );
	}

	/**
	 * basic ideas behind this method:
	 * pull variant all the way to the left & hide the namespace tab
	 * EXCEPT if this is a talk page or a system message (NS_MEDIAWIKI)
	 * (we want those to remain as they are, don't transliterate then EVER)
	 */
	function mContActions(&$content_actions) {
		global $wgTitle;
		$fname="LanguageSr::mContActions";
		wfProfileIn( $fname );
		$actions = array();
		$variants = array();
		$Namespace = $wgTitle->getNamespace();
		if (Namespace::isTalk($Namespace)) {
		//this is some talk page, don't display variants
			foreach ($content_actions as $key => $value) {
				if (strpos($key,'varlang') === FALSE) {
					$actions[$key] = $value;
				}
			}
		} else {
		//NOT in talk namespace, namespace tab is not needed anymore...
			$NS = array_shift($content_actions);
			// ...but we need to move its "xxxxx new" class to variant tabs
			$new = strpos($NS['class'], 'new') !== FALSE ? TRUE : FALSE;

			foreach ($content_actions as $key => $value) {
				//variants act like 'article' or 'special' etc links, remove action=edit
				if (strpos($key,'varlang') !== FALSE) {
					$value['href'] = preg_replace('/&action=(\w+)&/', '&', $value['href']);
					$variants[$key] = $value;
					if ($new === TRUE) { $variants[$key]['class'] .= ' new'; }
				} else {
					$actions[$key] = $value;
				}
			}
		}
		$content_actions = array_merge($variants, $actions);
	}
}
?>

LanguageSr_el.php

[edit]

This file is too long (40+ KB) but is also relatively easy to make using various tools (text editor with support for regular expressions, or even some UN*X tool). I'll describe the steps needed to make it from LanguageSr_ec.php:

  • Replace
require_once( "LanguageUtf8.php");

with

require_once( "LanguageSr_ec.php");
  • Replace Sr_ec with Sr_el in all arrays (variables) everywhere (all ocurences); example: $wgNamespaceNamesSr_ec becomes $wgNamespaceNamesSr_el
  • Change the main class declaration, from
class LanguageSr_ec extends LanguageUtf8 {

to

class LanguageSr_el extends LanguageSr_ec {
  • Optionally, you can remove the formatNum, time, date and timeanddate methods (again, not necesary).

LanguageSr_jc.php

[edit]

This file falls into the To Be Done (TM) category - currently I'm trying to catch someone who natively speaks (i)yekavian to make the necessary changes to system messages in LanguageSr_ec.php file so we can finaly finish at least this part.

<?php
/**
  * @package MediaWiki
  * @subpackage Language
  */
require_once( "LanguageSr_ec.php");

class LanguageSr_jc extends LanguageSr_ec { 
# Inherit everything for now
}
?>

LanguageSr_jl.php

[edit]

Also in To Be Done (TM) ;) - once when LanguageSr_jc.php is done, I'll transliterate it to latin script; meanwhile, this is all we have.

<?php
/**
  * @package MediaWiki
  * @subpackage Language
  */
require_once( "LanguageSr_ec.php");

class LanguageSr_jl extends LanguageSr_ec { 
# Inherit everything for now
}
?>

Names.php diff

[edit]

Not much to say here, diff is pretty straightforward.

--- Names.php	2005-07-25 23:34:54.000000000 +0200
+++ Names.php	2005-11-06 09:39:52.000000000 +0100
@@ -175,6 +175,10 @@
	'so' => 'Soomaaliga',	# Somali
	'sq' => 'Shqip',		# Albanian
	'sr' => 'Српски / Srpski',	# Serbian
+	'sr-ec' => 'екавица',	# Serbian cyrillic ekavian
+	'sr-jc' => 'ијекавица',	# Serbian cyrillic iyekvian
+	'sr-el' => 'ekavica',	# Serbian latin ekavian
+	'sr-jl' => 'ijekavica',	# Serbian latin iyekavian
	'ss' => 'SiSwati',		# Swati
	'st' => 'seSotho',		# Southern Sotho
	'su' => 'Basa Sunda',	# Sundanes