Skip to content

Commit

Permalink
Add ExtraneousLanguage JSON format, refs 1691, 1561
Browse files Browse the repository at this point in the history
- Moves SMW specific language elements from PHP to JSON
- Support for partial fallback
- If a json file (e.g. `zh-hant.json`) contains `isLanguageRedirect` then
only a `fallbackLanguage` is required
- The `CanonicalFallbackLanguage` is `en`
- Adds `LanguageFallbackFinder`, `LanguageFileContentsReader`
  • Loading branch information
mwjames committed Sep 14, 2016
1 parent 2604e65 commit d0d465a
Show file tree
Hide file tree
Showing 53 changed files with 5,772 additions and 543 deletions.
2 changes: 1 addition & 1 deletion DefaultSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# this file.
##
$GLOBALS['smwgIP'] = dirname( __FILE__ ) . '/';
$GLOBALS['smwgExtraneousLanguageFileDir'] = __DIR__ . '/languages';
$GLOBALS['smwgExtraneousLanguageFileDir'] = __DIR__ . '/languages/i18n';
##

###
Expand Down
4 changes: 3 additions & 1 deletion includes/NamespaceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SMW;

use SMW\ExtraneousLanguage\ExtraneousLanguage;

/**
* @license GNU GPL v2+
* @since 1.9
Expand Down Expand Up @@ -141,7 +143,7 @@ protected function addNamespaceSettings() {
* @var SMWLanguage $smwgContLang
*/
$this->globalVars['wgExtraNamespaces'] = $this->globalVars['smwgContLang']->getNamespaces() + $this->globalVars['wgExtraNamespaces'];
$this->globalVars['wgNamespaceAliases'] = array_flip( $this->globalVars['smwgContLang']->getNamespaces() ) + $this->globalVars['wgNamespaceAliases'];
$this->globalVars['wgNamespaceAliases'] = array_flip( $this->globalVars['smwgContLang']->getNamespaceAliases() ) + $this->globalVars['wgNamespaceAliases'];

