From: Michal Pawluk Date: Sat, 19 Sep 2015 07:29:36 +0000 (+0200) Subject: [SAMPLE APP][INTERNATIONALIZATION] Model section added X-Git-Tag: tizen_3.0/TD_SYNC/20161201~427^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3cb7143f0b5a3f778071eb882748cacaa802c86e;p=sdk%2Fonline-doc.git [SAMPLE APP][INTERNATIONALIZATION] Model section added Change-Id: Ia41ad0f9902c2fdfb450ed0a0cb4e341118d02fa Signed-off-by: Michal Pawluk --- diff --git a/org.tizen.sampledescriptions/html/mobile_n/internationalization_sd_mn.htm b/org.tizen.sampledescriptions/html/mobile_n/internationalization_sd_mn.htm index bffbc5d..2eb0ae3 100644 --- a/org.tizen.sampledescriptions/html/mobile_n/internationalization_sd_mn.htm +++ b/org.tizen.sampledescriptions/html/mobile_n/internationalization_sd_mn.htm @@ -396,6 +396,94 @@ static void __view_apply_button_click_cb(void *data, Evas_Object *obj, void *eve

Model

+

+ The responsibility of the application's "Model" module is to operate directly on the i18n (localization) API. The additional benefit of this module is the simplification of the API function calling, + error checking and message logging. +
+ One of the functions implemented within the "Model" module was briefly described in the Handling global language change section + (model_get_locale_language()). Other functions are presented here. +

+ +

+ The model_get_available_locale() function is responsible for enumerating all languages with respect to their localization information. + For each localization code, the callback function of get_available_locale_cb type is called. +

+ +
+bool model_get_available_locale(get_available_locale_cb func_cb, void *data)
+{
+   if (!func_cb) {
+      controller_log(DLOG_ERROR, "Wrong argument provided.");
+      return false;
+   }
+
+   /* The number of available locale is acquired. */
+   int i;
+   int32_t count = i18n_ulocale_count_available();
+
+   for (i = 0; i < count; i++) {
+      /* The localization code is obtained by its index. */
+      const char *locale = i18n_ulocale_get_available(i);
+
+      /* For each localization code obtained, the provided callback function is called. */
+      if (locale && !func_cb(locale, data))
+         break;
+   }
+
+   return true;
+}
+
+ +

+ The model_get_locale_display_language() function is responsible for obtaining the readable display language name based on + its localization code. +

+ +
+bool model_get_locale_display_language(const char *locale, char **display_language)
+{
+   i18n_uchar i18n_language[256] = {0,};
+
+   if (!display_language) {
+      controller_log(DLOG_ERROR, "Wrong argument provided.");
+      return false;
+   }
+
+   /* The readable display language string is obtained from the localization code. */
+   i18n_ulocale_get_display_language(locale, NULL, i18n_language, sizeof(i18n_language));
+   int ret = get_last_result();
+   if (ret != I18N_ERROR_NONE) {
+      controller_log(DLOG_ERROR, "Function i18n_ulocale_get_display_language() failed with error %d.", ret);
+      return false;
+   }
+
+   /* The returned display language string is stored in an array of i18n_uchar,        */
+   /* which is represented by the 16-bit unsigned int value, so it can not be simply   */
+   /* typecasted to the char string. The transformation to the char string             */
+   /* requires the i18n relevant function application. In order to store               */
+   /* the display language in a char string, a new memory area is reserved.            */
+   int32_t str_len = i18n_ustring_get_length(i18n_language);
+   *display_language = (char *)calloc(str_len + 1, sizeof(char));
+   if (!(*display_language)) {
+      controller_log(DLOG_ERROR, "Function calloc() failed.");
+      return false;
+   }
+
+   /* The display language string of type i18n_uchar is copied to the char string, */
+   /* while the 8 higher bits are truncated from each of the i18n_uchar character. */
+   i18n_ustring_copy_au_n(*display_language, i18n_language, str_len);
+   ret = get_last_result();
+   if (ret != I18N_ERROR_NONE) {
+      free(*display_language);
+      *display_language = NULL;
+      controller_log(DLOG_ERROR, "Function i18n_ustring_copy_au_n() failed with error %d.", ret);
+      return false;
+   }
+
+   return true;
+}
+
+