I am revising the dynamic-locale plugin to display buttons rather than a pull down list. In this way I can then blend the buttons in with CSS to look like a typical pipelist. Check it out bottom left here: http://estudioa-2.com/
As you can see it works but the problem I have is that I cannot find the correct way to label the button. I want the button value (label) to be the 'language array key'/'language name' eg. Español. This however generates the error which says that the locale cannot be found on the server.
Now I suspect that this is because the getOption function called in the plugin is only appropriate for a select list and not for buttons. Is that assumption correct? How can I get around that - by writing another function to convert the value to the 'language array item'/'ISO code' ie. es_ES.
I include below the plugin in which, for simplicity, I also put the new functions rather than also hacking the functions and functions-i18n files. To toggle the error alternate between lines 46 and 47 (//if ($localize) $display = $key;...) . Please feel free to suggest more efficient methods or redundant code.
A second method I really would prefer to use is an unordered html list (UL) styled with CSS to make a flat/pipelist. I believe that to POST the locale selection would need a javascript call on anchor links around the language list items (LI). Can anyone illustrate to to do this alternate method correctly to avoid hassle with the buttons?
Of course if anyone can outline which of these two methods is best and why then I would be most grateful!
Mike
`
<?php
/**
* dynamic-locale -- plugin to allow the site viewer to select a localization.
* This applies only to the theme pages--not Admin. Admin continues to use the
* language option for its language.
*
* Only the zenphoto and theme gettext() string are localized by this facility.
*
* If you want to support image descriptions, etc. in multiple languages you will
* have to enable the multi-lingual option found next to the language selector on
* the admin gallery configuration page. Then you will have to provide appropriate
* alternate translations for the fields you use. While there will be a place for
* strings for all zenphoto supported languages you need supply only those you choose.
* The others language strings will default to your local language.
*
* Uses cookies to store the individual selection. Sets the 'locale' option
* to the selected language (non-persistent.)
*
* @author Stephen Billard (sbillard)
* @version 1.0.0
* @package plugins
*/
$plugin_description = gettext("Enable [b]dynamic-locale[/b] to allow viewers of your site to select the language translation of their choice.");
$plugin_author = "Stephen Billard (sbillard)";
$plugin_version = '1.0.0';
$plugin_URL = "http://www.zenphoto.org/documentation/plugins/_plugins---dynamic-locale.php.html";
function generateButtonsFromArray($currentValue, $list, $descending, $localize) {
if ($localize) {
$list = array_flip($list);
if ($descending) {
arsort($list);
} else {
natcasesort($list);
}
$list = array_flip($list);
} else {
if ($descending) {
rsort($list);
} else {
natcasesort($list);
}
}
foreach($list as $key=>$item) {
echo "\n".'<input type="submit" name="dynamic-locale"';
//if ($localize) $display = $key; else $display = $item;
$display = $item;
echo ' value="' . $display . '"';
echo ' class="localeButton';
if (in_array($item, $currentValue)) {
echo ' localeCurrent';
}
echo '" />';
}
}
$_zp_active_languages = NULL;
function generateLanguageButtons($HTTPAccept) {
global $_zp_active_languages;
if (!is_array($_zp_active_languages)) {
$_zp_active_languages = generateLanguageList();
}
$locales = $_zp_active_languages;
if ($HTTPAccept) { // for admin only
$locales[gettext("HTTP Accept Language")] = '';
}
generateButtonsFromArray(array(getOption('locale', $HTTPAccept)), $locales, false, true);
}
/**
* prints a form for selecting a locale
* The POST handling is by getUserLocale() called in functions.php
*
*/
function printLanguageSelector($class='') {
global $_zp_languages;
if (isset($_POST['dynamic-locale'])) {
$locale = sanitize($_POST['dynamic-locale'], 0);
if (getOption('locale') != $locale) {
echo '';
echo ''.sprintf(gettext('[i]%s[/i] is not available.'),$_zp_languages[$locale]).
' '.sprintf(gettext('The locale %s is not supported on your server.').
''.gettext('See the troubleshooting guide on zenphoto.org for details.'), $locale);
echo '';
echo '';
}
}
if (!empty($class)) { $class = " class='$class'"; }
echo "\n\n";
echo '<form action="#" method="post">'."\n";
echo '<input type="hidden" name="oldlocale" value="'.getOption('locale').'" />';
generateLanguageButtons(false);
echo "</form>\n";
echo "\n";
}
?>
`