1 Star 0 Fork 78

c01dface / global_i18n_lite

forked from OpenHarmony / global_i18n_lite 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 36.03 KB
一键复制 编辑 原始数据 按行查看 历史
openharmony_ci 提交于 2022-03-17 02:42 . !192 修改内源问题

i18n

Overview

The internationalization module, namely, i18n, provides i18n capabilities such as formatting the date and time, obtaining the month and week names, and formatting numbers.

Directory Structure

The directory structure for the i18n module is as follows:

/base/global/
├── i18n_lite                 # Code repository for the i18n framework
│   ├──  frameworks           # Core code of the i18n framework
│   │   ├── i18n              # i18n module
│   │   │   ├── include       # Header files of external APIs
│   │   │   ├── src           # Implementation code
│   │   │   └── test          # Test cases
│   ├──  interfaces           # i18n framework APIs
│   │   ├── kits              # Application APIs
│   │   │   ├── i18n          # C/C++ i18n APIs
│   │   │   └── js            # C/C++ support for JavaScript APIs

Constraints

Programming language: C/C++

Supported languages: See the Appendix.

Usage

  1. Change the date and time formats (such as the sequence of year, month, and day, month and week names, and 12-hour or 24-hour system) following the system settings to adapt to the cultural habits of users in different locales. For details, see the API reference. The sample code is as follows:
#include "date_time_format.h"
using namespace OHOS::I18N

LocaleInfo locale("zh", "Hans", "CN"); // Obtain the locale.
DateTimeFormat formatter(AvailableDateTimeFormatPattern::HOUR_MINUTE, locale); // Initialize the example date and time and obtain the data required to format the date and time for the specified locale. The first parameter specifies the formatting pattern. For details about the supported formatting patterns, see the types.h file.
time_t time = 3600 * 3; // Obtain the time to be formatted.
std::string zoneInfo = "+1:00"; // Set the time zone to be UTC+0 plus 1 hour.
std::string out; // Store the formatting result in the out field.
Ii8nStatus status = Ii8nStatus::ISUCCESS;
formatter.Format(time, zoneInfo, out, status); // Check the status field for the formatting result.

output:  4:00
  1. Change the number format (such as the numeral system, grouping, decimal point, and percent sign) following the system settings to adapt to the cultural habits of users in different locales. For details, see the API reference. The sample code is as follows:
#include "number_format.h"
using namespace OHOS::I18N

LocaleInfo locale("en", "US");
int status = 0;
NumberFormat formatter(locale, status); // Initialize the number formatting instance and obtain the data required to format numbers for the specified locale. The value of status indicates the initialization result. If the value is 1, the initialization has failed. 
int num = 1234
std::string out = formatter.Format(num, status); // Check the status field for the initialization result.

output: 1,234
  1. Obtain the month and week names in the format for the specified locale. The sample code is as follows:
#include "date_time_format.h"
using namespace OHOS::I18N

LocaleInfo locale("en", "US"); // Obtain the locale.
DateTimeFormat formatter(AvailableDateTimeFormatPattern::HOUR_MINUTE, locale);
std::string month = formatter.GetMonthName(0, DateTimeDataType::FORMAT_WIDE); //: Obtain the month name in the wide format.

output: January
  1. Change the plural rule type following the application's language to adapt to the cultural habits of users.

Languages vary in how they handle plurals of nouns. For example, there can be "one apple" or "two apples" in English. Singular and plural forms of nouns are generally classified into six plural rule types: zero, one, two, a few, many, and others. Supported plural rule types vary depending on languages. For example, Chinese supports only others, English supports one and others, and Arabic supports all the six plural rule types. The sample code is as follows:

#include "plural_format.h"
using namespace OHOS::I18N

LocaleInfo locale("en", "US"); // Obtain the locale.
Ii8nStatus status = Ii8nStatus::ISUCCESS;
PluralFormatter formatter = PluralFormatter(locale, status); // Check the status field for the i18n status of the locale.
int out = formatter.GetPluralFormatter(1, status); // Check the status field for the plural rule type.

output: 1 // Value 1 indicates plural rule type 1.

Repositories Involved

Globalization subsystem

global_resmgr_lite

global_i18n_lite

Appendix

Supported languages

Code

Name of Language

Code

Name of Language

Code

Name of Language

am_ET

Amharic

hr_HR

Croatian

or-IN

Odia

ar_EG

Arabic

hu_HU

Hungarian

pa_IN

Punjabi, Panjabi

as_IN

Assamese

in_ID

Indonesian

pl_PL

Polish

az_AZ

Azerbaijani

it_IT

Italian

pt_BR

Portuguese (Brazil)

be_BY

Belarusian

iw_IL

Hebrew

pt_PT

Portuguese (Europe)

bg_BG

Bulgarian

ja_JP

Japanese

ro_RO

Romanian; Moldavian; Moldovan

bn_BD

Bengali

jv_ID

Javanese

ru_RU

Russian

bo_CN

Tibetan

ka_GE

Georgian

si_LK

Sinhala

bs_BA

Bosnian

kk_KZ

Kazakh (Cyrillic)

sk_SK

Slovak

ca_ES

Catalan

km_KH

Khmer

sl_SI

Slovenian

cs_CZ

Czech

kn_IN

Kannada

sr_Latn_RS sr_RS

Serbian (Latin)

da_DK

Danish

ko_KR

Korean

sv_SE

Swedish

de_DE

German

lo_LA

Lao

sw_TZ

Swahili

el_GR

Greek

lt_LT

Lithuanian

ta_IN

Tamil

en_GB

English (UK)

lv_LV

Latvian

te_IN

Telugu

en_US

English (US)

mai-Deva-IN

Maithili

th_TH

Thai

es_ES

Spanish (Europe)

mi-NZ

Maori

tl_PH

Tagalog

es_US

Spanish (Latin America)

mk_MK

Macedonian

tr_TR

Turkish

et_EE

Estonian

ml_IN

Malayalam

uk_UA

Ukrainian

eu_ES

Basque

mn_MN

Mongolia

ur_PK

Urdu

fa_IR

Persian

mr_IN

Marathi

uz_UZ

Uzbek

fi_FI

Finnish

ms_MY

Malay

vi_VN

Vietnamese

fr_FR

French

my_MM my_ZG

Burmese

zh_CN

Simplified Chinese

gl_ES

Galician

nb_NO

Norwegian

zh_HK

Traditional Chinese (Hong Kong, China)

gu_IN

Gujarati

ne_NP

Nepali

zh_TW

Traditional Chinese (Taiwan, China)

hi_IN

Hindi

nl_NL

Dutch; Flemish

     
1
https://gitee.com/vmalloc/global_i18n_lite.git
git@gitee.com:vmalloc/global_i18n_lite.git
vmalloc
global_i18n_lite
global_i18n_lite
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891