001/*
002 * JGrapes Event Driven Framework
003 * Copyright (C) 2022 Michael N. Lipp
004 * 
005 * This program is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Affero General Public License as published by 
007 * the Free Software Foundation; either version 3 of the License, or 
008 * (at your option) any later version.
009 * 
010 * This program is distributed in the hope that it will be useful, but 
011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Affero General Public License along 
016 * with this program; if not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jgrapes.webconsole.base.freemarker;
020
021import java.util.Locale;
022import java.util.ResourceBundle;
023
024/**
025 * Holds the information about a supported language. Used by
026 * {@link FreeMarkerConsoleWeblet#expandConsoleModel(Map, 
027 * org.jgrapes.http.events.Request.In.Get, UUID)} and
028 * {@link FreeMarkerConlet#fmSessionModel(org.jgrapes.http.Session)}
029 * to provide the function "supportedLanguages" during template
030 * evaluation.
031 */
032public class LanguageInfo {
033    private final Locale locale;
034    private final ResourceBundle bundle;
035
036    /**
037     * Instantiates a new language info.
038     *
039     * @param locale the locale
040     */
041    public LanguageInfo(Locale locale, ResourceBundle bundle) {
042        this.locale = locale;
043        this.bundle = bundle;
044    }
045
046    /**
047     * Gets the locale.
048     *
049     * @return the locale
050     */
051    public Locale getLocale() {
052        return locale;
053    }
054
055    /**
056     * Gets the label.
057     *
058     * @return the label
059     */
060    public String getLabel() {
061        String str = locale.getDisplayName(locale);
062        return Character.toUpperCase(str.charAt(0)) + str.substring(1);
063    }
064
065    /**
066     * Gets the bundle.
067     *
068     * @return the bundle
069     */
070    public ResourceBundle getL10nBundle() {
071        return bundle;
072    }
073}