Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Global I18n Standard
提交
e81c711c
G
Global I18n Standard
项目概览
OpenHarmony
/
Global I18n Standard
大约 1 年 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Global I18n Standard
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e81c711c
编写于
9月 18, 2021
作者:
O
openharmony_ci
提交者:
Gitee
9月 18, 2021
浏览文件
操作
浏览文件
下载
差异文件
!64 fix locale_config isSuggested bug and update supporte_locale.xml
Merge pull request !64 from c大神群里的小喽啰/OpenHarmony-3.0-LTS
上级
9b20f71a
1c9e78f5
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
675 addition
and
488 deletion
+675
-488
frameworks/intl/include/locale_config.h
frameworks/intl/include/locale_config.h
+11
-4
frameworks/intl/src/locale_config.cpp
frameworks/intl/src/locale_config.cpp
+137
-69
frameworks/intl/src/supported_locales.xml
frameworks/intl/src/supported_locales.xml
+527
-415
未找到文件。
frameworks/intl/include/locale_config.h
浏览文件 @
e81c711c
...
...
@@ -60,19 +60,26 @@ private:
static
constexpr
int
CONFIG_LEN
=
128
;
static
const
char
*
SUPPORTED_LOCALES_NAME
;
static
const
char
*
SUPPORTED_REGIONS_NAME
;
static
const
char
*
WHITE_LANGUAGE_NAME
;
static
const
char
*
WHILTE_LANGUAGES_PATH
;
static
const
char
*
WHITE_LANGUAGES_NAME
;
static
const
char
*
WHITE_LANGUAGES_PATH
;
static
const
char
*
FORBIDDEN_REGIONS_PATH
;
static
const
char
*
FORBIDDEN_REGIONS_NAME
;
static
const
char
*
FORBIDDEN_LANGUAGES_PATH
;
static
const
char
*
FORBIDDEN_LANGUAGES_NAME
;
static
const
std
::
unordered_set
<
std
::
string
>&
GetSupportedLocales
();
static
const
std
::
unordered_set
<
std
::
string
>&
GetForbiddenRegions
();
static
const
std
::
unordered_set
<
std
::
string
>&
GetSupportedRegions
();
static
void
GetCountriesFromSim
(
std
::
vector
<
std
::
string
>
&
simCountries
);
static
void
GetRelatedLocales
(
std
::
unordered_set
<
std
::
string
>
&
relatedLocales
);
static
void
GetRelatedLocales
(
std
::
unordered_set
<
std
::
string
>
&
relatedLocales
,
const
std
::
vector
<
std
::
string
>
countries
);
static
std
::
string
GetRegionChangeLocale
(
const
std
::
string
&
languageTag
,
const
std
::
string
&
region
);
static
void
GetListFromFile
(
const
char
*
path
,
const
char
*
resourceName
,
std
::
unordered_set
<
std
::
string
>
&
ret
);
static
void
Expunge
(
std
::
unordered_set
<
std
::
string
>
&
src
,
const
std
::
unordered_set
<
std
::
string
>
&
another
);
static
std
::
string
GetMainLanguage
(
const
std
::
string
&
language
);
static
std
::
unordered_set
<
std
::
string
>
supportedLocales
;
static
std
::
unordered_set
<
std
::
string
>
forbiddenRegions
;
static
std
::
unordered_set
<
std
::
string
>
supportedRegions
;
static
std
::
unordered_set
<
std
::
string
>
whiteLanguages
;
static
std
::
unordered_map
<
std
::
string
,
std
::
string
>
dialectMap
;
static
bool
listsInitialized
;
static
bool
InitializeLists
();
};
...
...
frameworks/intl/src/locale_config.cpp
浏览文件 @
e81c711c
...
...
@@ -16,7 +16,6 @@
#include <memory.h>
#include <unordered_set>
#include "locale_config.h"
#include "core_manager.h"
#include "libxml/parser.h"
#include "locale_info.h"
#include "localebuilder.h"
...
...
@@ -40,14 +39,43 @@ const char *LocaleConfig::DEFAULT_LANGUAGE = "zh-Hans";
const
char
*
LocaleConfig
::
DEFAULT_REGION
=
"CN"
;
const
char
*
LocaleConfig
::
SUPPORTED_LOCALES_NAME
=
"supported_locales"
;
const
char
*
LocaleConfig
::
SUPPORTED_REGIONS_NAME
=
"supported_regions"
;
const
char
*
LocaleConfig
::
WHITE_LANGUAGE_NAME
=
"white_language"
;
const
char
*
LocaleConfig
::
WHITE_LANGUAGES_NAME
=
"white_languages"
;
const
char
*
LocaleConfig
::
FORBIDDEN_LANGUAGES_NAME
=
"forbidden_languages"
;
const
char
*
LocaleConfig
::
FORBIDDEN_REGIONS_NAME
=
"forbidden_regions"
;
const
char
*
LocaleConfig
::
FORBIDDEN_LANGUAGES_PATH
=
"/system/usr/ohos_locale_config/forbidden_languages.xml"
;
const
char
*
LocaleConfig
::
FORBIDDEN_REGIONS_PATH
=
"/system/usr/ohos_locale_config/forbidden_regions.xml"
;
const
char
*
LocaleConfig
::
SUPPORTED_LOCALES_PATH
=
"/system/usr/ohos_locale_config/supported_locales.xml"
;
const
char
*
LocaleConfig
::
SUPPORTED_REGIONS_PATH
=
"/system/usr/ohos_locale_config/supported_regions.xml"
;
const
char
*
LocaleConfig
::
WHILTE_LANGUAGES_PATH
=
"/system/usr/ohos_locale_config/white_languages.xml"
;
unordered_set
<
string
>
LocaleConfig
::
forbiddenRegions
;
const
char
*
LocaleConfig
::
WHITE_LANGUAGES_PATH
=
"/system/usr/ohos_locale_config/white_languages.xml"
;
unordered_set
<
string
>
LocaleConfig
::
supportedLocales
;
unordered_set
<
string
>
LocaleConfig
::
supportedRegions
;
unordered_set
<
string
>
LocaleConfig
::
whiteLanguages
;
unordered_map
<
string
,
string
>
LocaleConfig
::
dialectMap
{
{
"es-Latn-419"
,
"es-Latn-419"
},
{
"es-Latn-BO"
,
"es-Latn-419"
},
{
"es-Latn-BR"
,
"es-Latn-419"
},
{
"es-Latn-BZ"
,
"es-Latn-419"
},
{
"es-Latn-CL"
,
"es-Latn-419"
},
{
"es-Latn-CO"
,
"es-Latn-419"
},
{
"es-Latn-CR"
,
"es-Latn-419"
},
{
"es-Latn-CU"
,
"es-Latn-419"
},
{
"es-Latn-DO"
,
"es-Latn-419"
},
{
"es-Latn-EC"
,
"es-Latn-419"
},
{
"es-Latn-GT"
,
"es-Latn-419"
},
{
"es-Latn-HN"
,
"es-Latn-419"
},
{
"es-Latn-MX"
,
"es-Latn-419"
},
{
"es-Latn-NI"
,
"es-Latn-419"
},
{
"es-Latn-PA"
,
"es-Latn-419"
},
{
"es-Latn-PE"
,
"es-Latn-419"
},
{
"es-Latn-PR"
,
"es-Latn-419"
},
{
"es-Latn-PY"
,
"es-Latn-419"
},
{
"es-Latn-SV"
,
"es-Latn-419"
},
{
"es-Latn-US"
,
"es-Latn-419"
},
{
"es-Latn-UY"
,
"es-Latn-419"
},
{
"es-Latn-VE"
,
"es-Latn-419"
},
{
"pt-Latn-PT"
,
"pt-Latn-PT"
},
{
"en-Latn-US"
,
"en-Latn-US"
}
};
bool
LocaleConfig
::
listsInitialized
=
LocaleConfig
::
InitializeLists
();
...
...
@@ -88,7 +116,7 @@ string LocaleConfig::GetSystemLocale()
bool
LocaleConfig
::
SetSystemLanguage
(
const
string
&
language
)
{
if
(
(
language
!=
""
)
&&
!
IsValidTag
(
language
))
{
if
(
!
IsValidTag
(
language
))
{
return
false
;
}
return
SetParameter
(
LANGUAGE_KEY
,
language
.
data
())
==
0
;
...
...
@@ -96,14 +124,15 @@ bool LocaleConfig::SetSystemLanguage(const string &language)
bool
LocaleConfig
::
SetSystemRegion
(
const
string
&
region
)
{
if
(
(
region
!=
""
)
&&
!
IsValidRegion
(
region
))
{
if
(
!
IsValidRegion
(
region
))
{
return
false
;
}
char
value
[
CONFIG_LEN
];
int
code
=
GetParameter
(
LOCALE_KEY
,
""
,
value
,
CONFIG_LEN
);
string
newLocale
;
if
(
code
>
0
)
{
newLocale
=
GetRegionChangeLocale
(
value
,
region
);
string
tag
(
value
,
code
);
newLocale
=
GetRegionChangeLocale
(
tag
,
region
);
if
(
newLocale
==
""
)
{
return
false
;
}
...
...
@@ -124,7 +153,7 @@ bool LocaleConfig::SetSystemRegion(const string ®ion)
bool
LocaleConfig
::
SetSystemLocale
(
const
string
&
locale
)
{
if
(
(
locale
!=
""
)
&&
!
IsValidTag
(
locale
))
{
if
(
!
IsValidTag
(
locale
))
{
return
false
;
}
return
SetParameter
(
LOCALE_KEY
,
locale
.
data
())
==
0
;
...
...
@@ -198,13 +227,11 @@ void LocaleConfig::Split(const string &src, const string &sep, vector<string> &d
}
}
// language in white languages should have script.
void
LocaleConfig
::
GetSystemLanguages
(
vector
<
string
>
&
ret
)
{
const
unordered_set
<
string
>
&
supported
=
GetSupportedLocales
();
for
(
auto
item
:
supported
)
{
if
(
supported
.
find
(
item
)
!=
supported
.
end
())
{
ret
.
push_back
(
item
);
}
for
(
auto
item
:
whiteLanguages
)
{
ret
.
push_back
(
item
);
}
}
...
...
@@ -228,49 +255,62 @@ void LocaleConfig::GetSystemCountries(vector<string> &ret)
bool
LocaleConfig
::
IsSuggested
(
const
string
&
language
)
{
unordered_set
<
string
>
relatedLocales
;
GetRelatedLocales
(
relatedLocales
);
return
relatedLocales
.
find
(
language
)
!=
relatedLocales
.
end
();
vector
<
string
>
simCountries
;
GetCountriesFromSim
(
simCountries
);
GetRelatedLocales
(
relatedLocales
,
simCountries
);
for
(
auto
iter
=
relatedLocales
.
begin
();
iter
!=
relatedLocales
.
end
();)
{
if
(
whiteLanguages
.
find
(
*
iter
)
==
whiteLanguages
.
end
())
{
iter
=
relatedLocales
.
erase
(
iter
);
}
else
{
++
iter
;
}
}
string
mainLanguage
=
GetMainLanguage
(
language
);
return
relatedLocales
.
find
(
mainLanguage
)
!=
relatedLocales
.
end
();
}
bool
LocaleConfig
::
IsSuggested
(
const
std
::
string
&
language
,
const
std
::
string
&
region
)
{
unordered_set
<
string
>
relatedLocales
;
GetRelatedLocales
(
relatedLocales
);
if
(
relatedLocales
.
find
(
language
)
==
relatedLocales
.
end
())
{
return
false
;
vector
<
string
>
countries
{
region
};
GetRelatedLocales
(
relatedLocales
,
countries
);
for
(
auto
iter
=
relatedLocales
.
begin
();
iter
!=
relatedLocales
.
end
();)
{
if
(
whiteLanguages
.
find
(
*
iter
)
==
whiteLanguages
.
end
())
{
iter
=
relatedLocales
.
erase
(
iter
);
}
else
{
++
iter
;
}
}
string
temp
=
GetRegionChangeLocale
(
language
,
region
);
return
relatedLocales
.
find
(
temp
)
!=
relatedLocales
.
end
();
string
mainLanguage
=
GetMainLanguage
(
language
);
return
relatedLocales
.
find
(
mainLanguage
)
!=
relatedLocales
.
end
();
}
void
LocaleConfig
::
GetRelatedLocales
(
unordered_set
<
string
>
&
relatedLocales
)
void
LocaleConfig
::
GetRelatedLocales
(
unordered_set
<
string
>
&
relatedLocales
,
vector
<
string
>
countries
)
{
vector
<
string
>
simCountries
;
GetCountriesFromSim
(
simCountries
);
// remove unsupported countries
const
unordered_set
<
string
>
&
regions
=
GetSupportedRegions
();
for
(
auto
iter
=
simCountries
.
begin
();
iter
!=
simC
ountries
.
end
();)
{
for
(
auto
iter
=
countries
.
begin
();
iter
!=
c
ountries
.
end
();)
{
if
(
regions
.
find
(
*
iter
)
==
regions
.
end
())
{
iter
=
simC
ountries
.
erase
(
iter
);
iter
=
c
ountries
.
erase
(
iter
);
}
else
{
++
iter
;
}
}
const
unordered_set
<
string
>
&
locales
=
GetSupportedLocales
();
for
(
auto
item
:
locales
)
{
if
(
whiteLanguages
.
find
(
item
)
==
whiteLanguages
.
end
())
{
continue
;
}
UErrorCode
status
=
U_ZERO_ERROR
;
icu
::
Locale
locale
=
icu
::
Locale
::
forLanguageTag
(
item
,
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
continue
;
for
(
string
locale
:
locales
)
{
bool
find
=
false
;
for
(
string
country
:
countries
)
{
if
(
locale
.
find
(
country
)
!=
string
::
npos
)
{
find
=
true
;
break
;
}
}
const
char
*
region
=
locale
.
getCountry
();
if
(
region
==
nullptr
)
{
if
(
!
find
)
{
continue
;
}
if
(
find
(
simCountries
.
begin
(),
simCountries
.
end
(),
region
)
!=
simCountries
.
end
())
{
relatedLocales
.
insert
(
item
);
string
mainLanguage
=
GetMainLanguage
(
locale
);
if
(
mainLanguage
!=
""
)
{
relatedLocales
.
insert
(
mainLanguage
);
}
}
}
...
...
@@ -295,58 +335,54 @@ void LocaleConfig::GetListFromFile(const char *path, const char *resourceName, u
}
xmlNodePtr
cur
=
xmlDocGetRootElement
(
doc
);
if
(
cur
==
nullptr
||
(
xmlStrcmp
(
cur
->
name
,
reinterpret_cast
<
const
xmlChar
*>
(
resourceName
)))
!=
0
)
{
xmlFreeDoc
(
doc
);
return
;
}
cur
=
cur
->
xmlChildrenNode
;
xmlChar
*
content
;
xmlChar
*
content
=
nullptr
;
while
(
cur
!=
nullptr
)
{
content
=
xmlNodeGetContent
(
cur
);
ret
.
insert
(
reinterpret_cast
<
const
char
*>
(
content
));
xmlFree
(
content
);
cur
=
cur
->
next
;
if
(
content
!=
nullptr
)
{
ret
.
insert
(
reinterpret_cast
<
const
char
*>
(
content
));
xmlFree
(
content
);
cur
=
cur
->
next
;
}
else
{
break
;
}
}
xmlFreeDoc
(
doc
);
}
const
unordered_set
<
string
>&
LocaleConfig
::
GetForbiddenRegions
(
)
void
LocaleConfig
::
Expunge
(
unordered_set
<
string
>
&
src
,
const
unordered_set
<
string
>
&
another
)
{
return
forbiddenRegions
;
for
(
auto
iter
=
src
.
begin
();
iter
!=
src
.
end
();)
{
if
(
another
.
find
(
*
iter
)
!=
another
.
end
())
{
iter
=
src
.
erase
(
iter
);
}
else
{
++
iter
;
}
}
}
bool
LocaleConfig
::
InitializeLists
()
{
SetHwIcuDirectory
();
GetListFromFile
(
SUPPORTED_LOCALES_PATH
,
SUPPORTED_LOCALES_NAME
,
supportedLocales
);
for
(
auto
iter
=
supportedLocales
.
begin
();
iter
!=
supportedLocales
.
end
();)
{
bool
find
=
false
;
for
(
auto
item
:
forbiddenRegions
)
{
if
(
iter
->
find
(
item
))
{
find
=
true
;
break
;
}
}
if
(
find
)
{
iter
=
supportedLocales
.
erase
(
iter
);
}
else
{
++
iter
;
}
}
GetListFromFile
(
SUPPORTED_REGIONS_PATH
,
SUPPORTED_REGIONS_NAME
,
supportedRegions
);
for
(
auto
iter
=
supportedRegions
.
begin
();
iter
!=
supportedRegions
.
end
();)
{
if
(
forbiddenRegions
.
find
(
*
iter
)
!=
forbiddenRegions
.
end
())
{
iter
=
supportedRegions
.
erase
(
iter
);
}
else
{
++
iter
;
}
}
GetListFromFile
(
WHILTE_LANGUAGES_PATH
,
WHITE_LANGUAGE_NAME
,
whiteLanguag
es
);
unordered_set
<
string
>
forbiddenRegions
;
GetListFromFile
(
FORBIDDEN_REGIONS_PATH
,
FORBIDDEN_REGIONS_NAME
,
forbiddenRegions
);
Expunge
(
supportedRegions
,
forbiddenRegions
);
GetListFromFile
(
WHITE_LANGUAGES_PATH
,
WHITE_LANGUAGES_NAME
,
whiteLanguages
);
unordered_set
<
string
>
forbiddenLanguages
;
GetListFromFile
(
FORBIDDEN_LANGUAGES_PATH
,
FORBIDDEN_LANGUAGES_NAME
,
forbiddenLanguages
);
Expunge
(
whiteLanguages
,
forbiddenLanguages
);
GetListFromFile
(
SUPPORTED_LOCALES_PATH
,
SUPPORTED_LOCALES_NAME
,
supportedLocal
es
);
return
true
;
}
string
LocaleConfig
::
GetRegionChangeLocale
(
const
string
&
languageTag
,
const
string
&
region
)
{
UErrorCode
status
=
U_ZERO_ERROR
;
icu
::
Locale
origin
=
icu
::
Locale
::
forLanguageTag
(
languageTag
,
status
);
const
icu
::
Locale
origin
=
icu
::
Locale
::
forLanguageTag
(
languageTag
,
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
return
""
;
}
...
...
@@ -360,10 +396,41 @@ string LocaleConfig::GetRegionChangeLocale(const string &languageTag, const stri
return
(
status
!=
U_ZERO_ERROR
)
?
""
:
ret
;
}
string
LocaleConfig
::
GetMainLanguage
(
const
string
&
language
)
{
UErrorCode
status
=
U_ZERO_ERROR
;
icu
::
Locale
origin
=
icu
::
Locale
::
forLanguageTag
(
language
,
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
return
""
;
}
origin
.
addLikelySubtags
(
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
return
""
;
}
icu
::
LocaleBuilder
builder
=
icu
::
LocaleBuilder
().
setLanguage
(
origin
.
getLanguage
()).
setScript
(
origin
.
getScript
()).
setRegion
(
origin
.
getCountry
());
icu
::
Locale
temp
=
builder
.
setExtension
(
'u'
,
""
).
build
(
status
);
string
fullLanguage
=
temp
.
toLanguageTag
<
string
>
(
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
return
""
;
}
if
(
dialectMap
.
find
(
fullLanguage
)
!=
dialectMap
.
end
())
{
return
dialectMap
[
fullLanguage
];
}
builder
.
setRegion
(
""
);
temp
=
builder
.
build
(
status
);
fullLanguage
=
temp
.
toLanguageTag
<
string
>
(
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
return
""
;
}
return
fullLanguage
;
}
string
LocaleConfig
::
GetDisplayLanguage
(
const
string
&
language
,
const
string
&
displayLocale
,
bool
sentenceCase
)
{
UErrorCode
status
=
U_ZERO_ERROR
;
const
icu
::
Locale
originLocale
=
icu
::
Locale
::
forLanguageTag
(
language
,
status
);
icu
::
Locale
originLocale
=
icu
::
Locale
::
forLanguageTag
(
language
,
status
);
originLocale
.
addLikelySubtags
(
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
return
""
;
}
...
...
@@ -385,7 +452,8 @@ string LocaleConfig::GetDisplayLanguage(const string &language, const string &di
string
LocaleConfig
::
GetDisplayRegion
(
const
string
&
region
,
const
string
&
displayLocale
,
bool
sentenceCase
)
{
UErrorCode
status
=
U_ZERO_ERROR
;
const
icu
::
Locale
originLocale
=
icu
::
Locale
::
forLanguageTag
(
region
,
status
);
icu
::
LocaleBuilder
builder
=
icu
::
LocaleBuilder
().
setRegion
(
region
);
icu
::
Locale
originLocale
=
builder
.
build
(
status
);
if
(
status
!=
U_ZERO_ERROR
)
{
return
""
;
}
...
...
frameworks/intl/src/supported_locales.xml
浏览文件 @
e81c711c
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录