From: Lukasz Pik Date: Wed, 14 Mar 2018 12:26:51 +0000 (+0100) Subject: [Base-utils][ACR-1182]Fix of setting locale in functions X-Git-Tag: submit/tizen/20180416.063536^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbe0048869da83453f7e902558a9e8aebaa63044;p=platform%2Fcore%2Fapi%2Fbase-utils.git [Base-utils][ACR-1182]Fix of setting locale in functions Change-Id: I8cc5d45b03e4e7b412a897472211c4dba918d017 Signed-off-by: Lukasz Pik --- diff --git a/src/include/utils_i18n.h b/src/include/utils_i18n.h index 1d824cf..54184fb 100644 --- a/src/include/utils_i18n.h +++ b/src/include/utils_i18n.h @@ -346,21 +346,11 @@ extern "C" { * * * @ref CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE - * #i18n_timezone_get_display_name_with_locale - * getDisplayName - * - * - * @ref CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE * #i18n_timezone_get_display_name_with_type * getDisplayName * * * @ref CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE - * #i18n_timezone_get_display_name_with_type_locale - * getDisplayName - * - * - * @ref CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE * #i18n_timezone_use_daylight_time * useDaylightTime * @@ -385,6 +375,16 @@ extern "C" { * detectHostTimeZone * * + * @ref CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE + * #i18n_timezone_get_display_name_with_locale_id + * getDisplayName + * + * + * @ref CAPI_BASE_UTILS_I18N_TIMEZONE_MODULE + * #i18n_timezone_get_display_name_with_type_locale_id + * getDisplayName + * + * * @ref CAPI_BASE_UTILS_I18N_UENUMERATION_MODULE * #i18n_uenumeration_destroy * uenum_close @@ -2352,21 +2352,11 @@ extern "C" { * * * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE - * #i18n_alpha_idx_create - * AlphabeticIndex - * - * - * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE * #i18n_alpha_idx_destroy * ~AlphabeticIndex * * * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE - * #i18n_alpha_idx_add_labels - * addLabels - * - * - * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE * #i18n_alpha_idx_add_record * addRecord * @@ -2481,6 +2471,16 @@ extern "C" { * resetRecordIterator * * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_create_from_locale_id + * AlphabeticIndex + * + * + * @ref CAPI_BASE_UTILS_I18N_ALPHA_IDX_MODULE + * #i18n_alpha_idx_add_labels_with_locale_id + * addLabels + * + * * @ref CAPI_BASE_UTILS_I18N_FORMATTABLE_MODULE * #i18n_formattable_create_default * Formattable() @@ -3302,16 +3302,11 @@ extern "C" { * * * @ref CAPI_BASE_UTILS_I18N_FORMAT_MODULE - * #i18n_format_get_locale + * #i18n_format_get_locale_id * getLocale * * * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE - * #i18n_measure_format_create - * MeasureFormat - * - * - * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE * #i18n_measure_format_destroy * ~MeasureFormat * @@ -3332,11 +3327,6 @@ extern "C" { * * * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE - * #i18n_measure_format_create_currency_format_from_locale - * createCurrencyFormat - * - * - * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE * #i18n_measure_format_create_currency_format * createCurrencyFormat * @@ -3361,6 +3351,16 @@ extern "C" { * getUnitDisplayName * * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_create_from_locale_id + * MeasureFormat + * + * + * @ref CAPI_BASE_UTILS_I18N_MEASURE_FORMAT_MODULE + * #i18n_measure_format_create_currency_format_from_locale_id + * createCurrencyFormat + * + * * @ref CAPI_BASE_UTILS_I18N_FIELD_POSITION_MODULE * #i18n_field_position_create * FieldPosition @@ -3778,11 +3778,6 @@ extern "C" { * * * @ref CAPI_BASE_UTILS_I18N_PLURAL_RULES_MODULE - * #i18n_plural_rules_for_locale - * forLocale - * - * - * @ref CAPI_BASE_UTILS_I18N_PLURAL_RULES_MODULE * #i18n_plural_rules_select_int32 * select * @@ -3812,6 +3807,11 @@ extern "C" { * getKeywordOther * * + * @ref CAPI_BASE_UTILS_I18N_PLURAL_RULES_MODULE + * #i18n_plural_rules_for_locale_id + * forLocale + * + * * @ref CAPI_BASE_UTILS_I18N_PLURAL_FORMAT_MODULE * #i18n_plural_format_create * PluralFormat diff --git a/src/include/utils_i18n_alpha_idx.h b/src/include/utils_i18n_alpha_idx.h index 7933404..8e60dc1 100644 --- a/src/include/utils_i18n_alpha_idx.h +++ b/src/include/utils_i18n_alpha_idx.h @@ -56,6 +56,7 @@ extern "C" { */ /** + * @deprecated Deprecated since 5.0. Use i18n_alpha_idx_create_from_locale_id() instead. * @brief Creates an alphabetic index object for the specified locale. * @details If the locale's data does not include index characters, * a set of them will be synthesized based on the locale's @@ -76,7 +77,7 @@ extern "C" { * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory */ int i18n_alpha_idx_create(const char *language, const char *country, - i18n_alpha_idx_h *index); + i18n_alpha_idx_h *index) TIZEN_DEPRECATED_API; /** * @brief Destroys the alphabetic index object. @@ -91,6 +92,7 @@ int i18n_alpha_idx_create(const char *language, const char *country, int i18n_alpha_idx_destroy(i18n_alpha_idx_h index); /** + * @deprecated Deprecated since 5.0. Use i18n_alpha_idx_add_labels_with_locale_id() instead. * @brief Adds the index characters from a specified locale to the index. * @details The labels are added to those that are already in the index; * they do not replace the existing index characters. The collation @@ -107,7 +109,7 @@ int i18n_alpha_idx_destroy(i18n_alpha_idx_h index); * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter */ int i18n_alpha_idx_add_labels(i18n_alpha_idx_h index, const char *language, - const char *country); + const char *country) TIZEN_DEPRECATED_API; /** * @brief Adds the record to the alphabetic index. @@ -478,6 +480,45 @@ int i18n_alpha_idx_reset_bucket_iter(i18n_alpha_idx_h index); */ int i18n_alpha_idx_reset_record_iter(i18n_alpha_idx_h index); + +/** + * @brief Creates an alphabetic index object for the specified locale. + * @details If the locale's data does not include index characters, + * a set of them will be synthesized based on the locale's + * exemplar characters. The locale determines the sorting order + * for both the index characters and the user item names appearing + * under each Index character. + * @since_tizen 5.0 + * @remarks The created object should be released by the caller with the + * #i18n_alpha_idx_destroy() function. + * + * @param[in] locale_id The locale string containing language and country code + * @param[out] index The created alphabetic index object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_alpha_idx_create_from_locale_id(const char *locale_id, i18n_alpha_idx_h *index); + +/** + * @brief Adds the index characters from a specified locale to the index. + * @details The labels are added to those that are already in the index; + * they do not replace the existing index characters. The collation + * order for this index is not changed; it remains that of the locale + * that was originally specified when creating this Index. + * @since_tizen 5.0 + * + * @param[in] index Label will be added to this alphabetic index + * @param[in] locale_id The locale string containing language and country code + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + */ +int i18n_alpha_idx_add_labels_with_locale_id(i18n_alpha_idx_h index, const char *locale_id); + /** * @} */ diff --git a/src/include/utils_i18n_format.h b/src/include/utils_i18n_format.h index f70cf8f..d4e27af 100644 --- a/src/include/utils_i18n_format.h +++ b/src/include/utils_i18n_format.h @@ -158,6 +158,7 @@ int i18n_format_parse_object(i18n_format_h format, const char *source, i18n_form int i18n_format_parse_object_with_parse_position(i18n_format_h format, const char *source, i18n_parse_position_h parse_position, i18n_formattable_h *result); /** + * @deprecated Deprecated since 5.0. Use i18n_format_get_locale_id() instead. * @brief Gets the locale for the given format object. * @details You can choose between valid and actual locale. * @since_tizen 2.3.2 and 3.0 @@ -174,7 +175,27 @@ int i18n_format_parse_object_with_parse_position(i18n_format_h format, const cha * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory */ int i18n_format_get_locale(i18n_format_h format, - i18n_ulocale_data_locale_type_e type, char **language, char **country); + i18n_ulocale_data_locale_type_e type, + char **language, char **country) TIZEN_DEPRECATED_API; + +/** + * @brief Gets the locale for the given format object. + * @details You can choose between valid and actual locale. + * @since_tizen 5.0 + * @remarks @a locale_id should be released by the caller with the free() function. + * + * @param[in] format The format object + * @param[in] type The type of the locale we're looking for (valid or actual) + * @param[out] locale_id The locale indentifier + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_format_get_locale_id(i18n_format_h format, + i18n_ulocale_data_locale_type_e type, char **locale_id); + /** * @} diff --git a/src/include/utils_i18n_measure_format.h b/src/include/utils_i18n_measure_format.h index 47d5810..135475b 100644 --- a/src/include/utils_i18n_measure_format.h +++ b/src/include/utils_i18n_measure_format.h @@ -46,6 +46,7 @@ extern "C" { */ /** + * @deprecated Deprecated since 5.0. Use i18n_measure_format_create_from_locale_id() instead. * @brief Creates the measure format object using given locale. * @since_tizen 2.3.2 and 3.0 * @remarks The created object should be released by the caller with the @@ -64,10 +65,10 @@ extern "C" { int i18n_measure_format_create(const char *language, const char *country, i18n_umeasure_format_width_e width, - i18n_measure_format_h *measure_format); + i18n_measure_format_h *measure_format) TIZEN_DEPRECATED_API; /** - * @brief Destroys the measure format object + * @brief Destroys the measure format object. * @since_tizen 2.3.2 and 3.0 * * @param[in] measure_format The measure format object to destroy @@ -147,6 +148,7 @@ int i18n_measure_format_parse_object(i18n_measure_format_h measure_format, i18n_formattable_h *result); /** + * @deprecated Deprecated since 5.0. Use i18n_measure_format_create_currency_format_from_locale_id() instead. * @brief Gets a formatter for currency amount objects in the given locale. * @since_tizen 2.3.2 and 3.0 * @remarks The created object should be released by the caller with the @@ -163,7 +165,7 @@ int i18n_measure_format_parse_object(i18n_measure_format_h measure_format, */ int i18n_measure_format_create_currency_format_from_locale(const char *language, const char *country, - i18n_measure_format_h *measure_format); + i18n_measure_format_h *measure_format) TIZEN_DEPRECATED_API; /** * @brief Gets a formatter for currency amount objects in the default locale. @@ -300,7 +302,7 @@ int i18n_measure_format_format_measure_per_unit(const i18n_measure_format_h meas * inserted to the @a buffer and #I18N_ERROR_BUFFER_OVERFLOW * is returned. * @param[out] buffer The buffer to which the formatted string will be inserted. - * Can be @c NULL if @a output_buffer_size <= 0. + * Can be @c NULL if @a buffer_size <= 0. * @param[out] output_length The length of the output string * * @return @c 0 on success, otherwise a negative error value @@ -314,6 +316,42 @@ int i18n_measure_format_get_unit_display_name(const i18n_measure_format_h measur i18n_uchar *buffer, int32_t *output_length); +/** + * @brief Creates the measure format object using given locale. + * @since_tizen 5.0 + * @remarks The created object should be released by the caller with the + * i18n_measure_format_destroy() function. + * + * @param[in] locale_id The locale string containing language and country code + * @param[in] width The format width + * @param[out] measure_format The created measure format object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_create_from_locale_id(const char *locale_id, + i18n_umeasure_format_width_e width, + i18n_measure_format_h *measure_format); + +/** + * @brief Gets a formatter for currency amount objects in the given locale. + * @since_tizen 5.0 + * @remarks The created object should be released by the caller with the + * i18n_measure_format_destroy() function. + * + * @param[in] locale_id The locale string containing language and country code + * @param[out] measure_format The measure format object + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_measure_format_create_currency_format_from_locale_id(const char *locale_id, + i18n_measure_format_h *measure_format); + /** * @} */ diff --git a/src/include/utils_i18n_plural_format.h b/src/include/utils_i18n_plural_format.h index bfbebaa..0303b32 100644 --- a/src/include/utils_i18n_plural_format.h +++ b/src/include/utils_i18n_plural_format.h @@ -158,8 +158,7 @@ int i18n_plural_format_create(i18n_plural_format_h *plural_format); * @remarks The created object should be released by the caller with the * i18n_plural_format_destroy() function. * - * @param[in] language The language of the locale - * @param[in] country The country of the locale + * @param[in] locale The locale string containing language and country code * @param[out] plural_format The created plural format object * * @return @c 0 on success, otherwise a negative error value @@ -167,8 +166,7 @@ int i18n_plural_format_create(i18n_plural_format_h *plural_format); * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory */ -int i18n_plural_format_create_from_locale(const char *language, - const char *country, +int i18n_plural_format_create_from_locale(const char *locale, i18n_plural_format_h *plural_format); /** @@ -196,8 +194,7 @@ int i18n_plural_format_create_from_rules_pattern(i18n_plural_rules_h plural_rule * @remarks The created object should be released by the caller with the * i18n_plural_format_destroy() function. * - * @param[in] language The language of the locale - * @param[in] country The country of the locale + * @param[in] locale The locale string containing language and country code * @param[in] type The plural type * @param[in] pattern The pattern for this plural format object * @param[out] plural_format The created plural format object @@ -207,8 +204,7 @@ int i18n_plural_format_create_from_rules_pattern(i18n_plural_rules_h plural_rule * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory */ -int i18n_plural_format_create_from_locale_type_pattern(const char *language, - const char *country, +int i18n_plural_format_create_from_locale_type_pattern(const char *locale, i18n_uplural_type_e type, const char *pattern, i18n_plural_format_h *plural_format); @@ -220,8 +216,7 @@ int i18n_plural_format_create_from_locale_type_pattern(const char *language, * @remarks The created object should be released by the caller with the * i18n_plural_format_destroy() function. * - * @param[in] language The language of the locale - * @param[in] country The country of the locale + * @param[in] locale The locale string containing language and country code * @param[in] type The plural type * @param[out] plural_format The created plural format object * @@ -230,8 +225,7 @@ int i18n_plural_format_create_from_locale_type_pattern(const char *language, * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory */ -int i18n_plural_format_create_from_locale_type(const char *language, - const char *country, +int i18n_plural_format_create_from_locale_type(const char *locale, i18n_uplural_type_e type, i18n_plural_format_h *plural_format); @@ -242,8 +236,7 @@ int i18n_plural_format_create_from_locale_type(const char *language, * @remarks The created object should be released by the caller with the * i18n_plural_format_destroy() function. * - * @param[in] language The language of the locale - * @param[in] country The country of the locale + * @param[in] locale The locale string containing language and country code * @param[in] pattern The pattern for this plural format object * @param[out] plural_format The created plural format object * @@ -252,8 +245,7 @@ int i18n_plural_format_create_from_locale_type(const char *language, * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory */ -int i18n_plural_format_create_from_locale_pattern(const char *language, - const char *country, +int i18n_plural_format_create_from_locale_pattern(const char *locale, const char *pattern, i18n_plural_format_h *plural_format); @@ -263,8 +255,7 @@ int i18n_plural_format_create_from_locale_pattern(const char *language, * @remarks The created object should be released by the caller with the * i18n_plural_format_destroy() function. * - * @param[in] language The language of the locale - * @param[in] country The country of the locale + * @param[in] locale The locale string containing language and country code * @param[in] plural_rules Plural rules which defines the behavior of the plural format object * @param[in] pattern The pattern for this plural format object * @param[out] plural_format The created plural format object @@ -274,8 +265,7 @@ int i18n_plural_format_create_from_locale_pattern(const char *language, * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory */ -int i18n_plural_format_create_from_locale_rules_pattern(const char *language, - const char *country, +int i18n_plural_format_create_from_locale_rules_pattern(const char *locale, i18n_plural_rules_h plural_rules, const char *pattern, i18n_plural_format_h *plural_format); diff --git a/src/include/utils_i18n_plural_rules.h b/src/include/utils_i18n_plural_rules.h index 121e8a9..7fa06b9 100644 --- a/src/include/utils_i18n_plural_rules.h +++ b/src/include/utils_i18n_plural_rules.h @@ -193,6 +193,7 @@ int i18n_plural_rules_clone(i18n_plural_rules_h plural_rules, i18n_plural_rules_ int i18n_plural_rules_create_rules_from_descr(const char *description, i18n_plural_rules_h *plural_rules); /** + * @deprecated Deprecated since 5.0. Use i18n_plural_rules_for_locale_id() instead. * @brief Provides access to the predefined plural rules object for a given locale and the plural type. * @details If there's no predefined rules for this locale, the rules for the closest parent * in the locale hierarchy that has one will be returned. @@ -214,7 +215,7 @@ int i18n_plural_rules_create_rules_from_descr(const char *description, i18n_plur int i18n_plural_rules_for_locale(const char *language, const char *country, i18n_uplural_type_e type, - i18n_plural_rules_h *plural_rules); + i18n_plural_rules_h *plural_rules) TIZEN_DEPRECATED_API; /** * @brief Returns the keyword of the first rule that applies to the given number. @@ -344,6 +345,28 @@ int i18n_plural_rules_get_keyword_other(i18n_plural_rules_h plural_rules, i18n_uchar *output_buffer, int32_t *output_length); +/** + * @brief Provides access to the predefined plural rules object for a given locale and the plural type. + * @details If there's no predefined rules for this locale, the rules for the closest parent + * in the locale hierarchy that has one will be returned. + * The final fallback always returns the default 'other' rules. + * @since_tizen 5.0 + * @remarks The created object should be released by the caller with the + * i18n_plural_rules_destroy() function. + * + * @param[in] locale_id The locale string containing language and country code + * @param[in] type The plural type (e.g., cardinal or ordinal) + * @param[out] plural_rules The pointer to the plural rules object for given locale + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #I18N_ERROR_OUT_OF_MEMORY Out of memory + */ +int i18n_plural_rules_for_locale_id(const char *locale_id, + i18n_uplural_type_e type, + i18n_plural_rules_h *plural_rules); + /** diff --git a/src/include/utils_i18n_timezone.h b/src/include/utils_i18n_timezone.h index f8ddec0..537796e 100644 --- a/src/include/utils_i18n_timezone.h +++ b/src/include/utils_i18n_timezone.h @@ -350,6 +350,7 @@ int i18n_timezone_set_id(i18n_timezone_h timezone, const char *timezone_id); int i18n_timezone_get_display_name(i18n_timezone_h timezone, char **display_name); /** + * @deprecated Deprecated since 5.0. Use i18n_timezone_get_display_name_with_locale_id() instead. * @brief Returns a name of this time zone suitable for presentation to the user in the default locale. * @details This method returns the long name, not including daylight savings. * If the display name is not available for the locale, then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm. @@ -380,6 +381,7 @@ int i18n_timezone_get_display_name_with_locale(i18n_timezone_h timezone, const c int i18n_timezone_get_display_name_with_type(i18n_timezone_h timezone, i18n_ubool daylight, i18n_timezone_display_type_e style, char **display_name); /** + * @deprecated Deprecated since 5.0. Use i18n_timezone_get_display_name_with_type_locale_id() instead. * @brief Returns a name of this time zone suitable for presentation to the user in the default locale. * @details If the display name is not available for the locale, * then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm. @@ -463,6 +465,42 @@ int i18n_timezone_get_dst_savings(i18n_timezone_h timezone, int32_t *dst_savings */ int i18n_timezone_detect_host_timezone(i18n_timezone_h *timezone); +/** + * @brief Returns a name of this time zone suitable for presentation to the user in the default locale. + * @details This method returns the long name, not including daylight savings. + * If the display name is not available for the locale, then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm. + * @since_tizen 5.0 + * @remarks @a display_name is allocated on heap and should be released by the caller with the free() function. + * + * @param[in] timezone The i18n_timezone_h to get a display name + * @param[in] locale_id The locale string containing language and country code + * @param[out] display_name The human-readable name of this time zone in the default locale + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + */ +int i18n_timezone_get_display_name_with_locale_id(i18n_timezone_h timezone, const char *locale_id , char **display_name); + +/** + * @brief Returns a name of this time zone suitable for presentation to the user in the default locale. + * @details If the display name is not available for the locale, + * then this method returns a string in the localized GMT offset format such as GMT[+-]HH:mm. + * @since_tizen 5.0 + * @remarks @a display_name is allocated on heap and should be released by the caller with the free() function. + * + * @param[in] timezone The i18n_timezone_h to get a display name + * @param[in] daylight If true, display_name is filled with the daylight savings name + * @param[in] style The style displayed on + * @param[in] locale_id The locale string containing language and country code + * @param[out] display_name The human-readable name of this time zone in the default locale + * + * @return @c 0 on success, otherwise a negative error value + * @retval #I18N_ERROR_NONE Successful + * @retval #I18N_ERROR_INVALID_PARAMETER Invalid function parameter + */ +int i18n_timezone_get_display_name_with_type_locale_id(i18n_timezone_h timezone, i18n_ubool daylight, i18n_timezone_display_type_e style, const char *locale_id, char **display_name); + #ifdef __cplusplus } #endif diff --git a/src/utils_i18n_alpha_idx.cpp b/src/utils_i18n_alpha_idx.cpp index cf5088c..734225d 100644 --- a/src/utils_i18n_alpha_idx.cpp +++ b/src/utils_i18n_alpha_idx.cpp @@ -371,3 +371,29 @@ int i18n_alpha_idx_reset_record_iter(i18n_alpha_idx_h index) return I18N_ERROR_NONE; } + +int i18n_alpha_idx_create_from_locale_id(const char *locale_id, i18n_alpha_idx_h *index) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + Locale locale(locale_id, 0, 0, 0); + UErrorCode status = U_ZERO_ERROR; + + *index = new AlphabeticIndex(locale, status); + retv_if(*index == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return _i18n_error_mapping(status); +} + +int i18n_alpha_idx_add_labels_with_locale_id(i18n_alpha_idx_h index, + const char *locale_id) +{ + retv_if(index == NULL, I18N_ERROR_INVALID_PARAMETER); + + Locale locale(locale_id, 0, 0, 0); + UErrorCode status = U_ZERO_ERROR; + + ((AlphabeticIndex *) index)->addLabels(locale, status); + + return _i18n_error_mapping(status); +} diff --git a/src/utils_i18n_format.cpp b/src/utils_i18n_format.cpp index f32eb7e..9953e5e 100644 --- a/src/utils_i18n_format.cpp +++ b/src/utils_i18n_format.cpp @@ -161,3 +161,20 @@ int i18n_format_get_locale(i18n_format_h format, i18n_ulocale_data_locale_type_e return _i18n_error_mapping(status); } + +int i18n_format_get_locale_id(i18n_format_h format, i18n_ulocale_data_locale_type_e type, + char **locale_id) +{ + retv_if(format == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(type < I18N_ULOCALE_DATA_LOCALE_TYPE_ACTUAL_LOCALE || type > I18N_ULOCALE_DATA_LOCALE_TYPE_VALID_LOCALE, I18N_ERROR_INVALID_PARAMETER); + retv_if(locale_id == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + ULocDataLocaleType icu_type = (ULocDataLocaleType) type; + + Locale locale = ((Format *) format)->getLocale(icu_type, status); + + *locale_id = strdup(locale.getName()); + + return _i18n_error_mapping(status); +} diff --git a/src/utils_i18n_measure_format.cpp b/src/utils_i18n_measure_format.cpp index 581d6e7..317ae15 100644 --- a/src/utils_i18n_measure_format.cpp +++ b/src/utils_i18n_measure_format.cpp @@ -310,3 +310,32 @@ int i18n_measure_format_get_unit_display_name(const i18n_measure_format_h measur return _i18n_error_mapping(status); } +int i18n_measure_format_create_from_locale_id(const char *locale_id, + i18n_umeasure_format_width_e width, + i18n_measure_format_h *measure_format) +{ + retv_if(measure_format == NULL, I18N_ERROR_INVALID_PARAMETER); + retv_if(width < I18N_UMEASFMT_WIDTH_WIDE, I18N_ERROR_INVALID_PARAMETER); + retv_if(width >= I18N_UMEASFMT_WIDTH_COUNT, I18N_ERROR_INVALID_PARAMETER); + UErrorCode status = U_ZERO_ERROR; + Locale locale(locale_id, 0, 0, 0); + UMeasureFormatWidth icu_width = (UMeasureFormatWidth) width; + + *measure_format = new MeasureFormat(locale, icu_width, status); + retv_if(*measure_format == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return _i18n_error_mapping(status); +} + +int i18n_measure_format_create_currency_format_from_locale_id(const char *locale_id, + i18n_measure_format_h *measure_format) +{ + retv_if(measure_format == NULL, I18N_ERROR_INVALID_PARAMETER); + UErrorCode status = U_ZERO_ERROR; + Locale locale(locale_id, 0, 0, 0); + + *measure_format = MeasureFormat::createCurrencyFormat(locale, status); + retv_if(*measure_format == NULL, I18N_ERROR_OUT_OF_MEMORY); + + return _i18n_error_mapping(status); +} diff --git a/src/utils_i18n_plural_format.cpp b/src/utils_i18n_plural_format.cpp index e90224d..2b40015 100644 --- a/src/utils_i18n_plural_format.cpp +++ b/src/utils_i18n_plural_format.cpp @@ -33,14 +33,13 @@ int i18n_plural_format_create(i18n_plural_format_h *plural_format) } -int i18n_plural_format_create_from_locale(const char *language, - const char *country, +int i18n_plural_format_create_from_locale(const char *locale, i18n_plural_format_h *plural_format) { retv_if(plural_format == NULL, I18N_ERROR_INVALID_PARAMETER); UErrorCode status = U_ZERO_ERROR; - *plural_format = new PluralFormat(Locale(language, country, 0, 0), status); + *plural_format = new PluralFormat(Locale(locale, 0, 0, 0), status); retv_if(*plural_format == NULL, I18N_ERROR_OUT_OF_MEMORY); return _i18n_error_mapping(status); @@ -64,8 +63,7 @@ int i18n_plural_format_create_from_rules_pattern(i18n_plural_rules_h plural_rule return _i18n_error_mapping(status); } -int i18n_plural_format_create_from_locale_type_pattern(const char *language, - const char *country, +int i18n_plural_format_create_from_locale_type_pattern(const char *locale, i18n_uplural_type_e type, const char *pattern, i18n_plural_format_h *plural_format) @@ -76,7 +74,7 @@ int i18n_plural_format_create_from_locale_type_pattern(const char *language, UErrorCode status = U_ZERO_ERROR; UnicodeString unicode_pattern(pattern); - *plural_format = new PluralFormat(Locale(language, country, 0, 0), + *plural_format = new PluralFormat(Locale(locale, 0, 0, 0), (UPluralType)type, unicode_pattern, status); @@ -85,8 +83,7 @@ int i18n_plural_format_create_from_locale_type_pattern(const char *language, return _i18n_error_mapping(status); } -int i18n_plural_format_create_from_locale_type(const char *language, - const char *country, +int i18n_plural_format_create_from_locale_type(const char *locale, i18n_uplural_type_e type, i18n_plural_format_h *plural_format) { @@ -94,14 +91,13 @@ int i18n_plural_format_create_from_locale_type(const char *language, retv_if(type < 0 || type > I18N_UPLURAL_TYPE_ORDINAL, I18N_ERROR_INVALID_PARAMETER); UErrorCode status = U_ZERO_ERROR; - *plural_format = new PluralFormat(Locale(language, country, 0, 0), (UPluralType)type, status); + *plural_format = new PluralFormat(Locale(locale, 0, 0, 0), (UPluralType)type, status); retv_if(*plural_format == NULL, I18N_ERROR_OUT_OF_MEMORY); return _i18n_error_mapping(status); } -int i18n_plural_format_create_from_locale_pattern(const char *language, - const char *country, +int i18n_plural_format_create_from_locale_pattern(const char *locale, const char *pattern, i18n_plural_format_h *plural_format) { @@ -110,14 +106,13 @@ int i18n_plural_format_create_from_locale_pattern(const char *language, UErrorCode status = U_ZERO_ERROR; UnicodeString unicode_pattern(pattern); - *plural_format = new PluralFormat(Locale(language, country, 0, 0), unicode_pattern, status); + *plural_format = new PluralFormat(Locale(locale, 0, 0, 0), unicode_pattern, status); retv_if(*plural_format == NULL, I18N_ERROR_OUT_OF_MEMORY); return _i18n_error_mapping(status); } -int i18n_plural_format_create_from_locale_rules_pattern(const char *language, - const char *country, +int i18n_plural_format_create_from_locale_rules_pattern(const char *locale, i18n_plural_rules_h plural_rules, const char *pattern, i18n_plural_format_h *plural_format) @@ -129,7 +124,7 @@ int i18n_plural_format_create_from_locale_rules_pattern(const char *language, UErrorCode status = U_ZERO_ERROR; UnicodeString unicode_pattern(pattern); - *plural_format = new PluralFormat(Locale(language, country, 0, 0), + *plural_format = new PluralFormat(Locale(locale, 0, 0, 0), *((PluralRules *)plural_rules), unicode_pattern, status); diff --git a/src/utils_i18n_plural_rules.cpp b/src/utils_i18n_plural_rules.cpp index 54ae3d6..6ce4612 100644 --- a/src/utils_i18n_plural_rules.cpp +++ b/src/utils_i18n_plural_rules.cpp @@ -183,3 +183,15 @@ int i18n_plural_rules_get_keyword_other(i18n_plural_rules_h plural_rules, return I18N_ERROR_NONE; } + +int i18n_plural_rules_for_locale_id(const char *locale_id, + i18n_uplural_type_e type, + i18n_plural_rules_h *plural_rules) +{ + retv_if(plural_rules == NULL, I18N_ERROR_INVALID_PARAMETER); + + UErrorCode status = U_ZERO_ERROR; + *plural_rules = PluralRules::forLocale(Locale(locale_id, 0, 0, 0), (UPluralType)type, status); + + return _i18n_error_mapping(status); +} diff --git a/src/utils_i18n_timezone.cpp b/src/utils_i18n_timezone.cpp index 1b582bb..99f992e 100755 --- a/src/utils_i18n_timezone.cpp +++ b/src/utils_i18n_timezone.cpp @@ -466,3 +466,55 @@ int i18n_timezone_detect_host_timezone(i18n_timezone_h *timezone) return I18N_ERROR_NONE; } + +int i18n_timezone_get_display_name_with_locale_id(i18n_timezone_h timezone, const char *locale_id, + char **display_name) +{ + retv_if(timezone == NULL || display_name == NULL, I18N_ERROR_INVALID_PARAMETER); + + Locale locale(locale_id, 0, 0, 0); + *display_name = NULL; + UnicodeString displayName; + + ((TimeZone *) timezone)->getDisplayName(locale, displayName); + const UChar *dn = displayName.getTerminatedBuffer(); + + retv_if(dn == NULL, I18N_ERROR_INVALID_PARAMETER); + int32_t ulen = u_strlen(dn); + + retv_if(ulen <= 0, I18N_ERROR_INVALID_PARAMETER); + *display_name = (char *)malloc(ulen + 1); + + retv_if(*display_name == NULL, I18N_ERROR_OUT_OF_MEMORY); + + i18n_ustring_copy_au(*display_name, (i18n_uchar*)dn); + + return I18N_ERROR_NONE; +} + +int i18n_timezone_get_display_name_with_type_locale_id(i18n_timezone_h timezone, i18n_ubool daylight, + i18n_timezone_display_type_e style, + const char *locale_id, char **display_name) +{ + retv_if(timezone == NULL || display_name == NULL, I18N_ERROR_INVALID_PARAMETER); + + const Locale locale(locale_id, 0, 0, 0); + *display_name = NULL; + UnicodeString displayName; + + ((TimeZone *) timezone)->getDisplayName((UBool) daylight, (TimeZone::EDisplayType) style, + locale, displayName); + const UChar *dn = displayName.getTerminatedBuffer(); + + retv_if(dn == NULL, I18N_ERROR_INVALID_PARAMETER); + int32_t ulen = u_strlen(dn); + + retv_if(ulen <= 0, I18N_ERROR_INVALID_PARAMETER); + *display_name = (char *)malloc(ulen + 1); + + retv_if(*display_name == NULL, I18N_ERROR_OUT_OF_MEMORY); + + i18n_ustring_copy_au(*display_name, (i18n_uchar*)dn); + + return I18N_ERROR_NONE; +}