Exemplo n.º 1
0
 function test_export_mo_file()
 {
     $entries = array();
     $entries[] = new Translation_Entry(array('singular' => 'pink', 'translations' => array('розов')));
     $no_translation_entry = new Translation_Entry(array('singular' => 'grey'));
     $entries[] = new Translation_Entry(array('singular' => 'green', 'plural' => 'greens', 'translations' => array('зелен', 'зелени')));
     $entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'color', 'translations' => array('червен')));
     $entries[] = new Translation_Entry(array('singular' => 'red', 'context' => 'bull', 'translations' => array('бик')));
     $entries[] = new Translation_Entry(array('singular' => 'maroon', 'plural' => 'maroons', 'context' => 'context', 'translations' => array('пурпурен', 'пурпурни')));
     $mo = new MO();
     $mo->set_header('Project-Id-Version', 'Baba Project 1.0');
     foreach ($entries as $entry) {
         $mo->add_entry($entry);
     }
     $mo->add_entry($no_translation_entry);
     $temp_fn = $this->temp_filename();
     $mo->export_to_file($temp_fn);
     $again = new MO();
     $again->import_from_file($temp_fn);
     $this->assertEquals(count($entries), count($again->entries));
     foreach ($entries as $entry) {
         $this->assertEquals($entry, $again->entries[$entry->key()]);
     }
 }
Exemplo n.º 2
0
 /**
  * change language : if language file not exist return false
  * if language file not in THEME_LANGUAGE_PATH copy it from DEFAULT_LANG to THEME_LANGUAGE_PATH
  * @since 1.0
  */
 function change_language()
 {
     $lang = $_REQUEST['lang_name'];
     if (!in_array($lang, $this->get_language_list())) {
         wp_send_json(array('success' => false));
     }
     if (!in_array($lang, get_available_languages(THEME_LANGUAGE_PATH))) {
         $mo = new MO();
         $mo->set_header('Project-Id-Version', THEME_NAME . 'v' . ET_VERSION);
         $mo->set_header('Report-Msgid-Bugs-To', ET_URL);
         $mo->set_header('MO-Creation-Date', gmdate('Y-m-d H:i:s+00:00'));
         $mo->set_header('MIME-Version', '1.0');
         $mo->set_header('Content-Type', 'text/plain; charset=UTF-8');
         $mo->set_header('Content-Transfer-Encoding', '8bit');
         $mo->set_header('MO-Revision-Date', '2010-MO-DA HO:MI+ZONE');
         $mo->set_header('Last-Translator', 'JOB <EMAIL@ADDRESS>');
         $mo->set_header('Language-Team', 'ENGINETHEMES.COM <*****@*****.**>');
         $mo->import_from_file(DEFAULT_LANGUAGE_PATH . '/' . $lang . '.mo');
         $mo->export_to_file(THEME_LANGUAGE_PATH . '/' . $lang . '.mo');
     }
     $this->set_site_language($lang);
     wp_send_json(array('success' => true, 'data' => array('ID' => $lang, 'lang_name' => $lang)));
 }