mirror of
https://gitee.com/openharmony/global_i18n
synced 2024-11-23 07:00:13 +00:00
补充维测日志
Signed-off-by: LY <liuyong235@huawei.com>
This commit is contained in:
parent
80f5a7ae47
commit
0ac2ab4ffb
@ -52,6 +52,7 @@ bool CheckSystemPermission();
|
||||
size_t ConvertBytesToSizeT(const char *byteArray);
|
||||
std::set<std::string> GetTimeZoneAvailableIDs(I18nErrorCode &errorCode);
|
||||
bool RegexSearchNoExcept(const std::string& str, std::smatch& match, const std::regex& regex);
|
||||
std::string LocaleEncode(const std::string& locale);
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
@ -1198,6 +1198,8 @@ I18nErrorCode LocaleConfig::SetSystemLanguage(const std::string &languageTag)
|
||||
languageTag.c_str());
|
||||
return I18nErrorCode::INVALID_LANGUAGE_TAG;
|
||||
}
|
||||
std::string languageCode = LocaleEncode(languageTag);
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemLanguage: set language %{public}s.", languageCode.c_str());
|
||||
// save old language, reset system language to old language if update locale failed.
|
||||
std::string oldLanguageTag = GetSystemLanguage();
|
||||
if (SetParameter(LANGUAGE_KEY, languageTag.data()) != 0) {
|
||||
@ -1223,6 +1225,8 @@ I18nErrorCode LocaleConfig::SetSystemRegion(const std::string ®ionTag)
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion %{public}s is not valid region tag.", regionTag.c_str());
|
||||
return I18nErrorCode::INVALID_REGION_TAG;
|
||||
}
|
||||
std::string resionCode = LocaleEncode(regionTag);
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion: set region %{public}s.", resionCode.c_str());
|
||||
return SetSystemLocale(UpdateRegionOfLocale(regionTag));
|
||||
}
|
||||
|
||||
@ -1232,6 +1236,8 @@ I18nErrorCode LocaleConfig::SetSystemLocale(const std::string &localeTag)
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemLocale %{public}s is not a valid locale tag.", localeTag.c_str());
|
||||
return I18nErrorCode::INVALID_LOCALE_TAG;
|
||||
}
|
||||
std::string localeCode = LocaleEncode(localeTag);
|
||||
HILOG_ERROR_I18N("LocaleConfig::SetSystemRegion: set locale %{public}s.", localeCode.c_str());
|
||||
if (SetParameter(LOCALE_KEY, localeTag.data()) != 0) {
|
||||
return I18nErrorCode::UPDATE_SYSTEM_LOCALE_FAILED;
|
||||
}
|
||||
|
@ -13,13 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cerrno>
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <dirent.h>
|
||||
#include <iomanip>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
@ -40,6 +41,8 @@ using namespace std;
|
||||
static const std::string PSEUDO_LOCALE_TAG = "en-XA";
|
||||
static const std::string PSEUDO_START_TAG = "{";
|
||||
static const std::string PSEUDO_END_TAG = "}";
|
||||
static const char CHAR_A = 'A';
|
||||
static const int32_t CHAR2INT_SIZE = 2;
|
||||
constexpr const char *TIMEZONE_LIST_CONFIG_PATH = "/system/etc/zoneinfo/timezone_list.cfg";
|
||||
constexpr const char *DISTRO_TIMEZONE_LIST_CONFIG = "/system/etc/tzdata_distro/timezone_list.cfg";
|
||||
static std::mutex validLocaleMutex;
|
||||
@ -350,6 +353,16 @@ bool RegexSearchNoExcept(const std::string& str, std::smatch& match, const std::
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string LocaleEncode(const std::string& locale)
|
||||
{
|
||||
std::stringstream ss;
|
||||
for (auto& c : locale) {
|
||||
int32_t number = (c == '-') ? 0 : static_cast<int32_t>(c) - static_cast<int32_t>(CHAR_A) + 1;
|
||||
ss << std::setw(CHAR2INT_SIZE) << std::setfill('0') << number;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
} // namespace I18n
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
@ -537,6 +537,11 @@ HWTEST_F(IntlTest, IntlFuncTest0062, TestSize.Level1)
|
||||
const std::string replace = "";
|
||||
StrReplaceAll(str, target, replace);
|
||||
|
||||
std::string localeTag = "zh-Hans-CN";
|
||||
std::string localeCode = LocaleEncode(zh-Hans-CN);
|
||||
std::string targetCode = "58400008334651000314";
|
||||
EXPECT_TRUE(localeCode, targetCode);
|
||||
|
||||
std::string localeRule = "zh-Hans";
|
||||
DateTimeRule* dateTimeRule = new DateTimeRule(localeRule);
|
||||
DateTimeFilter* dateTimeFilter = new DateTimeFilter(localeRule, dateTimeRule);
|
||||
|
Loading…
Reference in New Issue
Block a user