Example #1
0
function recursive_translate(stdClass $obj, $source_lang, $dest_lang)
{
    $response = new stdClass();
    foreach ($obj as $key => $value) {
        switch (gettype($value)) {
            case "string":
                $response->{$key} = google_translate((string) $value, $source_lang, $dest_lang);
                break;
            case "object":
                $response->{$key} = recursive_translate($value, $source_lang, $dest_lang);
                break;
        }
    }
    return $response;
}
Example #2
0
 /**
  * Try to return the human-readable version of the language id, passed in as $entry.
  *
  * @param  integer			The id
  * @param  ?object			The database connection to use (NULL: standard site connection)
  * @param  ?LANGUAGE_NAME	The language (NULL: uses the current language)
  * @return string				The human-readable version
  */
 function get_translated_text($entry, $connection = NULL, $lang = NULL)
 {
     if ($entry == 0) {
         return do_lang('FAILED_ENTRY');
     }
     if ($entry === NULL) {
         fatal_exit(do_lang_tempcode('NULL_LANG_STRING'));
     }
     if ($connection === NULL) {
         $connection = $GLOBALS['SITE_DB'];
     }
     global $RECORD_LANG_STRINGS_CONTENT;
     if ($RECORD_LANG_STRINGS_CONTENT) {
         global $RECORDED_LANG_STRINGS_CONTENT;
         $RECORDED_LANG_STRINGS_CONTENT[$entry] = $connection->connection_write != $GLOBALS['SITE_DB']->connection_write;
     }
     if ($lang === NULL) {
         $lang = user_lang();
     }
     if (array_key_exists($entry, $connection->text_lookup_original_cache) && $lang == user_lang()) {
         return $connection->text_lookup_original_cache[$entry];
     }
     if ($lang == 'xxx') {
         return '!!!';
     }
     // Helpful for testing language compliancy. We don't expect to see non x's/!'s if we're running this language
     $result = $connection->query_select('translate', array('text_original', 'text_parsed'), array('id' => $entry, 'language' => $lang), '', 1);
     if (!array_key_exists(0, $result)) {
         $result = $connection->query_select('translate', array('*'), array('id' => $entry, 'language' => get_site_default_lang()), '', 1);
         if (!array_key_exists(0, $result)) {
             $result = $connection->query_select('translate', array('*'), array('id' => $entry), '', 1);
         }
         if (array_key_exists(0, $result)) {
             $result[0]['text_original'] = google_translate($result[0]['text_original'], $lang);
             $result[0]['text_parsed'] = '';
             $connection->query_insert('translate', array('broken' => 1, 'language' => $lang) + $result[0]);
         }
     }
     if (!array_key_exists(0, $result)) {
         $member_id = function_exists('get_member') ? get_member() : $GLOBALS['FORUM_DRIVER']->get_guest_id();
         $connection->query_insert('translate', array('id' => $entry, 'source_user' => $member_id, 'broken' => 0, 'importance_level' => 3, 'text_original' => '', 'text_parsed' => '', 'language' => $lang));
         $msg = do_lang('LANGUAGE_CORRUPTION', strval($entry));
         if (preg_match('#^localhost[\\.\\:$]#', ocp_srv('HTTP_HOST')) != 0) {
             fatal_exit($msg);
         }
         require_code('site');
         attach_message(make_string_tempcode($msg), 'warn');
         return '';
     }
     if ($lang == user_lang()) {
         $connection->text_lookup_original_cache[$entry] = $result[0]['text_original'];
         $connection->text_lookup_cache[$entry] = $result[0]['text_parsed'];
     }
     return $result[0]['text_original'];
 }
Example #3
0
    <div class="content_right">
        <?php 
echo form_open('user/cpageproduct/languages', array('name' => 'langForm', 'id' => 'langForm'));
?>
	<input type="hidden" name="dlang" id="dlang">
	<input type="hidden" name="current" id="current" value="<?php 
echo substr(uri_string(), 1, strlen(uri_string()));
?>
">

	<img src="<?php 
base_url();
?>
images/fr.png" onClick="lanfTrans('fr');" width="16" height="11" title="French"> &nbsp;
	<img src="<?php 
base_url();
?>
images/en.png" onClick="lanfTrans('en');" width="16" height="11" title="English"> &nbsp;
	<img src="<?php 
base_url();
?>
images/es_flag.gif" onClick="lanfTrans('es');" width="16" height="11" title="Spanish"> &nbsp;
<?php 
echo form_close();
?>

        <?php 
google_translate("Ini bahasa indonesia menjadi..?", $lang, "id", "text");
?>
    </div>
