/*
 * Created on 2004-11-14
 *
 * Part of the Symbian development plug-in for Eclipse
 * Copyright (C) Mikołaj Zalewski, 2004
 */
package pl.zalewski.mikolaj.symbdev.core.mmpmodel;

/**
 * A language definition in the MMP file
 * 
 * @author mikolaj
 */
public interface ILanguage {
    /**
     * Languages with numeric ids defined by Symbian
     * 
     * @author mikolaj
     */
    static class StdLanguage
    {
        StdLanguage(String name, int id)
        {
            this.name=name;
            this.id=id;
        }
        
        /**
         * Human-readable name
         */
        public String name;
        
        /**
         * Symbian id
         */
        public int id;
        
        /**
         * Get the id in the standard string representation
         */
        public String getStringId()
        {
            if (id<10) return "0"+id;
            return ""+id;
        }
        
        /**
         * This functions checks if the given id is a code of a code
         * of a standard language. 
         * @param id The id of the language
         * @return The position of the StdLanguage object for this language
         * in the ILanguage.stdLanguages table or -1 if this is not a code
         * of a known language 
         */
        static public int getStdLanguagePos(String id)
        {
            if (id.length()==2)
            {
                int d1=id.charAt(0)-'0';
                int d2=id.charAt(1)-'0';
                if (d1<0 || d1>9 || d2<0 || d2>9)
                    return -1;
                int num=d1*10+d2;
                
                //binsearch the language
                int l=0, r=ILanguage.stdLanguages.length;
                while (r>l)
                {
                    int k=(l+r)/2;
                    if (num==ILanguage.stdLanguages[k].id)
                        return k;
                    if (num<ILanguage.stdLanguages[k].id) r=k;
                    	else l=k+1;
                }
            }
            return -1;
        }

        /**
         * This functions checks if the given id is a code of a code
         * of a standard language. 
         * @param id The id of the language
         * @return The StdLanguage object for this language
         * or <code>null</code> if this is not a code of a known language 
         */
        static public StdLanguage getStdLanguage(String id)
        {
            int k=getStdLanguagePos(id);
            if (k!=-1)
                return ILanguage.stdLanguages[k];
            return null;
        }
        
        /**
         * Returns the name of a known language. This function recognises
         * all the languages that has a StdLanguage structure plus the "SC"
         * unspecified language
         * @param id The id of the language
         * @return The name of this language or <code>null</code>
         * if this is not a code of a known language.
         */
        static public String getStdLanguageName(String id)
        {
            if (id.equals("SC"))
                return "Unspecified";
            StdLanguage lang=getStdLanguage(id);
            if (lang!=null) return lang.name;
            return null;
        }
    
    }
    
