/**
  * Test...
  *
  * @covers Joomla\Language\Text::setLanguage
  *
  * @return  void
  *
  * @since   1.1.2
  */
 public function testSetLanguage()
 {
     $lang = Language::getInstance();
     Text::setLanguage($lang);
     $this->assertInstanceOf('Joomla\\Language\\Language', TestHelper::getValue($this->object, 'lang'));
     $this->assertEquals($lang, TestHelper::getValue($this->object, 'lang'));
 }
 /**
  * @dataProvider getParseCzechTextTests
  */
 public function testParseCzechText($template, $expected, $context = array())
 {
     // Load language
     $czechLanguage = Language::getInstance('cs-CZ');
     // Load cs-CZ.test.ini
     $czechLanguage->load('test', __DIR__);
     Text::setLanguage($czechLanguage);
     // Set timezone
     $this->object->setTimeZone('Europe/Prague');
     $this->assertEquals($expected, $this->getTemplate($template)->render($context));
     return;
 }
Example #3
0
 /**
  * This method processes a string and replaces all accented UTF-8 characters by unaccented
  * ASCII-7 "equivalents", whitespaces are replaced by hyphens and the string is lowercase.
  *
  * @param   string  $string  String to process
  *
  * @return  string  Processed string
  *
  * @since   1.0
  */
 public static function stringUrlSafe($string)
 {
     // Remove any '-' from the string since they will be used as concatenaters
     $str = str_replace('-', ' ', $string);
     $str = Language::getInstance()->transliterate($str);
     // Trim white spaces at beginning and end of alias and make lowercase
     $str = trim(StringHelper::strtolower($str));
     // Remove any duplicate whitespace, and ensure all characters are alphanumeric
     $str = preg_replace('/(\\s|[^A-Za-z0-9\\-])+/', '-', $str);
     // Trim dashes at beginning and end of alias
     $str = trim($str, '-');
     return $str;
 }
