<commit_before>// @requires Tian.js

//=============================================================
// Namespace: Tian.Lang
// Internationalization functions.
//-------------------------------------------------------------

Tian.Lang = {
    /** 
     * Property: code
     * {String}  Current language code to use in Tian.  Use the
     *     <setCode> method to set this value and the <getCode> method to
     *     retrieve it.
     */
    code: null,

    /** 
     * APIProperty: defaultCode
     * {String} Default language to use when a specific language can't be
     *     found.  Default is "en".
     */
    defaultCode: "en",
        
    /**
     * APIFunction: getCode
     * Get the current language code.
     *
     * Returns:
     * The current language code.
     */
    getCode: function() {
        if(!Tian.Lang.code) {
            Tian.Lang.setCode();
        }
        return Tian.Lang.code;
    },
    
    /**
     * APIFunction: setCode
     * Set the language code for string translation.  This code is used by
     *     the <Tian.Lang.translate> method.
     *
     * Parameters-
     * code - {String} These codes follow the IETF recommendations at
     *     http://www.ietf.org/rfc/rfc3066.txt.  If no value is set, the
     *     browser's language setting will be tested.
     */
    setCode: function(code) {
        var lang;
        if(!code) {
            code = (Tian.BROWSER == "msie") ?
                navigator.userLanguage : navigator.language;
        }
        var parts = code.split('-');
        parts[0] = parts[0].toLowerCase();
        if(typeof Tian.Lang[parts[0]] == "object") {
            lang = parts[0];
        }

        // check for regional extensions
        if(parts[1]) {
            var testLang = parts[0] + '-' + parts[1].toUpperCase();
            if(typeof Tian.Lang[testLang] == "object") {
                lang = testLang;
            }
        }
        if(!lang) {
            lang = Tian.Lang.defaultCode;
        }
        
        Tian.Lang.code = lang;
    },

    /**
     * APIMethod: translate
     * Looks up a key from a dictionary based on the current language string.
     *     The value of <getCode> will be used to determine the appropriate
     *     dictionary.  Dictionaries are stored in <Tian.Lang>.
     *
     * Parameters:
     * key - {String} The key for an i18n string value in the dictionary.
     * 
     * Returns:
     * {String} A internationalized string.
     */
    translate: function(key) {
        var dictionary = Tian.Lang[Tian.Lang.getCode()];
        var message = dictionary && dictionary[key];
        if(!message) {
            // Message not found, fall back to message key
            message = key;
        }
        return message;
    },
    <commit_msg>Fix bug: Failed to set language code if Tian.Lang[] is empty.<commit_after>// @requires Tian.js

//=============================================================
// Namespace: Tian.Lang
// Internationalization functions.
//-------------------------------------------------------------

Tian.Lang = {
    /** 
     * Property: code
     * {String}  Current language code to use in Tian.  Use the
     *     <setCode> method to set this value and the <getCode> method to
     *     retrieve it.
     */
    code: null,

    /** 
     * APIProperty: defaultCode
     * {String} Default language to use when a specific language can't be
     *     found.  Default is "en".
     */
    defaultCode: "en",
        
    /**
     * APIFunction: getCode
     * Get the current language code.
     *
     * Returns:
     * The current language code.
     */
    getCode: function() {
        if(!Tian.Lang.code) {
            Tian.Lang.setCode();
        }
        return Tian.Lang.code;
    },
    
    /**
     * APIFunction: setCode
     * Set the language code for string translation.  This code is used by
     *     the <Tian.Lang.translate> method.
     *
     * Parameters-
     * code - {String} These codes follow the IETF recommendations at
     *     http://www.ietf.org/rfc/rfc3066.txt.  If no value is set, the
     *     browser's language setting will be tested.
     */
    setCode: function(code) {
        var lang;
        if(!code) {
            code = (Tian.BROWSER == "msie") ?
                navigator.userLanguage : navigator.language;
        }
        
        var parts = code.split('-');
        parts[0] = parts[0].toLowerCase();
        lang = parts[0];

        // check for regional extensions
        if(parts[1]) {
            lang = parts[0] + '-' + parts[1].toUpperCase();
        }
        
        if(!lang) {
            lang = Tian.Lang.defaultCode;
        }
        
        Tian.Lang.code = lang;
    },

    /**
     * APIMethod: translate
     * Looks up a key from a dictionary based on the current language string.
     *     The value of <getCode> will be used to determine the appropriate
     *     dictionary.  Dictionaries are stored in <Tian.Lang>.
     *
     * Parameters:
     * key - {String} The key for an i18n string value in the dictionary.
     * 
     * Returns:
     * {String} A internationalized string.
     */
    translate: function(key) {
        var dictionary = Tian.Lang[Tian.Lang.getCode()];
        var message = dictionary && dictionary[key];
        if(!message) {
            // Message not found, fall back to message key
            message = key;
        }
        return message;
    },
    
{'fraction_non_alphanumeric': 0.15272927770630398, 'fraction_numerical': 0.004594743613306377, 'mean_word_length': 1.6226506024096385, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2789290', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1508, 'n_words': 447}