敏感地区名称修改

Signed-off-by: zhangdd_ewan <zhangdongdong50@huawei.com>
This commit is contained in:
zhangdd_ewan 2024-10-16 20:26:54 +08:00
parent b563500795
commit bac414c20c
6 changed files with 4 additions and 187 deletions

View File

@ -146,7 +146,6 @@ ohos_shared_library("intl_util") {
":i18n.para.dac",
":i18n_param_config_xml",
":lang_supported_locales",
":region_supported_locales_xml",
":root_timezone_xml",
":timezones_xml",
":ug_lang_xml",
@ -344,13 +343,6 @@ ohos_prebuilt_etc("timezones_xml") {
subsystem_name = "global"
}
ohos_prebuilt_etc("region_supported_locales_xml") {
source = "//base/global/i18n/frameworks/intl/etc/region/supported_regions.xml"
module_install_dir = "usr/ohos_locale_config/region/"
part_name = "i18n"
subsystem_name = "global"
}
ohos_prebuilt_etc("zh_Hans_region_xml") {
source = "//base/global/i18n/frameworks/intl/etc/region/zh-Hans.xml"
module_install_dir = "usr/ohos_locale_config/region/"

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
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.
-->
<regions>
<region>
<id>HK</id>
<display_name>Hong Kong (China)</display_name>
</region>
<region>
<id>MO</id>
<display_name>Macao (China)</display_name>
</region>
<region>
<id>TW</id>
<display_name>Taiwan (China)</display_name>
</region>
</regions>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
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.
-->
<supported_regions>
<item>en-Latn-US</item>
<item>zh-Hans</item>
</supported_regions>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 Huawei Device Co., Ltd.
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.
-->
<regions>
<region>
<id>HK</id>
<display_name>中国香港</display_name>
</region>
<region>
<id>MO</id>
<display_name>中国澳门</display_name>
</region>
<region>
<id>TW</id>
<display_name>中国台湾</display_name>
</region>
</regions>

View File

@ -151,9 +151,7 @@ private:
static const char *OVERRIDE_SUPPORTED_REGIONS_PATH;
static const char *DIALECT_LANGS_PATH;
static const char *DIALECT_LANGS_NAME;
static const char *REGION_PATH;
static std::mutex dialectLocaleMutex;
static std::mutex region2DisplayNameMutex;
static std::mutex locale2DisplayNameMutex;
static const std::unordered_set<std::string>& GetSupportedLocales();
@ -174,7 +172,6 @@ private:
static void ReadRegionData(const char *regionDataPath);
static void ProcessForbiddenRegions(const std::unordered_set<std::string> &forbiddenRegions);
static void SetSupportedDialectLocales(const char* key, const char* value);
static void SetRegion2DisplayName(const char* key, const char* value);
static void SetLocale2DisplayName(const char* key, const char* value);
static bool Is24HourLocale(const std::string& systemLocale);
static bool HasDesignator(const std::string& inFormat, const char designator);
@ -262,7 +259,6 @@ private:
static std::unordered_set<std::string> supportedRegions;
static std::unordered_set<std::string> supportLocales;
static std::unordered_set<std::string> dialectLang;
static std::unordered_set<std::string> overrideSupportedRegions;
static std::unordered_set<std::string> blockedLanguages;
static std::unordered_set<std::string> blockedRegions;
static std::unordered_map<std::string, std::unordered_set<std::string>> blockedLanguageRegions;
@ -272,7 +268,6 @@ private:
static std::unordered_map<std::string, std::string> dialectMap;
static std::unordered_map<std::string, std::string> localDigitMap;
static std::map<std::string, std::string> locale2DisplayName;
static std::map<std::string, std::string> region2DisplayName;
static std::string currentDialectLocale;
static std::string currentOverrideRegion;
static std::set<std::string> validCaTag;

View File

@ -69,13 +69,9 @@ const char *LocaleConfig::SUPPORT_LOCALES_PATH = "/etc/ohos_lang_config/supporte
const char *LocaleConfig::SUPPORT_LOCALES_NAME = "supported_locales";
const char *LocaleConfig::DIALECT_LANGS_PATH = "/system/usr/ohos_locale_config/dialect_languages.xml";
const char *LocaleConfig::DIALECT_LANGS_NAME = "dialect_langs";
const char *LocaleConfig::OVERRIDE_SUPPORTED_REGIONS_NAME = "supported_regions";
const char *LocaleConfig::OVERRIDE_SUPPORTED_REGIONS_PATH =
"/system/usr/ohos_locale_config/region/supported_regions.xml";
const char *LocaleConfig::DEFAULT_LOCALE = "en-Latn";
const char *LocaleConfig::supportLocalesTag = "supported_locales";
const char *LocaleConfig::LANG_PATH = "/etc/ohos_lang_config/";
const char *LocaleConfig::REGION_PATH = "/system/usr/ohos_locale_config/region/";
const char *LocaleConfig::rootTag = "languages";
const char *LocaleConfig::secondRootTag = "lang";
const char *LocaleConfig::rootRegion = "regions";
@ -84,7 +80,6 @@ const char *LocaleConfig::NUMBER_SYSTEM_KEY = "-nu-";
unordered_set<string> LocaleConfig::supportedLocales;
unordered_set<string> LocaleConfig::supportLocales;
unordered_set<string> LocaleConfig::supportedRegions;
unordered_set<string> LocaleConfig::overrideSupportedRegions;
unordered_set<string> LocaleConfig::dialectLang;
unordered_set<string> LocaleConfig::blockedLanguages;
unordered_set<string> LocaleConfig::blockedRegions;
@ -131,11 +126,9 @@ unordered_map<string, string> LocaleConfig::localDigitMap {
std::map<std::string, std::string> LocaleConfig::supportedDialectLocales;
std::map<string, string> LocaleConfig::locale2DisplayName {};
std::map<string, string> LocaleConfig::region2DisplayName {};
std::string LocaleConfig::currentDialectLocale = "";
std::string LocaleConfig::currentOverrideRegion = "";
std::mutex LocaleConfig::dialectLocaleMutex;
std::mutex LocaleConfig::region2DisplayNameMutex;
std::mutex LocaleConfig::locale2DisplayNameMutex;
set<std::string> LocaleConfig::validCaTag {
@ -586,7 +579,6 @@ bool LocaleConfig::InitializeLists()
Expunge(whiteLanguages, blockedLanguages);
GetListFromFile(SUPPORTED_LOCALES_PATH, SUPPORTED_LOCALES_NAME, supportedLocales);
GetListFromFile(SUPPORT_LOCALES_PATH, SUPPORT_LOCALES_NAME, supportLocales);
GetListFromFile(OVERRIDE_SUPPORTED_REGIONS_PATH, OVERRIDE_SUPPORTED_REGIONS_NAME, overrideSupportedRegions);
GetListFromFile(DIALECT_LANGS_PATH, DIALECT_LANGS_NAME, dialectLang);
ExtendWhiteLanguages();
return true;
@ -792,13 +784,6 @@ void LocaleConfig::ReadLangData(const char *langDataPath)
xmlFreeDoc(doc);
}
void LocaleConfig::SetRegion2DisplayName(const char* key, const char* value)
{
std::lock_guard<std::mutex> regionDisplayLock(region2DisplayNameMutex);
region2DisplayName.insert(
std::make_pair<std::string, std::string>(key, value));
}
void LocaleConfig::SetLocale2DisplayName(const char* key, const char* value)
{
std::lock_guard<std::mutex> localeDisplayLock(locale2DisplayNameMutex);
@ -806,54 +791,6 @@ void LocaleConfig::SetLocale2DisplayName(const char* key, const char* value)
std::make_pair<std::string, std::string>(key, value));
}
void LocaleConfig::ReadRegionData(const char *regionDataPath)
{
xmlKeepBlanksDefault(0);
if (regionDataPath == nullptr) {
return;
}
xmlDocPtr doc = xmlParseFile(regionDataPath);
if (!doc) {
HILOG_INFO_I18N("can not open region data file");
return;
}
xmlNodePtr cur = xmlDocGetRootElement(doc);
if (cur) {
HILOG_INFO_I18N("cur pointer is true");
}
if (!cur || xmlStrcmp(cur->name, reinterpret_cast<const xmlChar *>(rootRegion))) {
xmlFreeDoc(doc);
HILOG_INFO_I18N("parse region data file failed");
return;
}
cur = cur->xmlChildrenNode;
while (cur != nullptr && !xmlStrcmp(cur->name, reinterpret_cast<const xmlChar *>(secondRootRegion))) {
xmlChar *regionContents[ELEMENT_NUM] = { 0 };
xmlNodePtr regionValue = cur->xmlChildrenNode;
bool xmlNodeNull = false;
for (size_t i = 0; i < ELEMENT_NUM && regionValue != nullptr; i++) {
regionContents[i] = xmlNodeGetContent(regionValue);
regionValue = regionValue->next;
if (regionContents[i] == nullptr) {
xmlNodeNull = true;
}
}
if (!xmlNodeNull) {
// 0 represents langid index, 1 represents displayname index
const char* regionKey = reinterpret_cast<const char *>(regionContents[0]);
const char* regionVal = reinterpret_cast<const char *>(regionContents[1]);
SetRegion2DisplayName(regionKey, regionVal);
}
for (size_t i = 0; i < ELEMENT_NUM; i++) {
if (regionContents[i] != nullptr) {
xmlFree(regionContents[i]);
}
}
cur = cur->next;
}
xmlFreeDoc(doc);
}
string LocaleConfig::GetDisplayLanguageWithDialect(const std::string &localeStr, const std::string &displayLocale)
{
std::string finalLocale = ComputeLocale(displayLocale);
@ -892,37 +829,6 @@ string LocaleConfig::GetDisplayLanguageWithDialect(const std::string &localeStr,
return "";
}
string LocaleConfig::GetDisplayOverrideRegion(const std::string &region, const std::string &displayLocale)
{
UErrorCode status = U_ZERO_ERROR;
icu::Locale originLocale;
icu::UnicodeString displayRegion;
if (displayLocale.compare(currentOverrideRegion) != 0) {
std::string xmlPath = REGION_PATH + displayLocale + ".xml";
region2DisplayName.clear();
ReadRegionData(xmlPath.c_str());
currentOverrideRegion = displayLocale;
}
if (region2DisplayName.find(region) != region2DisplayName.end()) {
return region2DisplayName.at(region);
} else {
icu::Locale locale = icu::Locale::forLanguageTag(displayLocale, status);
if (U_FAILURE(status)) {
return "";
}
if (IsValidRegion(region)) {
icu::LocaleBuilder builder = icu::LocaleBuilder().setRegion(region);
originLocale = builder.build(status);
} else {
originLocale = icu::Locale::forLanguageTag(region, status);
}
originLocale.getDisplayCountry(locale, displayRegion);
std::string result;
displayRegion.toUTF8String(result);
return result;
}
}
string LocaleConfig::GetDisplayRegion(const string &region, const string &displayLocale, bool sentenceCase)
{
UErrorCode status = U_ZERO_ERROR;
@ -947,12 +853,10 @@ string LocaleConfig::GetDisplayRegion(const string &region, const string &displa
icu::UnicodeString unistr;
icu::UnicodeString displayRegion;
std::string result;
if (overrideSupportedRegions.find(displayLocale) != overrideSupportedRegions.end()) {
result = GetDisplayOverrideRegion(region, displayLocale);
} else {
originLocale.getDisplayCountry(locale, displayRegion);
displayRegion.toUTF8String(result);
}
originLocale.getDisplayCountry(locale, displayRegion);
displayRegion.toUTF8String(result);
if (sentenceCase) {
char ch = static_cast<char>(toupper(result[0]));
return PseudoLocalizationProcessor(result.replace(0, 1, 1, ch));