    static final StdLanguage[] stdLanguages=new StdLanguage[]{
        new StdLanguage("English", 1),
        new StdLanguage("French", 2),
        new StdLanguage("German", 3),
        new StdLanguage("Spanish", 4),
        new StdLanguage("Italian",  5),
        new StdLanguage("Swedish", 6),
        new StdLanguage("Danish", 7),
        new StdLanguage("Norwegian", 8),
        new StdLanguage("Finnish", 9),
        new StdLanguage("American English", 10),
        new StdLanguage("Swiss French", 11),
        new StdLanguage("Swiss German", 12),
        new StdLanguage("Portuguese", 13),
        new StdLanguage("Turkish", 14),
        new StdLanguage("Icelandic", 15),
        new StdLanguage("Russian", 16),
        new StdLanguage("Hungarian", 17),
        new StdLanguage("Dutch", 18),
        new StdLanguage("Belgian Flemish", 19), // no flag
        new StdLanguage("Australian English", 20), // no flag
        new StdLanguage("Belgian French", 21), // no flag
        new StdLanguage("Austrian German", 22), // no flag
        new StdLanguage("New Zealand English", 23), // no flag
        new StdLanguage("International French", 24), // no flag
        new StdLanguage("Czech", 25),
        new StdLanguage("Slovak", 26),
        new StdLanguage("Polish", 27),
        new StdLanguage("Slovenian", 28),
        new StdLanguage("Taiwanese Chinese", 29),
        new StdLanguage("Hong Kong Chinese", 30), // no flag
        new StdLanguage("Peoples Republic of Chinas Chinese", 31),
        new StdLanguage("Japanese", 32),
        new StdLanguage("Thai", 33),
        new StdLanguage("Afrikaans", 34),
        new StdLanguage("Albanian", 35),
        new StdLanguage("Amharic", 36), // no flag
        new StdLanguage("Arabic", 37), // no flag
        new StdLanguage("Armenian", 38), // no flag
        new StdLanguage("Tagalog", 39),  // no flag
        new StdLanguage("Belarussian", 40), // no flag
        new StdLanguage("Bengali", 41), // no flag
        new StdLanguage("Bulgarian", 42),
        new StdLanguage("Burmese", 43), // no flag
        new StdLanguage("Catalan", 44),
        new StdLanguage("Croation", 45),
        new StdLanguage("Canadian English", 46),
        new StdLanguage("International English", 47), // no flag
        new StdLanguage("South African English", 48),
        new StdLanguage("Estonian", 49),
        new StdLanguage("Farsi", 50),
        new StdLanguage("Canadian French", 51),
        new StdLanguage("Gaelic", 52),
        new StdLanguage("Georgian", 53), // no flag
        new StdLanguage("Greek", 54),
        new StdLanguage("Cyprus Greek", 55),  // no flag
        new StdLanguage("Gujarati", 56), // no flag
        new StdLanguage("Hebrew", 57),
        new StdLanguage("Hindi", 58), // no flag
        new StdLanguage("Indonesian", 59), // no flag
        new StdLanguage("Irish", 60),
        new StdLanguage("Swiss Italian", 61),
        new StdLanguage("Kannada", 62), // no flag
        new StdLanguage("Kazakh", 63), // no flag
        new StdLanguage("Kmer", 64), // no flag
        new StdLanguage("Korean", 65),
        new StdLanguage("Lao", 66), // no flag
        new StdLanguage("Latvian", 67),
        new StdLanguage("Lithuanian", 68),
        new StdLanguage("Macedonian", 69),
        new StdLanguage("Malay", 70), // no flag
        new StdLanguage("Malayalam", 71), // no flag
        new StdLanguage("Marathi", 72), // no flag
        new StdLanguage("Moldovian", 73), // no flag
        new StdLanguage("Mongolian", 74), // no flag
        new StdLanguage("Norwegian Nynorsk", 75),
        new StdLanguage("Brazilian Portuguese", 76),
        new StdLanguage("Punjabi", 77), // no flag
        new StdLanguage("Romanian", 78),
        new StdLanguage("Serbian", 79),
        new StdLanguage("Sinhalese", 80), // no flag
        new StdLanguage("Somali", 81), // no flag
        new StdLanguage("International Spanish", 82),  // no flag
        new StdLanguage("American Spanish",83), // no flag
        new StdLanguage("Swahili", 84), // no flag
        new StdLanguage("Finland Swedish", 85),
        new StdLanguage("Tamil", 87),
        new StdLanguage("Telugu", 88), // no flag
        new StdLanguage("Tibetan", 89), // no flag
        new StdLanguage("Tigrinya", 90), // no flag
        new StdLanguage("Cyprus Turkish", 91), // no flag
        new StdLanguage("Turkmen", 92), // no flag
        new StdLanguage("Ukrainian", 93),
        new StdLanguage("Urdu", 94), // no flag
        new StdLanguage("Vietnamese", 96),
        new StdLanguage("Welsh", 97),
        new StdLanguage("Zulu", 98) // no flag
    };
    
    /**
     * @return The id of the language setting. Usually o two-digt
     * standard Symbian code
     */
    public String getCode();
}
