1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef OHOS_GLOBAL_I18N_PREFERRED_LANGUAGE_H 16 #define OHOS_GLOBAL_I18N_PREFERRED_LANGUAGE_H 17 18 #include <set> 19 #include <string> 20 #include <vector> 21 22 namespace OHOS { 23 namespace Global { 24 namespace I18n { 25 class PreferredLanguage { 26 public: 27 static bool AddPreferredLanguage(const std::string& language, int index); 28 static bool RemovePreferredLanguage(int index); 29 static std::vector<std::string> GetPreferredLanguageList(); 30 static std::string GetFirstPreferredLanguage(); 31 static std::string GetPreferredLocale(); 32 33 private: 34 static bool AddPreferredLanguageNonExist(std::vector<std::string> &preferredLangList, int index, 35 const std::string& language); 36 static bool AddPreferredLanguageExist(std::vector<std::string> &preferredLangList, int languageIdx, int index, 37 const std::string& language); 38 static bool IsMatched(const std::string& preferred, const std::string& resource); 39 static bool IsValidLanguage(const std::string &language); 40 static bool IsValidTag(const std::string &tag); 41 static void Split(const std::string &src, const std::string &sep, std::vector<std::string> &dest); 42 static const char *RESOURCE_PATH_HEAD; 43 static const char *RESOURCE_PATH_TAILOR; 44 static const char *RESOURCE_PATH_SPLITOR; 45 static const char *PREFERRED_LANGUAGES; 46 static constexpr int CONFIG_LEN = 128; 47 static constexpr uint32_t LANGUAGE_LEN = 2; 48 }; 49 } // namespace I18n 50 } // namespace Global 51 } // namespace OHOS 52 #endif