All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.cloudfarming.client.util.swing.i18n.SwingLocalization Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2008-2013 LimeTri. All rights reserved.
 *
 * AgroSense is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * There are special exceptions to the terms and conditions of the GPLv3 as it is applied to
 * this software, see the FLOSS License Exception
 * .
 *
 * AgroSense is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with AgroSense.  If not, see .
 */
package nl.cloudfarming.client.util.swing.i18n;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.UIManager;

/**
 * Utility for enabling translations of built-in Swing components in locales not provided by the JRE.
 * 
 * @author johan
 */
public class SwingLocalization {
    /**
     * Locales for which UI translations are provided by the JRE.
     * 
     * @see http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html#translation
     */
    public static final String[] SUPPORTED_LOCALES = {"de", "en", "es", "fr", "it", "ja", "ko", "pt_BR", "sv", "zh_CN", "zh_TW"};
    
    public static void apply() {
        Locale locale = Locale.getDefault();
        if (isSupported(locale)) { return; }
        ResourceBundle rb = ResourceBundle.getBundle("nl.cloudfarming.client.util.swing.i18n.Bundle", locale);
        for (String key : rb.keySet()) { UIManager.put(key, rb.getString(key)); }
    }
    
    protected static boolean isSupported(Locale locale) {
        String language = locale.getLanguage();
        String country = locale.getCountry();
        List supported = Arrays.asList(SUPPORTED_LOCALES);
        return supported.contains(language) || supported.contains(language + "_" + country);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy