<commit_before>import { EventHandler } from '../core/event-handler.js';

import { Asset } from '../asset/asset.js';

import { I18nParser } from './i18n-parser.js';

// Maps locale to function that returns the plural index
// based on the CLDR rules. See here for reference
// https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
// and http://unicode.org/reports/tr35/tr35-numbers.html#Operands .
// An initial set of locales is supported and we can keep adding more as we go.
var PLURALS = {};

// Helper function to define the plural function for an array of locales
var definePluralFn = function (locales, fn) {
    for (var i = 0, len = locales.length; i < len; i++) {
        PLURALS[locales[i]] = fn;
    }
};

// Gets the language portion form a locale
var getLang = function (locale) {
    var idx = locale.indexOf('-');
    if (idx !== -1) {
        return locale.substring(0, idx);
    }

    return locale;
};

// Replaces the language in the specified locale and returns the result
var replaceLang = function (locale, desiredLang) {
    var idx = locale.indexOf('-');
    if (idx !== -1) {
        return desiredLang + locale.substring(idx);
    }

    return desiredLang;
};

var DEFAULT_LOCALE = 'en-US';

// default locale fallbacks if a specific locale
// was not found. E.g. if the desired locale is en-AS but we
// have en-US and en-GB then pick en-US. If a fallback does not exist either
// then pick the first that satisfies the language.
var DEFAULT_LOCALE_FALLBACKS = {
    'en': 'en-US',
    'es': 'en-ES',
    'zh': 'zh-CN',
    'zh-HK': 'zh-TW',
    'zh-TW': 'zh-HK',
    'fr': 'fr-FR',
    'de': 'de-DE',
    'it': 'it-IT',
    'ru': 'ru-RU',
    'ja': 'ja-JP'
};

// Only OTHER
definePluralFn([
    'ja',
    'ko',
    'th',
    'vi',
    'zh',
    'id'
], function (n) {
    return 0;
});
<commit_msg>Add fallback zh-MO to zh-HK (#2189)<commit_after>import { EventHandler } from '../core/event-handler.js';

import { Asset } from '../asset/asset.js';

import { I18nParser } from './i18n-parser.js';

// Maps locale to function that returns the plural index
// based on the CLDR rules. See here for reference
// https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
// and http://unicode.org/reports/tr35/tr35-numbers.html#Operands .
// An initial set of locales is supported and we can keep adding more as we go.
var PLURALS = {};

// Helper function to define the plural function for an array of locales
var definePluralFn = function (locales, fn) {
    for (var i = 0, len = locales.length; i < len; i++) {
        PLURALS[locales[i]] = fn;
    }
};

// Gets the language portion form a locale
var getLang = function (locale) {
    var idx = locale.indexOf('-');
    if (idx !== -1) {
        return locale.substring(0, idx);
    }

    return locale;
};

// Replaces the language in the specified locale and returns the result
var replaceLang = function (locale, desiredLang) {
    var idx = locale.indexOf('-');
    if (idx !== -1) {
        return desiredLang + locale.substring(idx);
    }

    return desiredLang;
};

var DEFAULT_LOCALE = 'en-US';

// default locale fallbacks if a specific locale
// was not found. E.g. if the desired locale is en-AS but we
// have en-US and en-GB then pick en-US. If a fallback does not exist either
// then pick the first that satisfies the language.
var DEFAULT_LOCALE_FALLBACKS = {
    'en': 'en-US',
    'es': 'en-ES',
    'zh': 'zh-CN',
    'zh-HK': 'zh-TW',
    'zh-TW': 'zh-HK',
    'zh-MO': 'zh-HK',
    'fr': 'fr-FR',
    'de': 'de-DE',
    'it': 'it-IT',
    'ru': 'ru-RU',
    'ja': 'ja-JP'
};

// Only OTHER
definePluralFn([
    'ja',
    'ko',
    'th',
    'vi',
    'zh',
    'id'
], function (n) {
    return 0;
});

{'fraction_non_alphanumeric': 0.15603402445507708, 'fraction_numerical': 0.007974481658692184, 'mean_word_length': 2.7331349206349205, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4845853', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1272, 'n_words': 421}