</div>
Example #4
0
 /**
  * Load Comcode page from disk.
  *
  * @param  PATH			The relative (to ocPortal's base directory) path to the page (e.g. pages/comcode/EN/start.txt)
  * @param  ID_TEXT		The zone the page is being loaded from
  * @param  ID_TEXT		The codename of the page
  * @param  PATH			The file base to load from
  * @param  array			New row for database, used if nesessary (holds submitter etc)
  * @param  boolean		Whether the page is being included from another
  * @return array			A tuple: The page, New Comcode page row, Title
  */
 function _load_comcode_page_cache_off($string, $zone, $codename, $file_base, $new_comcode_page_row, $being_included = false)
 {
     global $COMCODE_PARSE_TITLE;
     if (is_null($new_comcode_page_row['p_submitter'])) {
         $as_admin = true;
         $members = $GLOBALS['FORUM_DRIVER']->member_group_query($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), 1);
         if (count($members) != 0) {
             $new_comcode_page_row['p_submitter'] = $GLOBALS['FORUM_DRIVER']->pname_id($members[key($members)]);
         } else {
             $new_comcode_page_row['p_submitter'] = db_get_first_id() + 1;
             // On OCF and most forums, this is the first admin member
         }
     }
     $_comcode_page_row = $GLOBALS['SITE_DB']->query_select('comcode_pages', array('*'), array('the_zone' => $zone, 'the_page' => $codename), '', 1);
     global $LAX_COMCODE;
     $temp = $LAX_COMCODE;
     $LAX_COMCODE = true;
     $result = file_get_contents($file_base . '/' . $string, FILE_TEXT);
     if (strpos($string, '/' . get_site_default_lang() . '/') !== false && user_lang() != get_site_default_lang()) {
         $result = google_translate($result, user_lang());
     }
     $lang = user_lang();
     $html = comcode_to_tempcode($result, array_key_exists(0, $_comcode_page_row) ? $_comcode_page_row[0]['p_submitter'] : get_member(), !array_key_exists(0, $_comcode_page_row) || is_guest($_comcode_page_row[0]['p_submitter']), 60, $being_included || strpos($codename, 'panel_') !== false ? 'panel' : NULL);
     $LAX_COMCODE = $temp;
     $title_to_use = is_null($COMCODE_PARSE_TITLE) ? NULL : clean_html_title($COMCODE_PARSE_TITLE);
     // Try and insert corresponding page; will silently fail if already exists. This is only going to add a row for a page that was not created in-system
     if (array_key_exists(0, $_comcode_page_row)) {
         $comcode_page_row = $_comcode_page_row[0];
     } else {
         $comcode_page_row = $new_comcode_page_row;
         $GLOBALS['SITE_DB']->query_insert('comcode_pages', $comcode_page_row, false, true);
     }
     return array($html, $comcode_page_row, $title_to_use);
 }
