[Gammu] setlocale and bindtextdomain Functions

Source: Internet
Author: User
These two functions are required for i18n implementation in Linux.
Setlocale is used to set locale, such as lc_all and lc_ctype. The general usage is setlocale (lc_all ,"")
This is used to set lc_all. The second parameter is an empty string that indicates the lc_all value defined in the environment variable.

Then bindtextdomain is used, for example: bindtextdomain ("libgammu", locale_path );
In Linux i18n, each resource file is a. Mo file, which is binary and is generated by a tool for a text file (the performance should be considered for Binary Conversion ). Therefore, in the code above, locale_path specifies a path for the mo file. Generally, if the above Code is called, The gettext library will find the mo file in this place:
/Usr/share/locale-langpack/<locale>/lc_messages/libgammu.mo

In addition, there are textdomain functions, such as textdomain ("gammu "); this function is used to set the text domain to be used currently (bindtextdomain must be used before these text domains so that gettext library can find the mo file ). If our program uses multiple Mo files, bindtextdomain needs to be used multiple times, and then textdomain is used to specify which one needs to be used before. For example, in gammu, The gammu command line program uses the text domain gammu and the libgammu library uses libgammu.mo.

The code for using these two functions in gammu is attached:

Code: select all
#ifdef GETTEXTLIBS_FOUND
void GSM_InitLocales(const char *path) {
   /* setlocale, locale is "" means all locale settings are
      depend on the environment setting. */
   setlocale(LC_ALL, "");
   if (path == NULL || strlen(path) == 0) {
#if defined(LOCALE_PATH)
      bindtextdomain("libgammu", LOCALE_PATH);
#else
      bindtextdomain("libgammu", ".");
#endif
   } else {
      /* bindtextdomain, libgammu is the catalog, path is the
         message file root path. E.g: if path is /usr/share/locale-langpack,
         then all messages represented by gettext will by found in:
         /usr/share/locale-langpack/<locale>/LC_MESSAGES/libgammu.mo
         Refer to manual of bindtextdomain for more details. */
      bindtextdomain("libgammu", path);
   }
}
#else
void GSM_InitLocales(const char UNUSED *path) {
   setlocale(LC_ALL, "");
}
#endif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.