/** * The actualiser to translate code (called externally, and may operate on many lang files). * * @return tempcode The UI */ function set_lang_code_2() { $lang = post_param('lang'); $lang_files = get_lang_files(fallback_lang()); foreach (array_keys($lang_files) as $lang_file) { $for_base_lang = get_lang_file_map(fallback_lang(), $lang_file, true); $for_base_lang_2 = get_lang_file_map($lang, $lang_file, false); $descriptions = get_lang_file_descriptions(fallback_lang(), $lang_file); $out = ''; foreach ($for_base_lang_2 + $for_base_lang as $key => $now_val) { $val = post_param('l_' . $key, array_key_exists($key, $for_base_lang_2) ? $for_base_lang_2[$key] : $now_val); if (str_replace(chr(10), '\\n', $val) != $now_val || !array_key_exists($key, $for_base_lang) || $for_base_lang[$key] != $val || !file_exists(get_file_base() . '/lang/' . fallback_lang() . '/' . $lang_file . '.ini')) { // if it's changed from default ocPortal, or not in default ocPortal, or was already changed in language file, or whole file is not in default ocPortal $out .= $key . '=' . str_replace(chr(10), '\\n', $val) . "\n"; } } if ($out != '') { $path = get_custom_file_base() . '/lang_custom/' . filter_naughty($lang) . '/' . filter_naughty($lang_file) . '.ini'; $path_backup = $path . '.' . strval(time()); if (file_exists($path)) { @copy($path, $path_backup) or intelligent_write_error($path_backup); sync_file($path_backup); } $myfile = @fopen($path, 'wt'); if ($myfile === false) { intelligent_write_error($path); } fwrite($myfile, "[descriptions]\n"); foreach ($descriptions as $key => $description) { if (fwrite($myfile, $key . '=' . $description . "\n") == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } } fwrite($myfile, "\n[strings]\n"); fwrite($myfile, $out); fclose($myfile); fix_permissions($path); sync_file($path); $path_backup2 = $path . '.latest_in_ocp_edit'; @copy($path, $path_backup2) or intelligent_write_error($path_backup2); sync_file($path_backup2); } } $title = get_page_title('TRANSLATE_CODE'); log_it('TRANSLATE_CODE'); require_code('view_modes'); erase_cached_language(); erase_cached_templates(); // Show it worked / Refresh $url = post_param('redirect', ''); if ($url == '') { return inform_screen($title, do_lang_tempcode('SUCCESS')); } return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); }
/** * Get a nice formatted XHTML listed language file selector for the given language. * * @param ?LANGUAGE_NAME The language (NULL: uses the current language) * @return tempcode The language file selector */ function nice_get_lang_files($lang = NULL) { $_lang_files = get_lang_files(is_null($lang) ? get_site_default_lang() : $lang); ksort($_lang_files); require_lang('lang'); $lang_files = new ocp_tempcode(); foreach (array_keys($_lang_files) as $lang_file) { if (!is_null($lang)) { $base_map = get_lang_file_map(fallback_lang(), $lang_file, true); $criticise_map = get_lang_file_map($lang, $lang_file); $num_translated = 0; $num_english = count($base_map); foreach ($base_map as $key => $val) { if (array_key_exists($key, $criticise_map)) { $num_translated++; } } $lang_files->attach(form_input_list_entry($lang_file, false, do_lang_tempcode('TRANSLATION_PROGRESS', escape_html($lang_file), escape_html(integer_format($num_translated)), escape_html(integer_format($num_english))))); } else { $lang_files->attach(form_input_list_entry($lang_file, false, $lang_file)); } } return $lang_files; }