Example #5
0
 /**
  * get_translated_tempcode was asked for a lang entry that had not been parsed into Tempcode yet.
  *
  * @param  integer			The id
  * @param  ?object			The database connection to use (NULL: standard site connection)
  * @param  ?LANGUAGE_NAME	The language (NULL: uses the current language)
  * @param  boolean			Whether to force it to the specified language
  * @param  boolean			Whether to force as_admin, even if the lang string isn't stored against an admin (designed for comcode page cacheing)
  * @return ?tempcode			The parsed comcode (NULL: the text couldn't be looked up)
  */
 function parse_translated_text($entry, $connection, $lang, $force, $as_admin)
 {
     global $SEARCH__CONTENT_BITS;
     global $LAX_COMCODE;
     $nql_backup = $GLOBALS['NO_QUERY_LIMIT'];
     $GLOBALS['NO_QUERY_LIMIT'] = true;
     $result = $connection->query_select('translate', array('text_original', 'source_user'), array('id' => $entry, 'language' => $lang), '', 1);
     $result = array_key_exists(0, $result) ? $result[0] : NULL;
     if (is_null($result)) {
         if ($force) {
             $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
             return NULL;
         }
         $result = $connection->query_value_null_ok('translate', 'text_parsed', array('id' => $entry, 'language' => get_site_default_lang()));
         if (is_null($result)) {
             $result = $connection->query_value_null_ok('translate', 'text_parsed', array('id' => $entry));
         }
         if (is_null($result) || $result == '') {
             load_user_stuff();
             require_code('comcode');
             // might not have been loaded for a quick-boot
             require_code('permissions');
             $result = $connection->query_select('translate', array('text_original', 'source_user'), array('id' => $entry, 'language' => get_site_default_lang()), '', 1);
             if (!array_key_exists(0, $result)) {
                 $result = $connection->query_select('translate', array('text_original', 'source_user'), array('id' => $entry), '', 1);
             }
             $result = array_key_exists(0, $result) ? $result[0] : NULL;
             if (!is_null($result)) {
                 $result['text_original'] = google_translate($result['text_original'], $lang);
                 $result['text_parsed'] = '';
             }
             $temp = $LAX_COMCODE;
             $LAX_COMCODE = true;
             lang_remap_comcode($entry, is_null($result) ? '' : $result['text_original'], $connection, NULL, $result['source_user'], $as_admin);
             if (!is_null($SEARCH__CONTENT_BITS)) {
                 $ret = comcode_to_tempcode($result['text_original'], $result['source_user'], $as_admin, 60, NULL, $connection, false, false, false, false, false, $SEARCH__CONTENT_BITS);
                 $LAX_COMCODE = $temp;
                 $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
                 return $ret;
             }
             $LAX_COMCODE = $temp;
             $ret = get_translated_tempcode($entry, $connection, $lang);
             $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
             return $ret;
         }
         $connection->text_lookup_cache[$entry] = new ocp_tempcode();
         $connection->text_lookup_cache[$entry]->from_assembly($result);
         $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
         return $connection->text_lookup_cache[$entry];
     } else {
         load_user_stuff();
         require_code('comcode');
         // might not have been loaded for a quick-boot
         require_code('permissions');
         global $LAX_COMCODE;
         $temp = $LAX_COMCODE;
         $LAX_COMCODE = true;
         lang_remap_comcode($entry, $result['text_original'], $connection, NULL, $result['source_user'], $as_admin);
         if (!is_null($SEARCH__CONTENT_BITS)) {
             $ret = comcode_to_tempcode($result['text_original'], $result['source_user'], $as_admin, 60, NULL, $connection, false, false, false, false, false, $SEARCH__CONTENT_BITS);
             $LAX_COMCODE = $temp;
             $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
             return $ret;
         }
         $LAX_COMCODE = $temp;
         $ret = get_translated_tempcode($entry, $connection, $lang);
         $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup;
         return $ret;
     }
 }
Example #6
0
 /**
  * Load up a language file, compiling it (it's not cached yet).
  *
  * @param  ID_TEXT			The language file name
  * @param  ?LANGUAGE_NAME	The language (NULL: uses the current language)
  * @param  ?string			The language type (lang_custom, or custom) (NULL: normal priorities are used)
  * @set    lang_custom custom
  * @param  PATH				Where we are cacheing too
  * @param  boolean			Whether to just return if there was a loading error
  * @return boolean			Whether we FAILED to load
  */
 function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_errors = false)
 {
     global $LANGUAGE, $REQUIRE_LANG_LOOP, $LANG_LOADED_LANG;
     $desire_cache = function_exists('get_option') && (get_option('is_on_lang_cache', true) == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0;
     if ($desire_cache) {
         if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 0) {
             global $DECACHED_COMCODE_LANG_STRINGS;
             // Cleanup language strings
             if (!$DECACHED_COMCODE_LANG_STRINGS) {
                 $DECACHED_COMCODE_LANG_STRINGS = true;
                 $comcode_lang_strings = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => '!'), '', NULL, NULL, true);
                 if (!is_null($comcode_lang_strings)) {
                     $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => '!'));
                     foreach ($comcode_lang_strings as $comcode_lang_string) {
                         delete_lang($comcode_lang_string['string_index']);
                     }
                 }
             }
         }
         $load_target = array();
     } else {
         $load_target =& $LANGUAGE[$lang];
     }
     global $FILE_ARRAY;
     if (@is_array($FILE_ARRAY) && file_array_exists('lang/' . $lang . '/' . $codename . '.ini')) {
         $lang_file = 'lang/' . $lang . '/' . $codename . '.ini';
         $file = file_array_get($lang_file);
         _get_lang_file_map($file, $load_target, NULL, true);
         $bad = true;
     } else {
         $bad = true;
         $dirty = false;
         // Load originals
         $lang_file = get_file_base() . '/lang/' . $lang . '/' . filter_naughty($codename) . '.ini';
         if (file_exists($lang_file)) {
             _get_lang_file_map($lang_file, $load_target, NULL, false);
             $bad = false;
         }
         // Load overrides now if they are there
         if ($type != 'lang') {
             $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini';
             if (!file_exists($lang_file) && get_file_base() != get_custom_file_base()) {
                 $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini';
             }
             if (!file_exists($lang_file)) {
                 $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.po';
                 if (!file_exists($lang_file)) {
                     $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '-' . strtolower($lang) . '.po';
                 }
             }
         }
         if ($type != 'lang' && file_exists($lang_file)) {
             _get_lang_file_map($lang_file, $load_target, NULL, false);
             $bad = false;
             $dirty = true;
             // Tainted from the official pack, so can't store server wide
         }
         // NB: Merge op doesn't happen in require_lang. It happens when do_lang fails and then decides it has to force a recursion to do_lang(xx,fallback_lang()) which triggers require_lang(xx,fallback_lang()) when it sees it's not loaded
         if ($bad && $lang != fallback_lang()) {
             require_lang($codename, fallback_lang(), $type, $ignore_errors);
             $REQUIRE_LANG_LOOP--;
             $fallback_cache_path = get_custom_file_base() . '/lang_cached/' . fallback_lang() . '/' . $codename . '.lcd';
             if (file_exists($fallback_cache_path)) {
                 require_code('files');
                 $fallback_map = unserialize(file_get_contents($fallback_cache_path));
                 $sep = '<span class="notranslate">----</span>';
                 $to_translate = '';
                 $i = 0;
                 $from = 0;
                 $lang_codes = array_keys($fallback_map);
                 foreach ($fallback_map as $value) {
                     if (strlen($to_translate . $sep . $to_translate) >= 3000) {
                         $translated = preg_split('#<span class="notranslate">[^<>]*----[^<>]*</span>#', google_translate($to_translate, $lang));
                         foreach ($translated as $j => $t_value) {
                             if (strtolower($lang_codes[$from + $j]) == $lang_codes[$from + $j]) {
                                 $t_value = $fallback_map[$lang_codes[$from + $j]];
                             }
                             if ($lang_codes[$from + $j] == 'locale') {
                                 $t_value = strtolower($lang) . '_' . strtoupper($lang);
                             }
                             $fallback_map[$lang_codes[$from + $j]] = $t_value;
                             $load_target[$lang_codes[$from + $j]] = $t_value;
                         }
                         $from = $i;
                         $to_translate = '';
                     }
                     if ($to_translate != '') {
                         $to_translate .= $sep;
                     }
                     $to_translate .= $value;
                     $i++;
                 }
                 $translated = preg_split('#<span class="notranslate">[^<>]*----[^<>]*</span>#', google_translate($to_translate, $lang));
                 foreach ($translated as $j => $t_value) {
                     if (strtolower($lang_codes[$from + $j]) == $lang_codes[$from + $j]) {
                         $t_value = $fallback_map[$lang_codes[$from + $j]];
                     }
                     if ($lang_codes[$from + $j] == 'locale') {
                         $t_value = strtolower($lang) . '_' . strtoupper($lang);
                     }
                     $fallback_map[$lang_codes[$from + $j]] = $t_value;
                     $load_target[$lang_codes[$from + $j]] = $t_value;
                 }
                 if (function_exists('ocp_mb_substr') && $codename == 'dates') {
                     foreach (array_keys($fallback_map) as $key) {
                         if (substr($key, 0, 3) == 'FC_') {
                             $test = ocp_mb_substr(trim($fallback_map[substr($key, 3)]), 0, 1, true);
                             if ($test !== false) {
                                 $fallback_map[$key] = $test;
                             }
                         }
                     }
                 }
                 $myfile = fopen($cache_path, 'wb');
                 fwrite($myfile, serialize($fallback_map));
                 fclose($myfile);
                 fix_permissions($cache_path);
             }
             if (!array_key_exists($lang, $LANG_LOADED_LANG)) {
                 $LANG_LOADED_LANG[$lang] = array();
             }
             $LANG_LOADED_LANG[$lang][$codename] = 1;
             if (!$bad) {
                 $LANGUAGE[$lang] += $fallback_map;
             }
             return $bad;
         }
         if ($bad) {
             if ($ignore_errors) {
                 return true;
             }
             if ($codename != 'critical_error' || $lang != get_site_default_lang()) {
                 fatal_exit(do_lang_tempcode('MISSING_LANG_FILE', escape_html($codename), escape_html($lang)));
             } else {
                 critical_error('CRIT_LANG');
             }
         }
     }
     if (is_null($GLOBALS['MEM_CACHE'])) {
         // Cache
         if ($desire_cache) {
             $file = @fopen($cache_path, 'wt');
             // Will fail if cache dir missing .. e.g. in quick installer
             if ($file) {
                 if (fwrite($file, serialize($load_target)) > 0) {
                     // Success
                     fclose($file);
                     require_code('files');
                     fix_permissions($cache_path);
                 } else {
                     // Failure
                     fclose($file);
                     @unlink($cache_path);
                 }
             }
         }
     } else {
         persistant_cache_set(array('LANG', $lang, $codename), $load_target, !$dirty);
     }
     if ($desire_cache) {
         $LANGUAGE[$lang] += $load_target;
     }
     return $bad;
 }