CVS: TapestryBook/examples/src/examples/l10n L10N.java,NONE,1.1 LocaleModel.java,NONE,1.1
Howard Lewis Ship <[email protected]> Sun, 09 Mar 2003 13:34:49 -0800
| Newsgroups | gmane.comp.java.tapestry.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tapestry/TapestryBook/examples/src/examples/l10n
In directory sc8-pr-cvs1:/tmp/cvs-serv20921/examples/src/examples/l10n
Added Files:
L10N.java LocaleModel.java
Log Message:
Add info on localization.
--- NEW FILE: L10N.java ---
package examples.l10n;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.html.BasePage;
public class L10N extends BasePage
{
private IPropertySelectionModel _localeModel;
public IPropertySelectionModel getLocaleModel()
{
if (_localeModel == null)
_localeModel = new LocaleModel(getLocale());
return _localeModel;
}
public void formSubmit(IRequestCycle cycle)
{
// This page is already loaded, with whatever the old locale was.
// engine.locale has been updated with the new locale.
// Load and render a different page to see the change.
cycle.setPage("L10NResult");
}
}
--- NEW FILE: LocaleModel.java ---
package examples.l10n;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.tapestry.form.IPropertySelectionModel;
/**
* A model that presents as a list all the available locales
* except the current one.
*
* @author Howard Lewis Ship
* @version $Id: LocaleModel.java,v 1.1 2003/03/09 21:34:46 hship Exp $
* @since 2.4
*
**/
public class LocaleModel implements IPropertySelectionModel
{
private Locale _activeLocale;
private List _locales = new ArrayList();
private static final Locale[] AVAILABLE_LOCALES =
{ Locale.ENGLISH, Locale.FRENCH, new Locale("es"), Locale.GERMAN };
public LocaleModel(Locale activeLocale)
{
_activeLocale = activeLocale;
String activeLanguage = activeLocale.getLanguage();
for (int i = 0; i < AVAILABLE_LOCALES.length; i++)
{
if (AVAILABLE_LOCALES[i].getLanguage().equals(activeLanguage))
continue;
_locales.add(AVAILABLE_LOCALES[i]);
}
}
public int getOptionCount()
{
return _locales.size();
}
public Object getOption(int index)
{
return _locales.get(index);
}
public String getLabel(int index)
{
Locale l = (Locale) _locales.get(index);
return l.getDisplayLanguage(_activeLocale);
}
public String getValue(int index)
{
return Integer.toString(index);
}
public Object translateValue(String value)
{
int index = Integer.parseInt(value);
return getOption(index);
}
}
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
for complex code. Debugging C/C++ programs can leave you feeling lost and
disoriented. TotalView can help you find your way. Available on major UNIX
and Linux platforms. Try it free. www.etnus.com