/**
  * @since 2.4
  *
  * @param string $userValue
  *
  * @return array
  */
 public function parse($userValue)
 {
     $text = $userValue;
     $languageCode = mb_substr(strrchr($userValue, "@"), 1);
     // Remove the language code and marker from the text
     if ($languageCode !== '') {
         $text = substr_replace($userValue, '', (mb_strlen($languageCode) + 1) * -1);
     }
     return array($text, Localizer::asBCP47FormattedLanguageCode($languageCode));
 }
 /**
  * @see DataValue::parseUserValue
  *
  * @param string $value
  */
 protected function parseUserValue($userValue)
 {
     $languageCode = Localizer::asBCP47FormattedLanguageCode($userValue);
     if ($languageCode === '') {
         $this->addErrorMsg(array('smw-datavalue-languagecode-missing', $this->m_property !== null ? $this->m_property->getLabel() : 'UNKNOWN'));
         return;
     }
     // Checks whether any localisation is available for that language tag in
     // MediaWiki
     if (!Localizer::isSupportedLanguage($languageCode)) {
         $this->addErrorMsg(array('smw-datavalue-languagecode-invalid', $languageCode));
         return;
     }
     $this->m_dataitem = new DIBlob($languageCode);
 }
예제 #3
0
 public function testAsBCP47FormattedLanguageCode()
 {
     $this->assertEquals('zh-Hans', Localizer::asBCP47FormattedLanguageCode('zh-hans'));
 }
 /**
  * @since 2.4
  *
  * @param string $languageCode
  */
 public function setLanguageCode($languageCode)
 {
     $this->languageCode = Localizer::asBCP47FormattedLanguageCode($languageCode);
 }
 /**
  * @since 2.4
  *
  * @param string $languageCode
  *
  * @return DataValue|null
  */
 public function getTextValueByLanguage($languageCode)
 {
     if (($list = $this->toArray()) === array()) {
         return null;
     }
     if ($list['_LCODE'] !== Localizer::asBCP47FormattedLanguageCode($languageCode)) {
         return null;
     }
     if ($list['_TEXT'] === '') {
         return null;
     }
     $dataValue = DataValueFactory::getInstance()->newDataValueByItem(new DIBlob($list['_TEXT']), new DIProperty('_TEXT'));
     return $dataValue;
 }