19596a2c1Sopenharmony_ci/* 29596a2c1Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 39596a2c1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 49596a2c1Sopenharmony_ci * you may not use this file except in compliance with the License. 59596a2c1Sopenharmony_ci * You may obtain a copy of the License at 69596a2c1Sopenharmony_ci * 79596a2c1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 89596a2c1Sopenharmony_ci * 99596a2c1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 109596a2c1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 119596a2c1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129596a2c1Sopenharmony_ci * See the License for the specific language governing permissions and 139596a2c1Sopenharmony_ci * limitations under the License. 149596a2c1Sopenharmony_ci */ 159596a2c1Sopenharmony_ci 169596a2c1Sopenharmony_ci#ifndef OHOS_GLOBAL_I18N_TABOO_H 179596a2c1Sopenharmony_ci#define OHOS_GLOBAL_I18N_TABOO_H 189596a2c1Sopenharmony_ci 199596a2c1Sopenharmony_ci#include <map> 209596a2c1Sopenharmony_ci#include <set> 219596a2c1Sopenharmony_ci#include <string> 229596a2c1Sopenharmony_ci#include <vector> 239596a2c1Sopenharmony_ci#include <mutex> 249596a2c1Sopenharmony_ci 259596a2c1Sopenharmony_cinamespace OHOS { 269596a2c1Sopenharmony_cinamespace Global { 279596a2c1Sopenharmony_cinamespace I18n { 289596a2c1Sopenharmony_cienum DataFileType { 299596a2c1Sopenharmony_ci CONFIG_FILE, 309596a2c1Sopenharmony_ci DATA_FILE 319596a2c1Sopenharmony_ci}; 329596a2c1Sopenharmony_ci 339596a2c1Sopenharmony_ciclass Taboo { 349596a2c1Sopenharmony_cipublic: 359596a2c1Sopenharmony_ci Taboo(); 369596a2c1Sopenharmony_ci Taboo(const std::string& path); 379596a2c1Sopenharmony_ci ~Taboo(); 389596a2c1Sopenharmony_ci std::string ReplaceCountryName(const std::string& region, const std::string& displayLanguage, 399596a2c1Sopenharmony_ci const std::string& name); 409596a2c1Sopenharmony_ci std::string ReplaceLanguageName(const std::string& language, const std::string& displayLanguage, 419596a2c1Sopenharmony_ci const std::string& name); 429596a2c1Sopenharmony_ci 439596a2c1Sopenharmony_ciprivate: 449596a2c1Sopenharmony_ci void ParseTabooData(const std::string& path, DataFileType fileType, const std::string& Locale = ""); 459596a2c1Sopenharmony_ci void ProcessTabooConfigData(const std::string& name, const std::string& value); 469596a2c1Sopenharmony_ci void ProcessTabooLocaleData(const std::string& locale, const std::string& name, const std::string& value); 479596a2c1Sopenharmony_ci void SplitValue(const std::string& value, std::set<std::string>& collation); 489596a2c1Sopenharmony_ci std::vector<std::string> QueryKeyFallBack(const std::string& key); 499596a2c1Sopenharmony_ci std::tuple<std::string, std::string> LanguageFallBack(const std::string& language); 509596a2c1Sopenharmony_ci void ReadResourceList(); 519596a2c1Sopenharmony_ci std::string GetLanguageFromFileName(const std::string& fileName); 529596a2c1Sopenharmony_ci 539596a2c1Sopenharmony_ci // Indicates which regions support name replacement using taboo data. 549596a2c1Sopenharmony_ci static std::set<std::string> supportedRegions; 559596a2c1Sopenharmony_ci // Indicates which languages support name replacement using taboo data. 569596a2c1Sopenharmony_ci static std::set<std::string> supportedLanguages; 579596a2c1Sopenharmony_ci // cache the name replacement taboo data of different locale. 589596a2c1Sopenharmony_ci std::map<std::string, std::map<std::string, std::string>> localeTabooData; 599596a2c1Sopenharmony_ci // Indicates which locales are supported to find taboo data. 609596a2c1Sopenharmony_ci static std::map<std::string, std::string> RESOURCES; 619596a2c1Sopenharmony_ci 629596a2c1Sopenharmony_ci std::string tabooDataPath = ""; 639596a2c1Sopenharmony_ci std::string tabooConfigFileName = "taboo-config.xml"; 649596a2c1Sopenharmony_ci std::string tabooLocaleDataFileName = "taboo-data.xml"; 659596a2c1Sopenharmony_ci std::string filePathSplitor = "/"; 669596a2c1Sopenharmony_ci std::string supportedRegionsTag = "regions"; // supported regions key in taboo-config.xml 679596a2c1Sopenharmony_ci std::string supportedLanguagesTag = "languages"; // supported languages key in taboo-config.xml 689596a2c1Sopenharmony_ci std::string regionKey = "region_"; // start part of region name replacement data key. 699596a2c1Sopenharmony_ci std::string languageKey = "language_"; // start part of language name replacement data key. 709596a2c1Sopenharmony_ci bool isTabooDataExist = false; 719596a2c1Sopenharmony_ci static std::mutex TABOO_MUTEX; 729596a2c1Sopenharmony_ci 739596a2c1Sopenharmony_ci static const char* ROOT_TAG; 749596a2c1Sopenharmony_ci static const char* ITEM_TAG; 759596a2c1Sopenharmony_ci static const char* NAME_TAG; 769596a2c1Sopenharmony_ci static const char* VALUE_TAG; 779596a2c1Sopenharmony_ci char tabooDataSplitor = ','; 789596a2c1Sopenharmony_ci}; 799596a2c1Sopenharmony_ci} // namespace I18n 809596a2c1Sopenharmony_ci} // namespace Global 819596a2c1Sopenharmony_ci} // namespace OHOS 829596a2c1Sopenharmony_ci#endif