2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Common config manipulation functions
10 * Returns sanitized language string, taking into account our special codes
11 * for formatting. Takes variable number of arguments.
12 * Based on PMA_sanitize from sanitize.lib.php.
14 * @param string $lang_key key in $GLOBALS WITHOUT 'strSetup' prefix
15 * @param mixed $args arguments for sprintf
18 function PMA_lang($lang_key)
20 static $search, $replace;
22 // some quick cache'ing
23 if ($search === null) {
24 $replace_pairs = array(
29 '[strong]' => '<strong>',
30 '[/strong]' => '</strong>',
32 '[/code]' => '</code>',
37 '[/sup]' => '</sup>');
38 if (defined('PMA_SETUP')) {
39 $replace_pairs['[a@Documentation.html'] = '[a@../Documentation.html';
41 $search = array_keys($replace_pairs);
42 $replace = array_values($replace_pairs);
44 $message = isset($GLOBALS["strConfig$lang_key"]) ?
$GLOBALS["strConfig$lang_key"] : $lang_key;
45 $message = str_replace($search, $replace, $message);
46 // replace [a@"$1"]$2[/a] with <a href="$1">$2</a>
47 $message = preg_replace('#\[a@("?)([^\]]+)\1\]([^\[]+)\[/a\]#e',
48 "PMA_lang_link_replace('$2', '$3')", $message);
50 if (func_num_args() == 1) {
53 $args = func_get_args();
55 return vsprintf($message, $args);
60 * Returns translated field name/description or comment
62 * @param string $canonical_path
63 * @param string $type 'name', 'desc' or 'cmt'
64 * @param mixed $default
67 function PMA_lang_name($canonical_path, $type = 'name', $default = 'key')
69 $lang_key = str_replace(
70 array('Servers/1/', '/'),
71 array('Servers/', '_'),
72 $canonical_path) . '_' . $type;
73 return isset($GLOBALS["strConfig$lang_key"])
74 ?
($type == 'desc' ?
PMA_lang($lang_key) : $GLOBALS["strConfig$lang_key"])
75 : ($default == 'key' ?
$lang_key : $default);
79 * Wraps link in <a> tags and replaces argument separator in internal links
80 * to the one returned by PMA_get_arg_separator()
86 function PMA_lang_link_replace($link, $text)
90 if (!isset($separator)) {
91 $separator = PMA_get_arg_separator('html');
94 if (!preg_match('#^http://#', $link)) {
95 $link = str_replace('&', $separator, $link);
98 return '<a href="' . $link . '">' . $text . '</a>';