// -*- c++ -*-

/*
 * Jakelib2 - General purpose C++ library
 * Copyright (C) 2001 Florian Wolff  (florian@donuz.de)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: Locale.h,v 1.10 2003/09/20 11:12:05 florian Exp $
 */

#ifndef INCLUDE_JAKELIB2_UTIL_LOCALE_H
# define INCLUDE_JAKELIB2_UTIL_LOCALE_H

namespace jakelib {
  namespace util {

    /**
     * @brief Locales represent a specific country and culture.
     *
     * Classes which can be passed a \c Locale object tailor their information 
     * for a given locale. For instance, currency number formatting is 
     * handled differently for the USA and France.
     *
     * Locales are made up of a language code, a country code, and an optional
     * set of variant strings.
     *
     * Language codes are represented by
     * <a href="http://www.indigo.ie/egt/standards/iso639/iso639-1-en.html">ISO 639:1988</a>
     * w/ additions from ISO 639/RA Newsletter No. 1/1989
     * and a decision of the Advisory Committee of ISO/TC39 on
     * August 8, 1997.
     *
     * Country codes are represented by 
     * <a href="ftp://ftp.ripe.net/iso3166-countrycodes">ISO 3166</a>.
     *
     * Variant strings are vendor and browser specific.  Standard variant
     * strings include "POSIX" for POSIX, "WIN" for MS-Windows, and "MAC" for
     * Macintosh. When there is more than one variant string, they must
     * be separated by an underscore (U+005F).
     *
     * @class Locale
     * @version $Id: Locale.h,v 1.10 2003/09/20 11:12:05 florian Exp $
     * @author Florian 'Overflo' Wolff (florian@donuz.de)
     * @author Jochen Hoenicke
     * @author Paul Fisher
     */
    class Locale : public jakelib::lang::Object
      {
      public:

	/**
	 * @brief Creates a new locale for the given language and country.
	 *
	 * @param language lowercase two-letter ISO-639 A2 language code.
	 * @param country uppercase two-letter ISO-3166 A2 contry code.
	 * @param variant vendor and browser specific.
	 */
	Locale(jakelib::lang::String* language,
	       jakelib::lang::String* country = null,
               jakelib::lang::String* variant = null);

	/**
	 * @brief Returns the language code of this locale.
	 *
	 * @return language code portion of this locale, or an empty String if
	 * none exists
	 */
        virtual jakelib::lang::String* getLanguage();

	/**
	 * @brief Returns the country code of this locale.
	 *
	 * @return country code portion of this locale, or an empty String if
	 * none exists
	 */
        virtual jakelib::lang::String* getCountry();

	/**
	 * @brief Returns the variant code of this locale.
	 */
        virtual jakelib::lang::String* getVariant();

	/**
	 * @brief Gets the string representation of the current locale.  This
	 * consists of the language, the country, and the variant,
	 * separated by an underscore.  If one of this three component is
	 * missing the underscore will also disappear.  
	 *
	 * @return the string representation of this Locale.
	 */
        jakelib::lang::String* toString();

	/**
	 * @brief Returns the default Locale.  The default locale is generally
	 * once set on start up and then never changed.  Normally you 
	 * should use this locale for everywhere you need a locale.
	 * The initial setting matches the default locale, the user has
	 * chosen.
	 */
        static Locale* getDefault();

        /**
         * Sets the default Locale.
         */
        static void setDefault(Locale *l);

	/**
	 * @brief Returns a list of all 2-letter lowercase language codes as defined
	 * in ISO 639 (both old and new variant).
	 */
        static jakelib::lang::Strings* getISOLanguages();

        /**
         * @brief Called by \c Object::initJakelib2().
         * Do not use otherwise.
         */
        static void initLocaleClass();

	/**
	 * @brief Returns a list of all 2-letter uppercase country codes as defined
	 * in ISO 3166
	 */
        static jakelib::lang::Strings* getISOCountries();

	/** @brief Locale which represents the English language. */
	static Locale* ENGLISH;

	/** @brief Locale which represents the English language. */
	static Locale* FRENCH;

	/** @brief Locale which represents the German language. */
	static Locale* GERMAN;

	/** @brief Locale which represents the Italian language. */
	static Locale* ITALIAN;

	/** @brief Locale which represents the Japanese language. */
	static Locale* JAPANESE;

	/** @brief Locale which represents the Korean language. */
	static Locale* KOREAN;

	/** @brief Locale which represents the Chinese language. */
	static Locale* CHINESE;

	/** @brief Locale which represents the Chinese language as used in China. */
	static Locale* SIMPLIFIED_CHINESE;

	/** @brief Locale which represents the Chinese language as used in Taiwan.
	    Same as \c TAIWAN Locale */
	static Locale* TRADITIONAL_CHINESE;

	/** @brief Locale which represents France. */
	static Locale* FRANCE;

	/** @brief Locale which represents Germany. */
	static Locale* GERMANY;

	/** @brief Locale which represents Italy. */
	static Locale* ITALY;

	/** @brief Locale which represents Japan. */
	static Locale* JAPAN;

	/** @brief Locale which represents Korea. */
	static Locale* KOREA;

	/** @brief Locale which represents China. 
	    Same as \c SIMPLIFIED_CHINESE Locale. */
	static Locale* CHINA;

	/** @brief Locale which represents the People's Republic of China.
	    Same as \c CHINA Locale. */
	static Locale* PRC;

	/** @brief Locale which represents Taiwan.
	    Same as TRADITIONAL_CHINESE Locale. */
	static Locale* TAIWAN;

	/** @brief Locale which represents the United Kingdom. */
	static Locale* UK;

	/** @brief Locale which represents the United States. */
	static Locale* US;

	/** @brief Locale which represents the English speaking portion of Canada. */
	static Locale* CANADA;

	/** @brief Locale which represents the French speaking portion of Canada. */
	static Locale* CANADA_FRENCH;

      private:
        jakelib::lang::String* language;
        jakelib::lang::String* country;
        jakelib::lang::String* variant;
        static Locale* defaultLocale;

        static char* isoLanguageShortNames[];
        static jakelib::lang::Strings* isoLanguages;

        static char* isoCountryShortNames[];
        static jakelib::lang::Strings* isoCountries;

	JAKELIB_DECLARE_CLASS(Locale);
      };

    JAKELIB_DECLARE_ARRAY(Locale);
  }
}
#endif