Example #4
0
 /**
  * Builds a list of the system languages which can be used in a select option
  *
  * @param   string  $selected  Client key for the area
  * @param   string  $basePath  Base path to use
  *
  * @return  array  List of system languages
  *
  * @since   1.0
  */
 protected function createLanguageList($selected, $basePath = JPATH_ROOT)
 {
     $list = array();
     // Cache activation
     $langs = Language::getKnownLanguages($basePath);
     foreach ($langs as $lang => $metadata) {
         $option = array();
         $option['text'] = $metadata['name'];
         $option['value'] = $lang;
         if ($lang == $selected) {
             $option['selected'] = 'selected="selected"';
         }
         $list[] = $option;
     }
     return $list;
 }
 /**
  * Test for Form::getInput method.
  *
  * @return void
  */
 public function testGetInput()
 {
     $form = new JFormInspector('form1');
     $this->assertThat($form->load(JFormDataHelper::$loadFieldDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
     $this->assertThat($form->getInput('title', null, 'The Title'), $this->equalTo('<input type="text" name="title" id="title_id" value="The Title" class="inputbox required"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field.');
     $this->assertThat($form->getInput('show_title', 'params', '0'), $this->equalTo('<fieldset id="params_show_title" class="radio">' . '<input type="radio" id="params_show_title0" name="params[show_title]" value="1"/>' . '<label for="params_show_title0">' . Text::_('JYes') . '</label>' . '<input type="radio" id="params_show_title1" name="params[show_title]" value="0" checked="checked"/>' . '<label for="params_show_title1">' . Text::_('JNo') . '</label>' . '</fieldset>'), 'Line:' . __LINE__ . ' The method should return a radio list.');
     $form = new JFormInspector('form1', array('control' => 'jform'));
     $this->assertThat($form->load(JFormDataHelper::$loadFieldDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
     $this->assertThat($form->getInput('colours', 'params', 'blue'), $this->equalTo('<select id="jform_params_colours" name="jform[params][colours][]" multiple="multiple">' . "\n" . '	<option value="red">Red</option>' . "\n" . '	<option value="blue" selected="selected">Blue</option>' . "\n" . '	<option value="green">Green</option>' . "\n" . '	<option value="yellow">Yellow</option>' . "\n" . '</select>' . "\n"), 'Line:' . __LINE__ . ' XML string should load successfully.');
     // Test translate default
     $this->assertThat($form->getInput('translate_default'), $this->equalTo('<input type="text" name="jform[translate_default]" id="jform_translate_default" value="DEFAULT_KEY"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field whose value is untranslated since the DEFAULT_KEY does not exist in the language.');
     $lang = Language::getInstance();
     $debug = $lang->setDebug(true);
     $this->assertThat($form->getInput('translate_default'), $this->equalTo('<input type="text" name="jform[translate_default]" id="jform_translate_default" value="??DEFAULT_KEY??"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field whose value is marked untranslated.');
     $lang->load('form_test', __DIR__);
     $this->assertThat($form->getInput('translate_default'), $this->equalTo('<input type="text" name="jform[translate_default]" id="jform_translate_default" value="My Default"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field whose value is translated.');
     $lang->setDebug($debug);
 }
 /**
  * Test...
  *
  * @covers  Joomla\Language\Language::parseXMLLanguageFile
  * @expectedException  RuntimeException
  *
  * @return void
  */
 public function testParseXMLLanguageFileException()
 {
     $path = __DIR__ . '/data/language/es-ES/es-ES.xml';
     Language::parseXMLLanguageFile($path);
 }
 /**
  * Test...
  *
  * @covers Joomla\Language\Language::parseLanguageFiles
  *
  * @return void
  */
 public function testParseLanguageFiles()
 {
     $dir = __DIR__ . '/data/language';
     $option = array('name' => 'English (United Kingdom)', 'tag' => 'en-GB', 'rtl' => '0', 'locale' => 'en_GB.utf8, en_GB.UTF-8, en_GB, eng_GB, en, english, english-uk, uk, gbr, britain, england,' . ' great britain, uk, united kingdom, united-kingdom', 'firstDay' => '0');
     $expected = array('en-GB' => $option);
     $result = Joomla\Language\Language::parseLanguageFiles($dir);
     $this->assertEquals($expected, $result, 'Line: ' . __LINE__);
 }
Example #8
0
 /**
  * Get a language object.
  *
  * @return Language
  *
  * @since   1.0
  */
 public function getLanguage()
 {
     if (is_null($this->language)) {
         $this->language = Language::getInstance($this->get('language'), $this->get('debug_lang'));
         // Configure Text to use language instance
         Text::setLanguage($this->language);
     }
     return $this->language;
 }
 /**
  * Get available languages
  *
  * @param   string  $key  Array key
  *
  * @return  array  An array of published languages
  *
  * @since   11.1
  */
 public static function getLanguages($key = 'default')
 {
     static $languages;
     if (empty($languages)) {
         // Installation uses available languages
         if (Factory::getApplication()->getClientId() == 2) {
             $languages[$key] = array();
             $knownLangs = Language::getKnownLanguages(JPATH_BASE);
             foreach ($knownLangs as $metadata) {
                 // Take off 3 letters iso code languages as they can't match browsers' languages and default them to en
                 $obj = new stdClass();
                 $obj->lang_code = $metadata['tag'];
                 $languages[$key][] = $obj;
             }
         } else {
             $cache = Factory::getCache('com_languages', '');
             if (!($languages = $cache->get('languages'))) {
                 $db = Factory::getDBO();
                 $query = $db->getQuery(true);
                 $query->select('*')->from('#__languages')->where('published=1')->order('ordering ASC');
                 $db->setQuery($query);
                 $languages['default'] = $db->loadObjectList();
                 $languages['sef'] = array();
                 $languages['lang_code'] = array();
                 if (isset($languages['default'][0])) {
                     foreach ($languages['default'] as $lang) {
                         $languages['sef'][$lang->sef] = $lang;
                         $languages['lang_code'][$lang->lang_code] = $lang;
                     }
                 }
                 $cache->store($languages, 'languages');
             }
         }
     }
     return $languages[$key];
 }
 /**
  * Create a language object
  *
  * @return  Language object
  *
  * @see     JLanguage
  * @since   11.1
  */
 protected static function createLanguage()
 {
     $conf = self::getConfig();
     $locale = $conf->get('language');
     $debug = $conf->get('debug_lang');
     $lang = Language::getInstance($locale, $debug);
     return $lang;
 }
Example #11
0
 /**
  * Method to load, setup and return a FormField object based on field data.
  *
  * @param   string  $element  The XML element object representation of the form field.
  * @param   string  $group    The optional dot-separated form group path on which to find the field.
  * @param   mixed   $value    The optional value to use as the default for the field.
  *
  * @return  mixed  The FormField object for the field or boolean false on error.
  *
  * @since   1.0
  */
 protected function loadField($element, $group = null, $value = null)
 {
     // Make sure there is a valid SimpleXMLElement.
     if (!$element instanceof \SimpleXMLElement) {
         return false;
     }
     // Get the field type.
     $type = $element['type'] ? (string) $element['type'] : 'text';
     // Load the Field object for the field.
     $field = FormHelper::loadFieldType($type);
     // If the object could not be loaded, get a text field object.
     if ($field === false) {
         $field = FormHelper::loadFieldType('text');
     }
     /*
      * Get the value for the form field if not set.
      * Default to the translated version of the 'default' attribute
      * if 'translate_default' attribute if set to 'true' or '1'
      * else the value of the 'default' attribute for the field.
      */
     if ($value === null) {
         $default = (string) $element['default'];
         if (($translate = $element['translate_default']) && ((string) $translate == 'true' || (string) $translate == '1')) {
             $lang = Language::getInstance();
             if ($lang->hasKey($default)) {
                 $debug = $lang->setDebug(false);
                 $default = Text::_($default);
                 $lang->setDebug($debug);
             } else {
                 $default = Text::_($default);
             }
         }
         $value = $this->getValue((string) $element['name'], $group, $default);
     }
     // Setup the Field object.
     $field->setForm($this);
     if ($field->setup($element, $value, $group)) {
         return $field;
     } else {
         return false;
     }
 }