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

com.jk.locale.JKLocale Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2002-2016 Jalal Kiswani.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jk.locale;

import java.io.Serializable;
import java.util.Locale;

/**
 * The Class JKLocale.
 *
 * @author Jalal Kiswani
 */
public class JKLocale implements Serializable {
	/**
	 *
	 */
	private static final long serialVersionUID = -4392783699434888201L;

	 /** The Constant ARABIC. */
	 public static final JKLocale ARABIC = new JKLocale(1, "ar");
	
	 /** The Constant ENGLISH. */
	 public static final JKLocale ENGLISH = new JKLocale(2, "en");
	
	// /**
	// * Value of.
	// *
	// * @param languageId
	// * the language id
	// * @return the JK locale
	// */
	public static JKLocale valueOf(final int languageId) {
		return languageId == 1 ? ARABIC : ENGLISH;
	}
	//
	// /**
	// * Value of.
	// *
	// * @param localeString
	// * the locale string
	// * @return the JK locale
	// */
	 public static JKLocale valueOf(final String localeString) {
	 return localeString.equals("ar") ? ARABIC : ENGLISH;
	 }

	 int languageId;
	 String languageName;

	private Locale locale;

	/**
	 * Instantiates a new JK locale.
	 *
	 * @param languageName
	 *            the language name
	 */
	public JKLocale(final String languageName) {
		locale = new Locale(languageName);
	}

	/**
	 * Instantiates a new JK locale.
	 *
	 * @param locale
	 *            the locale
	 */
	public JKLocale(Locale locale) {
		this.locale = locale;
	}

	public JKLocale(int id, String name) {
		languageId = id;
		languageName = name;
	}
	/**
	 * Gets the locale.
	 *
	 * @return the locale
	 */
	public Locale getLocale() {
		return locale;
	}

	/**
	 * Sets the locale.
	 *
	 * @param locale
	 *            the new locale
	 */
	public void setLocale(Locale locale) {
		this.locale = locale;
	}

	/**
	 * Gets the language name.
	 *
	 * @return the languageName
	 */
	public String getLanguageName() {
		return locale.getDisplayLanguage();
	}

	/**
	 * Gets the language short name.
	 *
	 * @return the language short name
	 */
	public String getLanguageShortName() {
		return locale.getLanguage();
	}

//	/**
//	 * Value of.
//	 *
//	 * @param locale2
//	 *            the locale 2
//	 * @return the JK locale
//	 */
//	public static JKLocale valueOf(JKLocale locale2) {
//		// TODO Auto-generated method stub
//		return null;
//	}

//	/**
//	 * Value of.
//	 *
//	 * @param languageId
//	 *            the language id
//	 * @return the JK locale
//	 */
//	public static JKLocale valueOf(int languageId) {
////		throw new IllegalStateException("implement me");
//		return nre JK
//	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy