"use strict";
// -*- mode: typescript; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of Genie
//
// Copyright 2019-2020 The Board of Trustees of the Leland Stanford Junior University
//
// 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.
//
// Author: Giovanni Campagna <gcampagn@cs.stanford.edu>
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.get = exports.BaseTokenizer = void 0;
const default_1 = __importDefault(require("./default"));
const english_1 = __importDefault(require("./english"));
const italian_1 = __importDefault(require("./italian"));
const persian_1 = __importDefault(require("./persian"));
const arabic_1 = __importDefault(require("./arabic"));
const german_1 = __importDefault(require("./german"));
const japanese_1 = __importDefault(require("./japanese"));
const turkish_1 = __importDefault(require("./turkish"));
const tagalog_1 = __importDefault(require("./tagalog"));
const spanish_1 = __importDefault(require("./spanish"));
const finnish_1 = __importDefault(require("./finnish"));
const polish_1 = __importDefault(require("./polish"));
const simplified_chinese_1 = __importDefault(require("./simplified-chinese"));
const traditional_chinese_1 = __importDefault(require("./traditional-chinese"));
const base_1 = __importDefault(require("./tokenizer/base"));
exports.BaseTokenizer = base_1.default;
const _classes = {
    'en': english_1.default,
    'it': italian_1.default,
    'fa': persian_1.default,
    'ar': arabic_1.default,
    'de': german_1.default,
    'ja': japanese_1.default,
    'tr': turkish_1.default,
    'tl': tagalog_1.default,
    'es': spanish_1.default,
    'fi': finnish_1.default,
    'pl': polish_1.default,
    // accept both BCP47 forms (either with Script code or with Country code)
    // default to simplified chinese
    'zh': simplified_chinese_1.default,
    'zh-cn': simplified_chinese_1.default,
    'zh-hans': simplified_chinese_1.default,
    'zh-tw': traditional_chinese_1.default,
    'zh-hant': traditional_chinese_1.default,
};
const _instances = new Map();
function get(locale) {
    locale = locale.toLowerCase();
    if (_instances.has(locale))
        return _instances.get(locale);
    const chunks = locale.split('-');
    for (let i = chunks.length; i >= 1; i--) {
        const candidate = chunks.slice(0, i).join('-');
        if (candidate in _classes) {
            const instance = new (_classes[candidate])(locale);
            _instances.set(locale, instance);
            return instance;
        }
    }
    console.error(`Locale ${locale} is not fully supported.`);
    const instance = new default_1.default(locale);
    _instances.set(locale, instance);
    return instance;
}
exports.get = get;
//# sourceMappingURL=index.js.map