locale.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
  22. void G_init_locale(void)
  23. {
  24. static int initialized;
  25. char localedir[GPATH_MAX];
  26. const char *gisbase;
  27. if (initialized)
  28. return;
  29. initialized = 1;
  30. setlocale(LC_CTYPE, "");
  31. setlocale(LC_MESSAGES, "");
  32. gisbase = getenv("GISBASE");
  33. if (!gisbase || !*gisbase)
  34. return;
  35. strcpy(localedir, gisbase);
  36. strcat(localedir, "/locale");
  37. bindtextdomain("grasslibs", localedir);
  38. bindtextdomain("grassmods", localedir);
  39. }
  40. #endif
  41. /**
  42. * \brief Gets localized text.
  43. *
  44. * \param[in] package
  45. * \param[in] msgid
  46. * \retval char * Pointer to string
  47. */
  48. char *G_gettext(const char *package, const char *msgid)
  49. {
  50. #if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
  51. G_init_locale();
  52. return dgettext(package, msgid);
  53. #else
  54. return (char *)msgid;
  55. #endif
  56. }