mirror of
https://gitee.com/openharmony/global_i18n
synced 2024-11-27 09:11:40 +00:00
commit
9daccc41a5
@ -115,8 +115,6 @@ private:
|
||||
static const int HOURS_OF_A_DAY = 24;
|
||||
static bool icuInitialized;
|
||||
static bool Init();
|
||||
static std::set<std::string> allValidLocales;
|
||||
static std::set<std::string> GetValidLocales();
|
||||
static std::map<std::string, icu::DateFormat::EStyle> dateTimeStyle;
|
||||
void ParseConfigsPartOne(std::map<std::string, std::string> &configs);
|
||||
void ParseConfigsPartTwo(std::map<std::string, std::string> &configs);
|
||||
|
@ -15,10 +15,11 @@
|
||||
#ifndef OHOS_GLOBAL_I18N_LOCALE_INFO_H
|
||||
#define OHOS_GLOBAL_I18N_LOCALE_INFO_H
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/localebuilder.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include <map>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
@ -45,6 +46,8 @@ public:
|
||||
icu::Locale GetLocaleTag() const;
|
||||
static const uint32_t SCRIPT_LEN = 4;
|
||||
static const uint32_t REGION_LEN = 2;
|
||||
static std::set<std::string> allValidLocales;
|
||||
static std::set<std::string> GetValidLocales();
|
||||
private:
|
||||
std::string language;
|
||||
std::string region;
|
||||
|
@ -98,8 +98,6 @@ private:
|
||||
static std::unordered_map<std::string, UNumberSignDisplay> signAutoStyle;
|
||||
static std::unordered_map<std::string, UNumberSignDisplay> signAccountingStyle;
|
||||
static std::unordered_map<UMeasurementSystem, std::string> measurementSystem;
|
||||
static std::set<std::string> allValidLocales;
|
||||
static std::set<std::string> GetValidLocales();
|
||||
void ParseConfigs(std::map<std::string, std::string> &configs);
|
||||
void ParseDigitsConfigs(std::map<std::string, std::string> &configs);
|
||||
void GetDigitsResolvedOptions(std::map<std::string, std::string> &map);
|
||||
|
@ -65,30 +65,18 @@ void Collator::ParseAllOptions(std::map<std::string, std::string> &options)
|
||||
collation = ParseOption(options, "collation");
|
||||
}
|
||||
|
||||
std::set<std::string> Collator::GetValidLocales()
|
||||
{
|
||||
int32_t validCount = 1;
|
||||
const icu::Locale *validLocaleArray = icu::Locale::getAvailableLocales(validCount);
|
||||
std::set<std::string> allValidLocales;
|
||||
for (int i = 0; i < validCount; i++) {
|
||||
allValidLocales.insert(validLocaleArray[i].getLanguage());
|
||||
}
|
||||
return allValidLocales;
|
||||
}
|
||||
|
||||
Collator::Collator(std::vector<std::string> &localeTags, std::map<std::string, std::string> &options)
|
||||
{
|
||||
ParseAllOptions(options);
|
||||
|
||||
UErrorCode status = UErrorCode::U_ZERO_ERROR;
|
||||
std::set<std::string> allValidLocales = GetValidLocales();
|
||||
if (localeTags.size() == 0) {
|
||||
localeTags.push_back(LocaleConfig::GetSystemLocale());
|
||||
}
|
||||
for (size_t i = 0; i < localeTags.size(); i++) {
|
||||
std::string curLocale = localeTags[i];
|
||||
locale = icu::Locale::forLanguageTag(icu::StringPiece(curLocale), status);
|
||||
if (allValidLocales.count(locale.getLanguage()) > 0) {
|
||||
if (LocaleInfo::allValidLocales.count(locale.getLanguage()) > 0) {
|
||||
localeInfo = new LocaleInfo(curLocale, options);
|
||||
locale = localeInfo->GetLocale();
|
||||
localeStr = localeInfo->GetBaseName();
|
||||
|
@ -25,19 +25,6 @@ using namespace icu;
|
||||
|
||||
bool DateTimeFormat::icuInitialized = DateTimeFormat::Init();
|
||||
|
||||
std::set<std::string> DateTimeFormat::allValidLocales = GetValidLocales();
|
||||
|
||||
std::set<std::string> DateTimeFormat::GetValidLocales()
|
||||
{
|
||||
int32_t validCount = 1;
|
||||
const Locale *validLocales = Locale::getAvailableLocales(validCount);
|
||||
std::set<std::string> allValidLocales;
|
||||
for (int i = 0; i < validCount; i++) {
|
||||
allValidLocales.insert(validLocales[i].getLanguage());
|
||||
}
|
||||
return allValidLocales;
|
||||
}
|
||||
|
||||
std::map<std::string, DateFormat::EStyle> DateTimeFormat::dateTimeStyle = {
|
||||
{ "full", DateFormat::EStyle::kFull },
|
||||
{ "long", DateFormat::EStyle::kLong },
|
||||
@ -51,11 +38,10 @@ DateTimeFormat::DateTimeFormat(const std::vector<std::string> &localeTags, std::
|
||||
auto builder = std::make_unique<LocaleBuilder>();
|
||||
ParseConfigsPartOne(configs);
|
||||
ParseConfigsPartTwo(configs);
|
||||
GetValidLocales();
|
||||
for (size_t i = 0; i < localeTags.size(); i++) {
|
||||
std::string curLocale = localeTags[i];
|
||||
locale = Locale::forLanguageTag(StringPiece(curLocale), status);
|
||||
if (allValidLocales.count(locale.getLanguage()) > 0) {
|
||||
if (LocaleInfo::allValidLocales.count(locale.getLanguage()) > 0) {
|
||||
localeInfo = new LocaleInfo(curLocale, configs);
|
||||
locale = localeInfo->GetLocale();
|
||||
localeTag = localeInfo->GetBaseName();
|
||||
|
@ -22,6 +22,22 @@ namespace Global {
|
||||
namespace I18n {
|
||||
using namespace icu;
|
||||
|
||||
std::set<std::string> LocaleInfo::allValidLocales = GetValidLocales();
|
||||
|
||||
std::set<std::string> LocaleInfo::GetValidLocales()
|
||||
{
|
||||
int32_t validCount = 1;
|
||||
const Locale *validLocales = Locale::getAvailableLocales(validCount);
|
||||
std::set<std::string> allValidLocales;
|
||||
for (int i = 0; i < validCount; i++) {
|
||||
allValidLocales.insert(validLocales[i].getLanguage());
|
||||
}
|
||||
allValidLocales.insert("in");
|
||||
allValidLocales.insert("iw");
|
||||
allValidLocales.insert("tl");
|
||||
return allValidLocales;
|
||||
}
|
||||
|
||||
LocaleInfo::LocaleInfo(std::string localeTag)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
@ -40,11 +40,11 @@ const std::unordered_map<std::string, std::vector<std::string>> USAGE_001 {
|
||||
{ "length-person", { "centimeter" } },
|
||||
{ "length-person-small", { "centimeter" } },
|
||||
{ "length-rainfall", { "millimeter" } },
|
||||
{ "length-road", { "kilometer" } },
|
||||
{ "length-road", { "meter" } },
|
||||
{ "length-road-small", { "meter" } },
|
||||
{ "length-snowfall", { "centimeter" } },
|
||||
{ "length-vehicle", { "meter" } },
|
||||
{ "length-visiblty", { "kilometer" } },
|
||||
{ "length-visiblty", { "meter" } },
|
||||
{ "length-visiblty-small", { "meter" } },
|
||||
{ "speed-road-travel", { "kilometer-per-hour" } },
|
||||
{ "speed-wind", { "kilometer-per-hour" } },
|
||||
@ -75,6 +75,7 @@ const std::unordered_map<std::string, std::vector<std::string>> USAGE_BS {
|
||||
};
|
||||
|
||||
const std::unordered_map<std::string, std::vector<std::string>> USAGE_CA {
|
||||
{ "length-person", { "inch" } },
|
||||
{ "length-person-informal", { "foot", "inch" } },
|
||||
{ "length-person-small-informal", { "inch" } },
|
||||
};
|
||||
@ -92,12 +93,13 @@ const std::unordered_map<std::string, std::vector<std::string>> USAGE_GB {
|
||||
{ "area-land-agricult", { "acre" } },
|
||||
{ "area-land-commercl", { "acre" } },
|
||||
{ "area-land-residntl", { "acre" } },
|
||||
{ "length-person", { "inch" } },
|
||||
{ "length-person-informal", { "foot", "inch" } },
|
||||
{ "length-person-small-informal", { "inch" } },
|
||||
{ "length-road", { "mile" } },
|
||||
{ "length-road", { "yard" } },
|
||||
{ "length-road-small", { "yard" } },
|
||||
{ "length-vehicle", { "foot", "inch" } },
|
||||
{ "length-visiblty", { "mile" } },
|
||||
{ "length-visiblty", { "mile", "foot" } },
|
||||
{ "length-visiblty-small", { "foot" } },
|
||||
{ "speed-road-travel", { "mile-per-hour" } },
|
||||
};
|
||||
@ -120,7 +122,7 @@ const std::unordered_map<std::string, std::vector<std::string>> USAGE_MX {
|
||||
|
||||
const std::unordered_map<std::string, std::vector<std::string>> USAGE_NL {
|
||||
{ "length-person-informal", { "meter", "centimeter" } },
|
||||
{ "length-visiblty", { "meter", "centimeter" } },
|
||||
{ "length-visiblty", { "meter" } },
|
||||
};
|
||||
|
||||
const std::unordered_map<std::string, std::vector<std::string>> USAGE_NO {
|
||||
@ -130,6 +132,7 @@ const std::unordered_map<std::string, std::vector<std::string>> USAGE_NO {
|
||||
|
||||
const std::unordered_map<std::string, std::vector<std::string>> USAGE_SE {
|
||||
{ "length-person", { "meter", "centimeter" } },
|
||||
{ "length-road", { "mile-scandinavian", "kilometer" } },
|
||||
{ "length-road-informal", { "mile-scandinavian" } },
|
||||
{ "speed-wind", { "meter-per-second" } },
|
||||
};
|
||||
@ -146,7 +149,7 @@ const std::unordered_map<std::string, std::vector<std::string>> USAGE_US {
|
||||
{ "length-road-small", { "foot" } },
|
||||
{ "length-snowfall", { "inch" } },
|
||||
{ "length-vehicle", { "foot", "inch" } },
|
||||
{ "length-visiblty", { "mile" } },
|
||||
{ "length-visiblty", { "mile", "foot" } },
|
||||
{ "length-visiblty-small", { "foot" } },
|
||||
{ "speed-road-travel", { "mile-per-hour" } },
|
||||
{ "speed-wind", { "mile-per-hour" } },
|
||||
@ -216,9 +219,9 @@ const std::unordered_map<std::string, std::vector<double>> CONVERT_FACTORS {
|
||||
};
|
||||
|
||||
const std::unordered_map<std::string, std::string> CONVERT_TO_UNIT {
|
||||
{ "acre", "sqaure-meter" },
|
||||
{ "hectare", "sqaure-meter" },
|
||||
{ "dunam", "sqaure-meter" },
|
||||
{ "acre", "square-meter" },
|
||||
{ "hectare", "square-meter" },
|
||||
{ "dunam", "square-meter" },
|
||||
{ "fathom", "meter" },
|
||||
{ "foot", "meter" },
|
||||
{ "furlong", "meter" },
|
||||
|
@ -23,19 +23,6 @@ namespace Global {
|
||||
namespace I18n {
|
||||
bool NumberFormat::icuInitialized = NumberFormat::Init();
|
||||
|
||||
std::set<std::string> NumberFormat::allValidLocales = GetValidLocales();
|
||||
|
||||
std::set<std::string> NumberFormat::GetValidLocales()
|
||||
{
|
||||
int32_t validCount = 1;
|
||||
const icu::Locale *validLocales = icu::Locale::getAvailableLocales(validCount);
|
||||
std::set<std::string> allValidLocales;
|
||||
for (int i = 0; i < validCount; i++) {
|
||||
allValidLocales.insert(validLocales[i].getLanguage());
|
||||
}
|
||||
return allValidLocales;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, UNumberUnitWidth> NumberFormat::unitStyle = {
|
||||
{ "long", UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME },
|
||||
{ "short", UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT },
|
||||
@ -77,7 +64,7 @@ NumberFormat::NumberFormat(const std::vector<std::string> &localeTags, std::map<
|
||||
for (size_t i = 0; i < localeTags.size(); i++) {
|
||||
std::string curLocale = localeTags[i];
|
||||
locale = builder->setLanguageTag(icu::StringPiece(curLocale)).build(status);
|
||||
if (allValidLocales.count(locale.getLanguage()) > 0) {
|
||||
if (LocaleInfo::allValidLocales.count(locale.getLanguage()) > 0) {
|
||||
localeInfo = new LocaleInfo(curLocale, configs);
|
||||
locale = localeInfo->GetLocale();
|
||||
localeBaseName = localeInfo->GetBaseName();
|
||||
|
@ -27,17 +27,6 @@ namespace I18n {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001E00, "IntlJs" };
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
std::set<std::string> PluralRules::GetValidLocales()
|
||||
{
|
||||
int32_t validCount = 1;
|
||||
const icu::Locale *validLocales = icu::Locale::getAvailableLocales(validCount);
|
||||
std::set<std::string> allValidLocales;
|
||||
for (int i = 0; i < validCount; i++) {
|
||||
allValidLocales.insert(validLocales[i].getLanguage());
|
||||
}
|
||||
return allValidLocales;
|
||||
}
|
||||
|
||||
std::string PluralRules::ParseOption(std::map<std::string, std::string> &options, const std::string &key)
|
||||
{
|
||||
std::map<std::string, std::string>::iterator it = options.find(key);
|
||||
@ -92,14 +81,13 @@ void PluralRules::InitPluralRules(std::vector<std::string> &localeTags,
|
||||
{
|
||||
UPluralType uPluralType = (type == "cardinal") ? UPLURAL_TYPE_CARDINAL : UPLURAL_TYPE_ORDINAL;
|
||||
UErrorCode status = UErrorCode::U_ZERO_ERROR;
|
||||
std::set<std::string> allValidLocales = GetValidLocales();
|
||||
if (localeTags.size() == 0) {
|
||||
localeTags.push_back(LocaleConfig::GetSystemLocale());
|
||||
}
|
||||
for (size_t i = 0; i < localeTags.size(); i++) {
|
||||
std::string curLocale = localeTags[i];
|
||||
locale = icu::Locale::forLanguageTag(icu::StringPiece(curLocale), status);
|
||||
if (allValidLocales.count(locale.getLanguage()) > 0) {
|
||||
if (LocaleInfo::allValidLocales.count(locale.getLanguage()) > 0) {
|
||||
localeInfo = new LocaleInfo(curLocale, options);
|
||||
locale = localeInfo->GetLocale();
|
||||
localeStr = localeInfo->GetBaseName();
|
||||
|
Loading…
Reference in New Issue
Block a user