同步操作将从 OpenHarmony/global_i18n_lite 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
The internationalization module, namely, i18n, provides i18n capabilities such as formatting the date and time, obtaining the month and week names, and formatting numbers.
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
Programming language: C/C++
Supported languages: See the Appendix.
#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
#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
#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
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.
global_i18n_lite
Supported languages
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。