locale.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * \file locale.c
  3. *
  4. * \brief GIS Library - Functions to handle locale.
  5. *
  6. * (C) 2001-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author GRASS GIS Development Team
  12. *
  13. * \date 2004-2008
  14. */
  15. #include <grass/config.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <locale.h>
  19. #include <grass/glocale.h>
  20. #include <grass/gis.h>
  21. void G_init_locale(void)
  22. {
  23. static int initialized;
  24. const char *gisbase;
  25. if (G_is_initialized(&initialized))
  26. return;
  27. setlocale(LC_CTYPE, "");
  28. #if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
  29. #ifdef LC_MESSAGES
  30. setlocale(LC_MESSAGES, "");
  31. #endif
  32. gisbase = getenv("GISBASE");
  33. if (gisbase && *gisbase) {
  34. char localedir[GPATH_MAX];
  35. strcpy(localedir, gisbase);
  36. strcat(localedir, "/locale");
  37. bindtextdomain("grasslibs", localedir);
  38. bindtextdomain("grassmods", localedir);
  39. }
  40. #endif
  41. G_initialize_done(&initialized);
  42. }
  43. /**
  44. * \brief Gets localized text.
  45. *
  46. * \param[in] package
  47. * \param[in] msgid
  48. * \retval char * Pointer to string
  49. */
  50. char *G_gettext(const char *package, const char *msgid)
  51. {
  52. #if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
  53. G_init_locale();
  54. return dgettext(package, msgid);
  55. #else
  56. return (char *)msgid;
  57. #endif
  58. }