<h3 id="model">Model</h3>
+ <p>
+ 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.
+ <br>
+ One of the functions implemented within the "Model" module was briefly described in the <a href="#global-lang-ch">Handling global language change</a> section
+ (<span style="font-family: Courier New,Courier,monospace">model_get_locale_language()</span>). Other functions are presented here.
+ </p>
+
+ <p>
+ The <span style="font-family: Courier New,Courier,monospace">model_get_available_locale()</span> function is responsible for enumerating all languages with respect to their localization information.
+ For each localization code, the callback function of <span style="font-family: Courier New,Courier,monospace">get_available_locale_cb</span> type is called.
+ </p>
+
+<pre class="prettyprint">
+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;
+}
+</pre>
+
+ <p>
+ The <span style="font-family: Courier New,Courier,monospace">model_get_locale_display_language()</span> function is responsible for obtaining the readable display language name based on
+ its localization code.
+ </p>
+
+<pre class="prettyprint">
+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;
+}
+</pre>
+
<script type="text/javascript" src="../scripts/jquery.zclip.min.js"></script>
<script type="text/javascript" src="../scripts/showhide.js"></script>
</div></div></div>