// Support subpages only for talk pages by default
$this->globalVars['wgNamespacesWithSubpages'] = $this->globalVars['wgNamespacesWithSubpages'] + array(
Expand Down
42 changes: 37 additions & 5 deletions languages/SMW_Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @ingroup SMWLanguage
* @ingroup Language
*/
abstract class SMWLanguage {
class SMWLanguage {

// the special message arrays ...
protected $m_DatatypeLabels;
Expand Down Expand Up @@ -136,16 +136,17 @@ abstract class SMWLanguage {
public function __construct() {
// `$this->m_SpecialProperties' is set in descendants.
// Let us initialize reverse mapping.
foreach ( $this->m_SpecialProperties as $propId => $propName ) {
$this->m_SpecialPropertyIds[$propName] = $propId;
}
// foreach ( $this->m_SpecialProperties as $propId => $propName ) {
// $this->m_SpecialPropertyIds[$propName] = $propId;
// }
}


/**
* Function that returns an array of namespace identifiers.
*/
function getNamespaces() {
return $this->m_Namespaces;
global $smwgHistoricTypeNamespace;
$namespaces = $this->m_Namespaces;
if ( !$smwgHistoricTypeNamespace ) {
Expand All @@ -159,6 +160,7 @@ function getNamespaces() {
* Function that returns an array of namespace aliases, if any.
*/
function getNamespaceAliases() {
return $this->m_NamespaceAliases;
global $smwgHistoricTypeNamespace;

$namespaceAliases = $this->m_NamespaceAliases;
Expand Down Expand Up @@ -196,6 +198,7 @@ function getCanonicalDatatypeLabels() {
* should also have a primary label defined in m_DatatypeLabels.
*/
function getDatatypeAliases() {
return $this->m_DatatypeAliases;
return $this->m_useEnDefaultAliases ?
$this->m_DatatypeAliases + self::$enDatatypeAliases :
$this->m_DatatypeAliases;
Expand All @@ -221,6 +224,10 @@ function getCanonicalPropertyLabels() {
*/
function getPropertyAliases() {
return $this->m_SpecialPropertyAliases;

// return $this->m_useEnDefaultAliases ?
// $this->m_SpecialPropertyAliases + self::$enPropertyAliases :
// $this->m_SpecialPropertyAliases;
}

/**
Expand Down Expand Up @@ -276,6 +283,31 @@ function getMonthLabel( $number ) {
return ( ( $number >= 1 ) && ( $number <= 12 ) ) ? $this->m_months[(int)( $number - 1 )] : '';
}

}
function getMonths() {
return $this->m_months;
}

function getMonthsShort() {
return $this->m_monthsshort;
}

public function getTargetFileFor( $languageCode ) {
return __DIR__ . '/i18n/' . $languageCode . '.json';
}

public function getLanguageFor( $languageCode ) {

$contLangFile = 'SMW_Language' . str_replace( '-', '_', ucfirst( $languageCode ) );
$contLangClass = 'SMWLanguage' . str_replace( '-', '_', ucfirst( $languageCode ) );

$file = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR, __DIR__ . '/' . $contLangFile . '.php' );

if ( file_exists( $file ) ) {
require_once ( $file );
return new $contLangClass;
}

}


}
182 changes: 182 additions & 0 deletions languages/i18n/ar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"@metadata": {
"authors": []
},
"fallbackLanguage": "en",
"dataTypeLabels": {
"_wpg": "الصفحة",
"_txt": "نص",
"_cod": "كود",
"_boo": "منطقي",
"_num": "عدد",
"_geo": "الإحداثيات الجغرافية",
"_tem": "الحرارة",
"_dat": "التاريخ",
"_ema": "البريد الإلكتروني",
"_uri": "مسار",
"_anu": "التعليق علي معرف الموارد الموحد",
"_tel": "رقم الهاتف",
"_rec": "تسجيل",
"_qty": "Quantity",
"_mlt_rec": "Monolingual text",
"_eid": "External identifier",
"_ref_rec": "Reference"
},
"dataTypeAliases": {
"URI": "_uri",
"Float": "_num",
"Integer": "_num",
"سلسلة": "_txt",
"Enumeration": "_txt"
},
"propertyLabels": {
"_TYPE": "لديه نوع",
"_URI": "معرف الموارد الموحد معادلة",
"_SUBP": "الخاصية الفرعية ل",
"_SUBC": "تصنيف فرعي من",
"_UNIT": "عرض الوحدات",
"_IMPO": "المستوردة من",
"_CONV": "يقابل",
"_SERV": "يوفر الخدمة",
"_PVAL": "يسمح بالقيمة",
"_MDAT": "تاريخ التعديل",
"_CDAT": "Creation date",
"_NEWP": "Is a new page",
"_LEDT": "Last editor is",
"_ERRP": "يمتلك قيمة غير صحيحة ل",
"_LIST": "يمتلك حقول",
"_SOBJ": "Has subobject",
"_ASK": "Has query",
"_ASKST": "Query string",
"_ASKFO": "Query format",
"_ASKSI": "Query size",
"_ASKDE": "Query depth",
"_ASKDU": "Query duration",
"_MEDIA": "Media type",
"_MIME": "MIME type",
"_ERRC": "Has processing error",
"_ERRT": "Has processing error text",
"_PREC": "Display precision of",
"_LCODE": "Language code",
"_TEXT": "Text",
"_PDESC": "Has property description",
"_PVAP": "Allows pattern",
"_DTITLE": "Display title of",
"_PVUC": "Has uniqueness constraint",
"_PEID": "External identifier",
"_PEFU": "External formatter uri"
},
"propertyAliases": {
"عرض الوحدة": "_UNIT"
},
"dateFormatsByPrecision": {
"SMW_PREC_Y": "Y",
"SMW_PREC_YM": "F Y",
"SMW_PREC_YMD": "F j, Y",
"SMW_PREC_YMDT": "H:i:s, j F Y"
},
"namespaces": {
"SMW_NS_PROPERTY": "خاصية",
"SMW_NS_PROPERTY_TALK": "نقاش_الخاصية",
"SMW_NS_TYPE": "نوع",
"SMW_NS_TYPE_TALK": "نقاش_النوع",
"SMW_NS_CONCEPT": "مبدأ",
"SMW_NS_CONCEPT_TALK": "نقاش_المبدأ"
},
"namespaceAliases": [],
"dateFormats": [
[
"SMW_Y"
],
[
"SMW_MY",
"SMW_YM"
],
[
"SMW_MDY",
"SMW_DMY",
"SMW_YMD",
"SMW_YDM"
]
],
"months": [
[
"يناير",
"يناير"
],
[
"فبراير",
"فبراير"
],
[
"مارس",
"مارس"
],
[
"أبريل",
"أبريل"
],
[
"مايو",
"مايو"
],
[
"يونيو",
"يونيو"
],
[
"يوليو",
"يوليو"
],
[
"أغسطس",
"أغسطس"
],
[
"سبتمبر",
"سبتمبر"
],
[
"أكتوبر",
"أكتوبر"
],
[
"نوفمبر",
"نوفمبر"
],
[
"ديسمبر",
"ديسمبر"
]
],
"days": [
[
"Monday",
"Mon"
],
[
"Tuesday",
"Tue"
],
[
"Wednesday",
"Wed"
],
[
"Thursday",
"Thu"
],
[
"Friday",
"Fri"
],
[
"Saturday",
"Sat"
],
[
"Sunday",
"Sun"
]
]
}

0 comments on commit d0d465a

Please sign in to comment.