Search in sources :

Example 1 with ViewLocale

use of org.zaproxy.zap.view.ViewLocale in project zaproxy by zaproxy.

the class LocaleUtils method getAvailableViewLocales.

/**
	 * Returns a list of {@code ViewLocale}s, sorted by display name, of the default language and available translations.
	 *
	 * @return the {@code ViewLocale}s of the default language and available translations.
	 * @see ViewLocale
	 * @since 2.4.0
	 */
public static List<ViewLocale> getAvailableViewLocales() {
    List<String> locales = readAvailableLocales();
    List<ViewLocale> localesUI = new ArrayList<>();
    if (!locales.isEmpty()) {
        for (String locale : locales) {
            localesUI.add(new ViewLocale(locale, getLocalDisplayName(locale)));
        }
        Collections.sort(localesUI, new Comparator<ViewLocale>() {

            @Override
            public int compare(ViewLocale o1, ViewLocale o2) {
                return o1.toString().compareTo(o2.toString());
            }
        });
    }
    // Always put English at the top
    localesUI.add(0, new ViewLocale(DEFAULT_LOCALE, getLocalDisplayName(DEFAULT_LOCALE)));
    return localesUI;
}
Also used : ArrayList(java.util.ArrayList) ViewLocale(org.zaproxy.zap.view.ViewLocale)

Example 2 with ViewLocale

use of org.zaproxy.zap.view.ViewLocale in project zaproxy by zaproxy.

the class OptionsLangPanel method saveParam.

@Override
public void saveParam(Object obj) throws Exception {
    OptionsParam options = (OptionsParam) obj;
    ViewLocale selectedLocale = (ViewLocale) localeSelect.getSelectedItem();
    if (selectedLocale != null) {
        options.getViewParam().setLocale(selectedLocale.getLocale());
    }
}
Also used : OptionsParam(org.parosproxy.paros.model.OptionsParam) ViewLocale(org.zaproxy.zap.view.ViewLocale)

Example 3 with ViewLocale

use of org.zaproxy.zap.view.ViewLocale in project zaproxy by zaproxy.

the class OptionsLangPanel method initParam.

@Override
public void initParam(Object obj) {
    OptionsParam options = (OptionsParam) obj;
    ViewLocale locale = LocaleUtils.getViewLocale(options.getViewParam().getLocale());
    localeSelect.setSelectedItem(locale);
}
Also used : OptionsParam(org.parosproxy.paros.model.OptionsParam) ViewLocale(org.zaproxy.zap.view.ViewLocale)

Example 4 with ViewLocale

use of org.zaproxy.zap.view.ViewLocale in project zaproxy by zaproxy.

the class OptionsLocalePanel method saveParam.

@Override
public void saveParam(Object obj) throws Exception {
    OptionsParam options = (OptionsParam) obj;
    ViewLocale selectedLocale = (ViewLocale) localeSelect.getSelectedItem();
    if (selectedLocale != null) {
        options.getViewParam().setLocale(selectedLocale.getLocale());
    }
}
Also used : OptionsParam(org.parosproxy.paros.model.OptionsParam) ViewLocale(org.zaproxy.zap.view.ViewLocale)

Example 5 with ViewLocale

use of org.zaproxy.zap.view.ViewLocale in project zaproxy by zaproxy.

the class OptionsLocalePanel method getLocaleSelect.

private JComboBox<ViewLocale> getLocaleSelect() {
    if (localeSelect == null) {
        localeSelect = new JComboBox<>();
        for (ViewLocale locale : LocaleUtils.getAvailableViewLocales()) {
            localeSelect.addItem(locale);
        }
        localeSelect.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // Change to use the selected language in the dialog
                ViewLocale selectedLocale = (ViewLocale) localeSelect.getSelectedItem();
                if (selectedLocale != null) {
                    Constant.setLocale(selectedLocale.getLocale());
                    localeLabel.setText(Constant.messages.getString("locale.options.label.language"));
                    localeChangeLabel.setText(Constant.messages.getString("locale.options.label.change"));
                }
            }
        });
    }
    return localeSelect;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ViewLocale(org.zaproxy.zap.view.ViewLocale)

Aggregations

ViewLocale (org.zaproxy.zap.view.ViewLocale)5 OptionsParam (org.parosproxy.paros.model.OptionsParam)3 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1