function get_lang_files(&$arr, &$i, &$dir) { if (is_dir($dir)) { $list = scandir($dir); foreach ($list as $file) { if ($file != 'images' && $file != '.' && $file != '..') { $val = $dir . '/' . $file; if (!is_dir($val)) { $arr[$i]['path'] = $val; $arr[$i]['path_str'] = rawurlencode($val); $i++; } else { $arr = get_lang_files($arr, $i, $val); } } } } return $arr; }
/** * Generates a <table> of every language that Textpattern supports. * * If requested with HTTP POST parameter 'force' set anything other than 'file', * outputs any errors in RPC server connection. * * @param string|array $message The activity message */ function list_languages($message = '') { require_once txpath . '/lib/IXRClass.php'; $active_lang = safe_field("val", 'txp_prefs', "name = 'language'"); $lang_form = tag(form(tag(gTxt('active_language'), 'label', array('for' => 'language')) . languages('language', $active_lang) . eInput('lang') . sInput('save_language')), 'div', array('class' => 'txp-control-panel')); $client = new IXR_Client(RPC_SERVER); // $client->debug = true; $available_lang = array(); $rpc_connect = false; $show_files = false; // Get items from RPC. @set_time_limit(90); // TODO: 90 seconds: seriously? if ($client->query('tups.listLanguages', get_pref('blog_uid'))) { $rpc_connect = true; $response = $client->getResponse(); foreach ($response as $language) { $available_lang[$language['language']]['rpc_lastmod'] = gmmktime($language['lastmodified']->hour, $language['lastmodified']->minute, $language['lastmodified']->second, $language['lastmodified']->month, $language['lastmodified']->day, $language['lastmodified']->year); } } elseif (gps('force') != 'file') { $msg = gTxt('rpc_connect_error') . "<!--" . $client->getErrorCode() . ' ' . $client->getErrorMessage() . "-->"; } // Get items from Filesystem. $files = get_lang_files(); if (is_array($files) && !empty($files)) { foreach ($files as $file) { if ($fp = @fopen(txpath . DS . 'lang' . DS . $file, 'r')) { $name = preg_replace('/\\.(txt|textpack)$/i', '', $file); $firstline = fgets($fp, 4069); fclose($fp); if (strpos($firstline, '#@version') !== false) { @(list($fversion, $ftime) = explode(';', trim(substr($firstline, strpos($firstline, ' ', 1))))); } else { $fversion = $ftime = null; } $available_lang[$name]['file_note'] = isset($fversion) ? $fversion : 0; $available_lang[$name]['file_lastmod'] = isset($ftime) ? $ftime : 0; } } } // Get installed items from the database. // We need a value here for the language itself, not for each one of the rows. $rows = safe_rows("lang, UNIX_TIMESTAMP(MAX(lastmod)) AS lastmod", 'txp_lang', "1 = 1 GROUP BY lang ORDER BY lastmod DESC"); $installed_lang = array(); foreach ($rows as $language) { $available_lang[$language['lang']]['db_lastmod'] = $language['lastmod']; if ($language['lang'] != $active_lang) { $installed_lang[] = $language['lang']; } } $list = ''; // Create the language table components. foreach ($available_lang as $langname => $langdat) { $file_updated = isset($langdat['db_lastmod']) && @$langdat['file_lastmod'] > $langdat['db_lastmod']; $rpc_updated = @$langdat['rpc_lastmod'] > @$langdat['db_lastmod']; $rpc_install = tda($rpc_updated ? strong(eLink('lang', 'get_language', 'lang_code', $langname, isset($langdat['db_lastmod']) ? gTxt('update') : gTxt('install'), 'updating', isset($langdat['db_lastmod']), '')) . n . span(safe_strftime('%d %b %Y %X', @$langdat['rpc_lastmod']), array('class' => 'date modified')) : (isset($langdat['rpc_lastmod']) ? gTxt('up_to_date') : '-') . (isset($langdat['db_lastmod']) ? n . span(safe_strftime('%d %b %Y %X', $langdat['db_lastmod']), array('class' => 'date modified')) : ''), isset($langdat['db_lastmod']) && $rpc_updated ? ' class="highlight lang-value"' : ' class="lang-value"'); $lang_file = tda(isset($langdat['file_lastmod']) ? strong(eLink('lang', 'get_language', 'lang_code', $langname, $file_updated ? gTxt('update') : gTxt('install'), 'force', 'file', '')) . n . span(safe_strftime(get_pref('archive_dateformat'), $langdat['file_lastmod']), array('class' => 'date ' . ($file_updated ? 'created' : 'modified'))) : '-', ' class="lang-value languages_detail' . (isset($langdat['db_lastmod']) && $rpc_updated ? ' highlight' : '') . '"'); $list .= tr(hCell(gTxt($langname), '', isset($langdat['db_lastmod']) && $rpc_updated ? ' class="highlight lang-label" scope="row"' : ' class="lang-label" scope="row"') . n . $rpc_install . n . $lang_file . tda(in_array($langname, $installed_lang) ? dLink('lang', 'remove_language', 'lang_code', $langname, 1) : '-', ' class="languages_detail' . (isset($langdat['db_lastmod']) && $rpc_updated ? ' highlight' : '') . '"')) . n; } // Output table and content. pagetop(gTxt('tab_languages'), $message); echo n . tag(hed(gTxt('tab_languages'), 1, array('class' => 'txp-heading')), 'div', array('class' => 'txp-layout-2col-cell-1')) . n . tag_start('div', array('class' => 'txp-layout-1col', 'id' => 'language_container')); if (isset($msg) && $msg) { echo graf('<span class="ui-icon ui-icon-closethick"></span> ' . $msg, array('class' => 'alert-block error')); } echo $lang_form, n . tag(toggle_box('languages_detail'), 'div', array('class' => 'txp-list-options')) . n . tag_start('div', array('class' => 'txp-listtables')) . n . tag_start('table', array('class' => 'txp-list')) . n . tag_start('thead') . tr(hCell(gTxt('language'), '', ' scope="col"') . hCell(gTxt('from_server') . popHelp('install_lang_from_server'), '', ' scope="col"') . hCell(gTxt('from_file') . popHelp('install_lang_from_file'), '', ' class="languages_detail" scope="col"') . hCell(gTxt('remove_lang') . popHelp('remove_lang'), '', ' class="languages_detail" scope="col"')) . n . tag_end('thead') . n . tag_start('tbody') . $list . n . tag_end('tbody') . n . tag_end('table') . n . tag_end('div') . hed(gTxt('install_from_textpack'), 2) . n . tag(form('<label for="textpack-install">' . gTxt('install_textpack') . '</label>' . popHelp('get_textpack') . n . '<textarea class="code" id="textpack-install" name="textpack" cols="' . INPUT_LARGE . '" rows="' . TEXTAREA_HEIGHT_SMALL . '" dir="ltr"></textarea>' . fInput('submit', 'install_new', gTxt('upload')) . eInput('lang') . sInput('get_textpack'), '', '', 'post', '', '', 'text_uploader'), 'div', array('class' => 'txp-control-panel')) . n . tag_end('div'); }
function list_languages($message = '') { global $prefs, $locale, $txpcfg, $textarray; require_once txpath . '/lib/IXRClass.php'; // Select and save active language if (!$message && ps('step') == 'list_languages' && ps('language')) { $locale = doSlash(getlocale(ps('language'))); safe_update("txp_prefs", "val='" . doSlash(ps('language')) . "'", "name='language'"); safe_update("txp_prefs", "val='" . $locale . "'", "name='locale'"); $textarray = load_lang(doSlash(ps('language'))); $locale = setlocale(LC_ALL, $locale); $message = gTxt('preferences_saved'); } $active_lang = safe_field('val', 'txp_prefs', "name='language'"); $lang_form = tda(form(gTxt('active_language') . ' ' . languages('language', $active_lang) . ' ' . fInput('submit', 'Submit', gTxt('save_button'), '') . eInput('prefs') . sInput('list_languages'), 'display:inline;'), ' style="text-align:center" colspan="3"'); $client = new IXR_Client(RPC_SERVER); #$client->debug = true; $available_lang = array(); $rpc_connect = false; $show_files = false; # Get items from RPC @set_time_limit(90); if (gps('force') != 'file' && $client->query('tups.listLanguages', $prefs['blog_uid'])) { $rpc_connect = true; $response = $client->getResponse(); foreach ($response as $language) { $available_lang[$language['language']]['rpc_lastmod'] = gmmktime($language['lastmodified']->hour, $language['lastmodified']->minute, $language['lastmodified']->second, $language['lastmodified']->month, $language['lastmodified']->day, $language['lastmodified']->year); } } elseif (gps('force') != 'file') { $msg = gTxt('rpc_connect_error') . "<!--" . $client->getErrorCode() . ' ' . $client->getErrorMessage() . "-->"; } # Get items from Filesystem $files = get_lang_files(); if (gps('force') == 'file' || !$rpc_connect) { $show_files = true; } if ($show_files && is_array($files) && !empty($files)) { foreach ($files as $file) { if ($fp = @fopen(txpath . DS . 'lang' . DS . $file, 'r')) { $name = str_replace('.txt', '', $file); $firstline = fgets($fp, 4069); fclose($fp); if (strpos($firstline, '#@version') !== false) { @(list($fversion, $ftime) = explode(';', trim(substr($firstline, strpos($firstline, ' ', 1))))); } else { $fversion = $ftime = NULL; } $available_lang[$name]['file_note'] = isset($fversion) ? $fversion : 0; $available_lang[$name]['file_lastmod'] = isset($ftime) ? $ftime : 0; } } } # Get installed items from the database # I'm affraid we need a value here for the language itself, not for each one of the rows $rows = safe_rows('lang, UNIX_TIMESTAMP(MAX(lastmod)) as lastmod', 'txp_lang', "1 GROUP BY lang ORDER BY lastmod DESC"); foreach ($rows as $language) { $available_lang[$language['lang']]['db_lastmod'] = $language['lastmod']; } $list = ''; # Show the language table foreach ($available_lang as $langname => $langdat) { $file_updated = isset($langdat['db_lastmod']) && @$langdat['file_lastmod'] > $langdat['db_lastmod']; $rpc_updated = @$langdat['rpc_lastmod'] > @$langdat['db_lastmod']; $rpc_install = tda(strong(eLink('prefs', 'get_language', 'lang_code', $langname, isset($langdat['db_lastmod']) ? gTxt('update') : gTxt('install'), 'updating', isset($langdat['db_lastmod']))) . br . safe_strftime('%d %b %Y %X', @$langdat['rpc_lastmod']), isset($langdat['db_lastmod']) ? ' style="color:red;text-align:center;background-color:#FFFFCC;"' : ' style="color:#667;vertical-align:middle;text-align:center"'); $list .= tr(tda(gTxt($langname) . tag(isset($langdat['db_lastmod']) ? br . ' ' . safe_strftime('%d %b %Y %X', $langdat['db_lastmod']) : '', 'span', ' style="color:#aaa;font-style:italic"'), isset($langdat['db_lastmod']) && $rpc_updated ? ' nowrap="nowrap" style="color:red;background-color:#FFFFCC;"' : ' nowrap="nowrap" style="vertical-align:middle"') . n . ($rpc_updated ? $rpc_install : tda(isset($langdat['rpc_lastmod']) ? gTxt('updated') : '-', ' style="vertical-align:middle;text-align:center"')) . n . ($show_files ? tda(tag(isset($langdat['file_lastmod']) ? eLink('prefs', 'get_language', 'lang_code', $langname, $file_updated ? gTxt('update') : gTxt('install'), 'force', 'file') . br . ' ' . safe_strftime($prefs['archive_dateformat'], $langdat['file_lastmod']) : ' ', 'span', $file_updated ? ' style="color:#667;"' : ' style="color:#aaa;font-style:italic"'), ' class="langfile" style="text-align:center;vertical-align:middle"') . n : '')) . n . n; } // Output Table + Content pagetop(gTxt('update_languages'), $message); if (isset($msg) && $msg) { echo tag($msg, 'p', ' style="text-align:center;color:red;width:50%;margin: 2em auto"'); } echo startTable('list'), tr(tdcs(hed(gTxt('manage_languages'), 1), 3)), tr(tdcs(sLink('prefs', 'prefs_list', gTxt('site_prefs'), 'navlink') . sp . sLink('prefs', 'advanced_prefs', gTxt('advanced_preferences'), 'navlink') . sp . sLink('prefs', 'list_languages', gTxt('manage_languages'), 'navlink-active'), '3')), tr(tda(' ', ' colspan="3" style="font-size:0.25em"')), tr($lang_form), tr(tda(' ', ' colspan="3" style="font-size:0.25em"')), tr(tda(gTxt('language')) . tda(gTxt('from_server')) . ($show_files ? tda(gTxt('from_file')) : ''), ' style="font-weight:bold"'); echo $list; if (!$show_files) { $linktext = gTxt('from_file') . ' (' . gTxt('experts_only') . ')'; echo tr(tda(' ', ' colspan="3" style="font-size:0.25em"')) . tr(tda(strong(eLink('prefs', 'list_languages', 'force', 'file', $linktext)), ' colspan="3" style="text-align:center"')); } elseif (gps('force') == 'file') { echo tr(tda(' ', ' colspan="3" style="font-size:0.25em"')) . tr(tda(sLink('prefs', 'list_languages', strong(gTxt('from_server'))), ' colspan="3" style="text-align:center"')); } echo endTable(); $install_langfile = gTxt('install_langfile', array('{url}' => strong('<a href="' . RPC_SERVER . '/lang/">' . RPC_SERVER . '/lang/</a>'))); if ($install_langfile == 'install_langfile') { $install_langfile = 'To install new languages from file you can download them from <b><a href="' . RPC_SERVER . '/lang/">' . RPC_SERVER . '/lang/</a></b> and place them inside your ./textpattern/lang/ directory.'; } echo tag($install_langfile, 'p', ' style="text-align:center;width:50%;margin: 2em auto"'); }
/** * 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')); }
function list_languages($message = '') { global $prefs, $locale, $textarray; require_once txpath . '/lib/IXRClass.php'; // Select and save active language if (!$message && ps('step') == 'list_languages' && ps('language')) { $locale = doSlash(getlocale(ps('language'))); safe_update("txp_prefs", "val='" . doSlash(ps('language')) . "'", "name='language'"); safe_update("txp_prefs", "val='" . $locale . "'", "name='locale'"); $textarray = load_lang(doSlash(ps('language'))); $locale = setlocale(LC_ALL, $locale); $message = gTxt('preferences_saved'); } $active_lang = safe_field('val', 'txp_prefs', "name='language'"); $lang_form = '<div id="language_control" class="txp-control-panel">' . form(graf(gTxt('active_language') . languages('language', $active_lang) . n . fInput('submit', 'Submit', gTxt('save'), 'publish') . eInput('prefs') . sInput('list_languages'))) . '</div>'; $client = new IXR_Client(RPC_SERVER); //$client->debug = true; $available_lang = array(); $rpc_connect = false; $show_files = false; // Get items from RPC @set_time_limit(90); if ($client->query('tups.listLanguages', $prefs['blog_uid'])) { $rpc_connect = true; $response = $client->getResponse(); foreach ($response as $language) { $available_lang[$language['language']]['rpc_lastmod'] = gmmktime($language['lastmodified']->hour, $language['lastmodified']->minute, $language['lastmodified']->second, $language['lastmodified']->month, $language['lastmodified']->day, $language['lastmodified']->year); } } elseif (gps('force') != 'file') { $msg = gTxt('rpc_connect_error') . "<!--" . $client->getErrorCode() . ' ' . $client->getErrorMessage() . "-->"; } // Get items from Filesystem $files = get_lang_files(); if (is_array($files) && !empty($files)) { foreach ($files as $file) { if ($fp = @fopen(txpath . DS . 'lang' . DS . $file, 'r')) { $name = str_replace('.txt', '', $file); $firstline = fgets($fp, 4069); fclose($fp); if (strpos($firstline, '#@version') !== false) { @(list($fversion, $ftime) = explode(';', trim(substr($firstline, strpos($firstline, ' ', 1))))); } else { $fversion = $ftime = NULL; } $available_lang[$name]['file_note'] = isset($fversion) ? $fversion : 0; $available_lang[$name]['file_lastmod'] = isset($ftime) ? $ftime : 0; } } } // Get installed items from the database // We need a value here for the language itself, not for each one of the rows $rows = safe_rows('lang, UNIX_TIMESTAMP(MAX(lastmod)) as lastmod', 'txp_lang', "1 GROUP BY lang ORDER BY lastmod DESC"); $installed_lang = array(); foreach ($rows as $language) { $available_lang[$language['lang']]['db_lastmod'] = $language['lastmod']; if ($language['lang'] != $active_lang) { $installed_lang[] = $language['lang']; } } $list = ''; // Show the language table foreach ($available_lang as $langname => $langdat) { $file_updated = isset($langdat['db_lastmod']) && @$langdat['file_lastmod'] > $langdat['db_lastmod']; $rpc_updated = @$langdat['rpc_lastmod'] > @$langdat['db_lastmod']; $rpc_install = tda($rpc_updated ? strong(eLink('prefs', 'get_language', 'lang_code', $langname, isset($langdat['db_lastmod']) ? gTxt('update') : gTxt('install'), 'updating', isset($langdat['db_lastmod']), '')) . n . '<span class="date modified">' . safe_strftime('%d %b %Y %X', @$langdat['rpc_lastmod']) . '</span>' : (isset($langdat['rpc_lastmod']) ? gTxt('updated') : '-') . (isset($langdat['db_lastmod']) ? n . '<span class="date modified">' . safe_strftime('%d %b %Y %X', $langdat['db_lastmod']) . '</span>' : ''), isset($langdat['db_lastmod']) && $rpc_updated ? ' class="highlight lang-value"' : ' class="lang-value"'); $lang_file = tda(isset($langdat['file_lastmod']) ? strong(eLink('prefs', 'get_language', 'lang_code', $langname, $file_updated ? gTxt('update') : gTxt('install'), 'force', 'file', '')) . n . '<span class="date ' . ($file_updated ? 'created' : 'modified') . '">' . safe_strftime($prefs['archive_dateformat'], $langdat['file_lastmod']) . '</span>' : '-', ' class="lang-value languages_detail' . (isset($langdat['db_lastmod']) && $rpc_updated ? ' highlight' : '') . '"'); $list .= tr(tda(gTxt($langname), isset($langdat['db_lastmod']) && $rpc_updated ? ' class="highlight lang-label"' : ' class="lang-label"') . n . $rpc_install . n . $lang_file . n . tda(in_array($langname, $installed_lang) ? dLink('prefs', 'remove_language', 'lang_code', $langname, 1) : '-', ' class="languages_detail' . (isset($langdat['db_lastmod']) && $rpc_updated ? ' highlight' : '') . '"')) . n . n; } // Output Table + Content // TODO: tab_languages when this panel is moved to its own tab pagetop(gTxt('update_languages'), $message); //TODO: tab_languages when this panel is moved to its own tab echo '<h1 class="txp-heading">' . gTxt('update_languages') . '</h1>'; echo n . '<div id="language_container" class="txp-container">'; if (isset($msg) && $msg) { echo tag($msg, 'p', ' class="error lang-msg"'); } echo n . '<p class="nav-tertiary">' . sLink('prefs', 'prefs_list', gTxt('site_prefs'), 'navlink') . sLink('prefs', 'advanced_prefs', gTxt('advanced_preferences'), 'navlink') . sLink('prefs', 'list_languages', gTxt('manage_languages'), 'navlink-active') . n . '</p>'; echo $lang_form; echo n, '<div class="txp-listtables">', startTable('', '', 'txp-list'), '<thead>', tr(hCell(gTxt('language')) . hCell(gTxt('from_server') . n . popHelp('install_lang_from_server')) . hCell(gTxt('from_file') . n . popHelp('install_lang_from_file'), '', ' class="languages_detail"') . hCell(gTxt('remove_lang') . n . popHelp('remove_lang'), '', ' class="languages_detail"')), '</thead>'; echo '<tbody>' . $list . '</tbody>', endTable(), n, '</div>'; echo graf(toggle_box('languages_detail'), ' class="detail-toggle"'); echo hed(gTxt('install_from_textpack'), 3) . n . form(graf('<label for="textpack-install">' . gTxt('install_textpack') . '</label>' . n . popHelp('get_textpack') . n . '<textarea id="textpack-install" class="code" name="textpack" cols="' . INPUT_LARGE . '" rows="' . INPUT_XSMALL . '"></textarea>' . n . fInput('submit', 'install_new', gTxt('upload')) . eInput('prefs') . sInput('get_textpack')), '', '', 'post', 'edit-form', '', 'text_uploader'); echo '</div>'; // end language_container }
function list_languages($message = '') { global $prefs; require_once txpath . '/lib/IXRClass.php'; pagetop(gTxt('update_languages'), $message); $client = new IXR_Client('http://rpc.textpattern.com'); #$client->debug = true; echo startTable('list'), tr(tdcs(hed(gTxt('update_languages'), 1), 3)), tr(tdcs(sLink('prefs', 'prefs_list', gTxt('site_prefs')) . sp . sLink('prefs', 'advanced_prefs', gTxt('advanced_preferences')), '3')); if (!$client->query('tups.listLanguages', $prefs['blog_uid'])) { $files = get_lang_files(); if (is_array($files) && !empty($files)) { foreach ($files as $file) { if ($fp = @fopen(txpath . '/lang/' . $file, 'r')) { $firstline = fgets($fp, 4069); fclose($fp); if (strpos($firstline, '#@version') !== false) { # Looks like: "#@version id;unixtimestamp" @(list($fversion, $ftime) = explode(';', trim(substr($firstline, strpos($firstline, ' ', 1))))); $note = "({$fversion} " . date("d. F Y", $ftime) . ")"; } else { $note = "(outdated)"; } } else { $note = ''; } $code = substr($file, 0, 5); echo tr(tda(eLink('prefs', 'get_language', 'lang_code', $code, $code) . sp, ' style="text-align:right;vertical-align:middle"') . tda(eLink('prefs', 'get_language', 'lang_code', $code, gTxt('install'))) . tda($note)); } } echo endTable(); echo tag(gTxt('error') . ': could not connect to RPC server to check for updated languages. Please, try it again later.<br /> If problem connecting to the RPC server persists, you can go to <a href="http://rpc.textpattern.com/lang/">http://rpc.textpattern.com/lang/</a>, download the desired language file and place it in the /lang/ directory of your textpattern install. Textpattern will try do the install using that file.', 'p', ' colspan="3" style="color:red;width:50%;margin: auto"'); } else { $response = $client->getResponse(); if (is_array($response)) { foreach ($response as $language) { # I'm affraid we need a value here for the language itself, not for each one of the rows $db_lastmod = safe_field('UNIX_TIMESTAMP(lastmod)', 'txp_lang', "lang='{$language['language']}' ORDER BY lastmod DESC"); $updating = $db_lastmod ? 1 : 0; $remote_mod = gmmktime($language['lastmodified']->hour, $language['lastmodified']->minute, $language['lastmodified']->second, $language['lastmodified']->month, $language['lastmodified']->day, $language['lastmodified']->year); $updated = $updating && $db_lastmod >= $remote_mod ? 1 : 0; if ($updated) { echo tr(tda(gTxt($language['language']) . sp, ' style="text-align:right;vertical-align:middle"') . tda(gTxt('updated'))); } else { echo tr(tda(gTxt($language['language']) . sp, $updating ? ' style="text-align:right;vertical-align:middle;color:red;"' : ' style="text-align:right;vertical-align:middle;"') . td(eLink('prefs', 'get_language', 'lang_code', $language['language'], $updating ? gTxt('update') : gTxt('install'), 'updating', "{$updating}"))); } } } echo endTable(); } }
/** * 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; }
/** * Include all the language files for use in the script. * NOTE: This may reduce performance, so you should only use it if you really have to. * * @param ?LANGUAGE_NAME The language to include files from (NULL: use current users language). * @param boolean Only load it up if it is specifically defined for our language. */ function require_all_lang($lang = NULL, $only_if_for_lang = false) { if (is_null($lang)) { global $REQUIRED_ALL_LANG; if (array_key_exists($lang, $REQUIRED_ALL_LANG)) { return; } $REQUIRED_ALL_LANG[$lang] = true; } if (is_null($lang)) { $lang = user_lang(); } require_code('lang2'); $lang_files = get_lang_files(fallback_lang()); foreach (array_keys($lang_files) as $file) { if (!$only_if_for_lang || is_file(get_custom_file_base() . '/lang_custom/' . $lang . '/' . $file . '.ini') || is_file(get_custom_file_base() . '/lang/' . $lang . '/' . $file . '.ini') || is_file(get_custom_file_base() . '/lang_custom/' . $lang . '/' . $file . '.po') || is_file(get_custom_file_base() . '/lang_custom/' . $lang . '/' . $file . '-' . strtolower($lang) . '.po')) { require_lang($file, $lang, NULL, true); } } }