X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=plugins%2Fsquirrelspell%2Fmodules%2Flang_change.mod;h=b0c1da1138b3d491d27837217ceeb2849c1ea0d9;hp=3519a903e4415c115e303bf1b3ccec71a0b8153c;hb=353d074afac6827c90f4bb03e846c5e453d3b5b1;hpb=44d661aa1bdc1a6f35d03ac7e1aee4c93dbc2c93 diff --git a/plugins/squirrelspell/modules/lang_change.mod b/plugins/squirrelspell/modules/lang_change.mod index 3519a903..b0c1da11 100644 --- a/plugins/squirrelspell/modules/lang_change.mod +++ b/plugins/squirrelspell/modules/lang_change.mod @@ -1,98 +1,74 @@ + * @author Konstantin Riabitsev + * @copyright 1999-2018 The SquirrelMail Project Team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package plugins * @subpackage squirrelspell */ +sqgetGlobalVar('smtoken', $submitted_token, SQ_POST, ''); +sm_validate_security_token($submitted_token, -1, TRUE); + global $SQSPELL_APP_DEFAULT; -$use_langs = $_POST['use_langs']; -$lang_default = $_POST['lang_default']; +if (! sqgetGlobalVar('use_langs',$use_langs,SQ_POST)) { + $use_langs = array($SQSPELL_APP_DEFAULT); +} -$words = sqspell_getWords(); -if (!$words) { - $words = sqspell_makeDummy(); +if (! sqgetGlobalVar('lang_default',$lang_default,SQ_POST)) { + $lang_default = $SQSPELL_APP_DEFAULT; } -$langs = sqspell_getSettings($words); -if (sizeof($use_langs)){ - /** - * See if the user clicked any options on the previous page. - */ - if (sizeof($use_langs)>1){ - /** - * See if s/he wants more than one dictionary. - */ - if ($use_langs[0]!=$lang_default){ - /** - * See if we need to juggle the order of the dictionaries - * to make the default dictionary first in line. - */ - if (in_array($lang_default, $use_langs)){ - /** - * See if the user was dumb and chose a default dictionary - * to be something other than the ones he selected. - */ - $hold = array_shift($use_langs); - $lang_string = join(", ", $use_langs); - $lang_string = str_replace("$lang_default", "$hold", $lang_string); - $lang_string = $lang_default . ", " . $lang_string; - } else { - /** - * Yes, he is dumb. - */ - $lang_string = join(', ', $use_langs); - } - } else { - /** - * No need to juggle the order -- preferred is already first. - */ - $lang_string = join(', ', $use_langs); + +/** + * Rebuild languages. Default language is first one. + */ +$new_langs = array($lang_default); +foreach ($use_langs as $lang) { + if (! in_array($lang,$new_langs)) { + $new_langs[]=$lang; } - } else { - /** - * Just one dictionary, please. - */ - $lang_string = $use_langs[0]; - } - $lang_array = explode( ',', $lang_string ); +} + +if (sizeof($new_langs)>1) { $dsp_string = ''; - foreach( $lang_array as $a) { - $dsp_string .= _(trim($a)) . ', '; + foreach( $new_langs as $a) { + $dsp_string .= _(sm_encode_html_special_chars(trim($a))) . _(", "); } + // remove last comma and space $dsp_string = substr( $dsp_string, 0, -2 ); + + // i18n: first %s is comma separated list of languages, second %s - default language. + // Language names are translated, if they are present in squirrelmail.po file. + // make sure that you don't use html codes in language name translations $msg = '

' - . sprintf(_("Settings adjusted to: %s with %s as default dictionary."), ''.$dsp_string.'', ''._($lang_default).'') + . sprintf(_("Settings adjusted to: %s with %s as default dictionary."), + ''.sm_encode_html_special_chars($dsp_string).'', + ''.sm_encode_html_special_chars(_($lang_default)).'') . '

'; } else { /** - * No dictionaries selected. Use system default. + * Only one dictionary is selected. */ $msg = '

' - . sprintf(_("Using %s dictionary (system default) for spellcheck." ), ''.$SQSPELL_APP_DEFAULT.'') + . sprintf(_("Using %s dictionary for spellcheck." ), ''.sm_encode_html_special_chars(_($new_langs[0])).'') . '

'; - $lang_string = $SQSPELL_APP_DEFAULT; } -$old_lang_string = join(", ", $langs); -$words = str_replace("# LANG: $old_lang_string", "# LANG: $lang_string", - $words); -/** - * Write it down where the sun don't shine. - */ -sqspell_writeWords($words); -sqspell_makePage(_("International Dictionaries Preferences Updated"), - null, $msg); + +/** save settings */ +sqspell_saveSettings($new_langs); + +sqspell_makePage(_("International Dictionaries Preferences Updated"), + null, $msg); /** * For Emacs weenies: @@ -101,4 +77,3 @@ sqspell_makePage(_("International Dictionaries Preferences Updated"), * End: * vim: syntax=php */ -?> \ No newline at end of file