From f82935bc4de61ce43efc9019c82692f7cdbf3d2c Mon Sep 17 00:00:00 2001 From: the-minions-of-cplu Date: Wed, 20 Oct 2021 20:04:09 +0800 Subject: [PATCH] add Global_IsRTL method Signed-off-by: the-minions-of-cplu --- frameworks/resmgr_lite/src/global.c | 34 +++++++++++++++++++++++++++ interfaces/innerkits/include/global.h | 1 + 2 files changed, 35 insertions(+) diff --git a/frameworks/resmgr_lite/src/global.c b/frameworks/resmgr_lite/src/global.c index c132ff7..e2852bf 100644 --- a/frameworks/resmgr_lite/src/global.c +++ b/frameworks/resmgr_lite/src/global.c @@ -35,6 +35,7 @@ #define MAX_LOCALE_LENGTH 13 #define UI_LOCALE_ELEMENT_NUM 2 +#define MAX_SCRIPT_LENGTH 5 static char g_locale[MAX_LOCALE_LENGTH] = {0}; void GLOBAL_ConfigLanguage(const char *appLanguage) @@ -72,6 +73,39 @@ int32_t GLOBAL_GetLanguage(char *language, uint8_t len) return (strncpy_s(language, len, localeArray[0], MAX_LANGUAGE_LENGTH - 1) != EOK) ? MC_FAILURE : MC_SUCCESS; } +int32_t GLOBAL_IsRTL(void) +{ + char *localeArray[LOCALE_ELEMENT_NUM] = { NULL }; + char tempLocale[MAX_LOCALE_LENGTH] = { '\0' }; + int32_t ret = strcpy_s(tempLocale, MAX_LOCALE_LENGTH, g_locale); + if (ret != EOK) { + return 0; + } + int32_t count = 0; + ret = GetGlobalUtilsImpl()->SplitLocale(tempLocale, localeArray, &count); + if (ret == MC_FAILURE || count != UI_LOCALE_ELEMENT_NUM) { + return 0; + } + char script[MAX_SCRIPT_LENGTH] = { 0 }; + if (strncpy_s(script, MAX_SCRIPT_LENGTH, localeArray[1], MAX_SCRIPT_LENGTH - 1) != EOK) { + return 0; + } + // if script is set and script != arab or script != hebr, return false; + if ((strlen(script) == MAX_SCRIPT_LENGTH - 1) && + (strcmp(script, "Arab") != 0) && (strcmp(script, "Hebr") != 0)) { + return 0; + } + char language[MAX_LANGUAGE_LENGTH] = { 0 }; + if (strncpy_s(language, MAX_LANGUAGE_LENGTH, localeArray[0], MAX_LANGUAGE_LENGTH - 1) != EOK) { + return 0; + } + if ((strcmp(language, "fa") == 0) || (strcmp(language, "ar") == 0) || (strcmp(language, "ur") == 0) || + (strcmp(language, "ug") == 0) || (strcmp(language, "he") == 0) || (strcmp(language, "iw") == 0)) { + return 1; + } + return 0; +} + int32_t GLOBAL_GetRegion(char *region, uint8_t len) { if (region == NULL || len == 0) { diff --git a/interfaces/innerkits/include/global.h b/interfaces/innerkits/include/global.h index 3a6f488..2eb2b50 100644 --- a/interfaces/innerkits/include/global.h +++ b/interfaces/innerkits/include/global.h @@ -38,6 +38,7 @@ int32_t GLOBAL_GetValueByName(const char *name, const char *path, char **value); void GLOBAL_ConfigLanguage(const char *appLanguage); int32_t GLOBAL_GetLanguage(char *language, uint8_t len); int32_t GLOBAL_GetRegion(char *region, uint8_t len); +int32_t GLOBAL_IsRTL(void); #ifdef __cplusplus #if __cplusplus -- Gitee