Blame glib/ggettext.c

Packit ae235b
/* GLIB - Library of useful routines for C programming
Packit ae235b
 * Copyright (C) 1995-1998  Peter Mattis, Spencer Kimball and Josh MacDonald
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public
Packit ae235b
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/*
Packit ae235b
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
Packit ae235b
 * file for a list of people on the GLib Team.  See the ChangeLog
Packit ae235b
 * files for a list of changes.  These files are distributed with
Packit ae235b
 * GLib at ftp://ftp.gtk.org/pub/gtk/. 
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include "ggettext.h"
Packit ae235b
#include "glibintl.h"
Packit ae235b
#include "glib-private.h"
Packit ae235b
Packit ae235b
#include "galloca.h"
Packit ae235b
#include "gthread.h"
Packit ae235b
#include "gmem.h"
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
#include "gwin32.h"
Packit ae235b
#include "gfileutils.h"
Packit ae235b
#include "gstrfuncs.h"
Packit ae235b
#include "glib-init.h"
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#include <string.h>
Packit ae235b
#include <locale.h>
Packit ae235b
#include <libintl.h>
Packit ae235b
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * _glib_get_locale_dir:
Packit ae235b
 *
Packit ae235b
 * Return the path to the share\locale or lib\locale subfolder of the
Packit ae235b
 * GLib installation folder. The path is in the system codepage. We
Packit ae235b
 * have to use system codepage as bindtextdomain() doesn't have a
Packit ae235b
 * UTF-8 interface.
Packit ae235b
 */
Packit ae235b
gchar *
Packit ae235b
_glib_get_locale_dir (void)
Packit ae235b
{
Packit ae235b
  gchar *install_dir = NULL, *locale_dir;
Packit ae235b
  gchar *retval = NULL;
Packit ae235b
Packit ae235b
  if (glib_dll != NULL)
Packit ae235b
    install_dir = g_win32_get_package_installation_directory_of_module (glib_dll);
Packit ae235b
Packit ae235b
  if (install_dir)
Packit ae235b
    {
Packit ae235b
      /*
Packit ae235b
       * Append "/share/locale" or "/lib/locale" depending on whether
Packit ae235b
       * autoconfigury detected GNU gettext or not.
Packit ae235b
       */
Packit ae235b
      const char *p = GLIB_LOCALE_DIR + strlen (GLIB_LOCALE_DIR);
Packit ae235b
      while (*--p != '/')
Packit ae235b
	;
Packit ae235b
      while (*--p != '/')
Packit ae235b
	;
Packit ae235b
Packit ae235b
      locale_dir = g_build_filename (install_dir, p, NULL);
Packit ae235b
Packit ae235b
      retval = g_win32_locale_filename_from_utf8 (locale_dir);
Packit ae235b
Packit ae235b
      g_free (install_dir);
Packit ae235b
      g_free (locale_dir);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (retval)
Packit ae235b
    return retval;
Packit ae235b
  else
Packit ae235b
    return g_strdup ("");
Packit ae235b
}
Packit ae235b
Packit ae235b
#undef GLIB_LOCALE_DIR
Packit ae235b
Packit ae235b
#endif /* G_OS_WIN32 */
Packit ae235b
Packit ae235b
Packit ae235b
static void
Packit ae235b
ensure_gettext_initialized (void)
Packit ae235b
{
Packit ae235b
  static gsize initialised;
Packit ae235b
Packit ae235b
  if (g_once_init_enter (&initialised))
Packit ae235b
    {
Packit ae235b
#ifdef G_OS_WIN32
Packit ae235b
      gchar *tmp = _glib_get_locale_dir ();
Packit ae235b
      bindtextdomain (GETTEXT_PACKAGE, tmp);
Packit ae235b
      g_free (tmp);
Packit ae235b
#else
Packit ae235b
      bindtextdomain (GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
Packit ae235b
#endif
Packit ae235b
#    ifdef HAVE_BIND_TEXTDOMAIN_CODESET
Packit ae235b
      bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
Packit ae235b
#    endif
Packit ae235b
      g_once_init_leave (&initialised, TRUE);
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * glib_gettext:
Packit ae235b
 * @str: The string to be translated
Packit ae235b
 *
Packit ae235b
 * Returns the translated string from the glib translations.
Packit ae235b
 * This is an internal function and should only be used by
Packit ae235b
 * the internals of glib (such as libgio).
Packit ae235b
 *
Packit ae235b
 * Returns: the transation of @str to the current locale
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
glib_gettext (const gchar *str)
Packit ae235b
{
Packit ae235b
  ensure_gettext_initialized ();
Packit ae235b
Packit ae235b
  return g_dgettext (GETTEXT_PACKAGE, str);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * glib_pgettext:
Packit ae235b
 * @msgctxtid: a combined message context and message id, separated
Packit ae235b
 *   by a \004 character
Packit ae235b
 * @msgidoffset: the offset of the message id in @msgctxid
Packit ae235b
 *
Packit ae235b
 * This function is a variant of glib_gettext() which supports
Packit ae235b
 * a disambiguating message context. See g_dpgettext() for full
Packit ae235b
 * details.
Packit ae235b
 *
Packit ae235b
 * This is an internal function and should only be used by
Packit ae235b
 * the internals of glib (such as libgio).
Packit ae235b
 *
Packit ae235b
 * Returns: the translation of @str to the current locale
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
glib_pgettext (const gchar *msgctxtid,
Packit ae235b
               gsize        msgidoffset)
Packit ae235b
{
Packit ae235b
  ensure_gettext_initialized ();
Packit ae235b
Packit ae235b
  return g_dpgettext (GETTEXT_PACKAGE, msgctxtid, msgidoffset);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_strip_context:
Packit ae235b
 * @msgid: a string
Packit ae235b
 * @msgval: another string
Packit ae235b
 *
Packit ae235b
 * An auxiliary function for gettext() support (see Q_()).
Packit ae235b
 *
Packit ae235b
 * Returns: @msgval, unless @msgval is identical to @msgid
Packit ae235b
 *     and contains a '|' character, in which case a pointer to
Packit ae235b
 *     the substring of msgid after the first '|' character is returned.
Packit ae235b
 *
Packit ae235b
 * Since: 2.4
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_strip_context (const gchar *msgid,
Packit ae235b
                 const gchar *msgval)
Packit ae235b
{
Packit ae235b
  if (msgval == msgid)
Packit ae235b
    {
Packit ae235b
      const char *c = strchr (msgid, '|');
Packit ae235b
      if (c != NULL)
Packit ae235b
        return c + 1;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return msgval;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dpgettext:
Packit ae235b
 * @domain: (nullable): the translation domain to use, or %NULL to use
Packit ae235b
 *   the domain set with textdomain()
Packit ae235b
 * @msgctxtid: a combined message context and message id, separated
Packit ae235b
 *   by a \004 character
Packit ae235b
 * @msgidoffset: the offset of the message id in @msgctxid
Packit ae235b
 *
Packit ae235b
 * This function is a variant of g_dgettext() which supports
Packit ae235b
 * a disambiguating message context. GNU gettext uses the
Packit ae235b
 * '\004' character to separate the message context and
Packit ae235b
 * message id in @msgctxtid.
Packit ae235b
 * If 0 is passed as @msgidoffset, this function will fall back to
Packit ae235b
 * trying to use the deprecated convention of using "|" as a separation
Packit ae235b
 * character.
Packit ae235b
 *
Packit ae235b
 * This uses g_dgettext() internally. See that functions for differences
Packit ae235b
 * with dgettext() proper.
Packit ae235b
 *
Packit ae235b
 * Applications should normally not use this function directly,
Packit ae235b
 * but use the C_() macro for translations with context.
Packit ae235b
 *
Packit ae235b
 * Returns: The translated string
Packit ae235b
 *
Packit ae235b
 * Since: 2.16
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dpgettext (const gchar *domain,
Packit ae235b
             const gchar *msgctxtid,
Packit ae235b
             gsize        msgidoffset)
Packit ae235b
{
Packit ae235b
  const gchar *translation;
Packit ae235b
  gchar *sep;
Packit ae235b
Packit ae235b
  translation = g_dgettext (domain, msgctxtid);
Packit ae235b
Packit ae235b
  if (translation == msgctxtid)
Packit ae235b
    {
Packit ae235b
      if (msgidoffset > 0)
Packit ae235b
        return msgctxtid + msgidoffset;
Packit ae235b
      sep = strchr (msgctxtid, '|');
Packit ae235b
Packit ae235b
      if (sep)
Packit ae235b
        {
Packit ae235b
          /* try with '\004' instead of '|', in case
Packit ae235b
           * xgettext -kQ_:1g was used
Packit ae235b
           */
Packit ae235b
          gchar *tmp = g_alloca (strlen (msgctxtid) + 1);
Packit ae235b
          strcpy (tmp, msgctxtid);
Packit ae235b
          tmp[sep - msgctxtid] = '\004';
Packit ae235b
Packit ae235b
          translation = g_dgettext (domain, tmp);
Packit ae235b
Packit ae235b
          if (translation == tmp)
Packit ae235b
            return sep + 1;
Packit ae235b
        }
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return translation;
Packit ae235b
}
Packit ae235b
Packit ae235b
/* This function is taken from gettext.h
Packit ae235b
 * GNU gettext uses '\004' to separate context and msgid in .mo files.
Packit ae235b
 */
Packit ae235b
/**
Packit ae235b
 * g_dpgettext2:
Packit ae235b
 * @domain: (nullable): the translation domain to use, or %NULL to use
Packit ae235b
 *   the domain set with textdomain()
Packit ae235b
 * @context: the message context
Packit ae235b
 * @msgid: the message
Packit ae235b
 *
Packit ae235b
 * This function is a variant of g_dgettext() which supports
Packit ae235b
 * a disambiguating message context. GNU gettext uses the
Packit ae235b
 * '\004' character to separate the message context and
Packit ae235b
 * message id in @msgctxtid.
Packit ae235b
 *
Packit ae235b
 * This uses g_dgettext() internally. See that functions for differences
Packit ae235b
 * with dgettext() proper.
Packit ae235b
 *
Packit ae235b
 * This function differs from C_() in that it is not a macro and
Packit ae235b
 * thus you may use non-string-literals as context and msgid arguments.
Packit ae235b
 *
Packit ae235b
 * Returns: The translated string
Packit ae235b
 *
Packit ae235b
 * Since: 2.18
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dpgettext2 (const gchar *domain,
Packit ae235b
              const gchar *msgctxt,
Packit ae235b
              const gchar *msgid)
Packit ae235b
{
Packit ae235b
  size_t msgctxt_len = strlen (msgctxt) + 1;
Packit ae235b
  size_t msgid_len = strlen (msgid) + 1;
Packit ae235b
  const char *translation;
Packit ae235b
  char* msg_ctxt_id;
Packit ae235b
Packit ae235b
  msg_ctxt_id = g_alloca (msgctxt_len + msgid_len);
Packit ae235b
Packit ae235b
  memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
Packit ae235b
  msg_ctxt_id[msgctxt_len - 1] = '\004';
Packit ae235b
  memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
Packit ae235b
Packit ae235b
  translation = g_dgettext (domain, msg_ctxt_id);
Packit ae235b
Packit ae235b
  if (translation == msg_ctxt_id)
Packit ae235b
    {
Packit ae235b
      /* try the old way of doing message contexts, too */
Packit ae235b
      msg_ctxt_id[msgctxt_len - 1] = '|';
Packit ae235b
      translation = g_dgettext (domain, msg_ctxt_id);
Packit ae235b
Packit ae235b
      if (translation == msg_ctxt_id)
Packit ae235b
        return msgid;
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return translation;
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
_g_dgettext_should_translate (void)
Packit ae235b
{
Packit ae235b
  static gsize translate = 0;
Packit ae235b
  enum {
Packit ae235b
    SHOULD_TRANSLATE = 1,
Packit ae235b
    SHOULD_NOT_TRANSLATE = 2
Packit ae235b
  };
Packit ae235b
Packit ae235b
  if (G_UNLIKELY (g_once_init_enter (&translate)))
Packit ae235b
    {
Packit ae235b
      gboolean should_translate = TRUE;
Packit ae235b
Packit ae235b
      const char *default_domain     = textdomain (NULL);
Packit ae235b
      const char *translator_comment = gettext ("");
Packit ae235b
#ifndef G_OS_WIN32
Packit ae235b
      const char *translate_locale   = setlocale (LC_MESSAGES, NULL);
Packit ae235b
#else
Packit ae235b
      const char *translate_locale   = g_win32_getlocale ();
Packit ae235b
#endif
Packit ae235b
      /* We should NOT translate only if all the following hold:
Packit ae235b
       *   - user has called textdomain() and set textdomain to non-default
Packit ae235b
       *   - default domain has no translations
Packit ae235b
       *   - locale does not start with "en_" and is not "C"
Packit ae235b
       *
Packit ae235b
       * Rationale:
Packit ae235b
       *   - If text domain is still the default domain, maybe user calls
Packit ae235b
       *     it later. Continue with old behavior of translating.
Packit ae235b
       *   - If locale starts with "en_", we can continue using the
Packit ae235b
       *     translations even if the app doesn't have translations for
Packit ae235b
       *     this locale.  That is, en_UK and en_CA for example.
Packit ae235b
       *   - If locale is "C", maybe user calls setlocale(LC_ALL,"") later.
Packit ae235b
       *     Continue with old behavior of translating.
Packit ae235b
       */
Packit ae235b
      if (!default_domain || !translator_comment || !translate_locale ||
Packit ae235b
          (0 != strcmp (default_domain, "messages") &&
Packit ae235b
          '\0' == *translator_comment &&
Packit ae235b
          0 != strncmp (translate_locale, "en_", 3) &&
Packit ae235b
          0 != strcmp (translate_locale, "C")))
Packit ae235b
        should_translate = FALSE;
Packit ae235b
Packit ae235b
      g_once_init_leave (&translate,
Packit ae235b
                         should_translate ?
Packit ae235b
                         SHOULD_TRANSLATE :
Packit ae235b
                         SHOULD_NOT_TRANSLATE);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  return translate == SHOULD_TRANSLATE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dgettext:
Packit ae235b
 * @domain: (nullable): the translation domain to use, or %NULL to use
Packit ae235b
 *   the domain set with textdomain()
Packit ae235b
 * @msgid: message to translate
Packit ae235b
 *
Packit ae235b
 * This function is a wrapper of dgettext() which does not translate
Packit ae235b
 * the message if the default domain as set with textdomain() has no
Packit ae235b
 * translations for the current locale.
Packit ae235b
 *
Packit ae235b
 * The advantage of using this function over dgettext() proper is that
Packit ae235b
 * libraries using this function (like GTK+) will not use translations
Packit ae235b
 * if the application using the library does not have translations for
Packit ae235b
 * the current locale.  This results in a consistent English-only
Packit ae235b
 * interface instead of one having partial translations.  For this
Packit ae235b
 * feature to work, the call to textdomain() and setlocale() should
Packit ae235b
 * precede any g_dgettext() invocations.  For GTK+, it means calling
Packit ae235b
 * textdomain() before gtk_init or its variants.
Packit ae235b
 *
Packit ae235b
 * This function disables translations if and only if upon its first
Packit ae235b
 * call all the following conditions hold:
Packit ae235b
 * 
Packit ae235b
 * - @domain is not %NULL
Packit ae235b
 *
Packit ae235b
 * - textdomain() has been called to set a default text domain
Packit ae235b
 *
Packit ae235b
 * - there is no translations available for the default text domain
Packit ae235b
 *   and the current locale
Packit ae235b
 *
Packit ae235b
 * - current locale is not "C" or any English locales (those
Packit ae235b
 *   starting with "en_")
Packit ae235b
 *
Packit ae235b
 * Note that this behavior may not be desired for example if an application
Packit ae235b
 * has its untranslated messages in a language other than English. In those
Packit ae235b
 * cases the application should call textdomain() after initializing GTK+.
Packit ae235b
 *
Packit ae235b
 * Applications should normally not use this function directly,
Packit ae235b
 * but use the _() macro for translations.
Packit ae235b
 *
Packit ae235b
 * Returns: The translated string
Packit ae235b
 *
Packit ae235b
 * Since: 2.18
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dgettext (const gchar *domain,
Packit ae235b
            const gchar *msgid)
Packit ae235b
{
Packit ae235b
  if (domain && G_UNLIKELY (!_g_dgettext_should_translate ()))
Packit ae235b
    return msgid;
Packit ae235b
Packit ae235b
  return dgettext (domain, msgid);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dcgettext:
Packit ae235b
 * @domain: (nullable): the translation domain to use, or %NULL to use
Packit ae235b
 *   the domain set with textdomain()
Packit ae235b
 * @msgid: message to translate
Packit ae235b
 * @category: a locale category
Packit ae235b
 *
Packit ae235b
 * This is a variant of g_dgettext() that allows specifying a locale
Packit ae235b
 * category instead of always using `LC_MESSAGES`. See g_dgettext() for
Packit ae235b
 * more information about how this functions differs from calling
Packit ae235b
 * dcgettext() directly.
Packit ae235b
 *
Packit ae235b
 * Returns: the translated string for the given locale category
Packit ae235b
 *
Packit ae235b
 * Since: 2.26
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dcgettext (const gchar *domain,
Packit ae235b
             const gchar *msgid,
Packit ae235b
             gint         category)
Packit ae235b
{
Packit ae235b
  if (domain && G_UNLIKELY (!_g_dgettext_should_translate ()))
Packit ae235b
    return msgid;
Packit ae235b
Packit ae235b
  return dcgettext (domain, msgid, category);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_dngettext:
Packit ae235b
 * @domain: (nullable): the translation domain to use, or %NULL to use
Packit ae235b
 *   the domain set with textdomain()
Packit ae235b
 * @msgid: message to translate
Packit ae235b
 * @msgid_plural: plural form of the message
Packit ae235b
 * @n: the quantity for which translation is needed
Packit ae235b
 *
Packit ae235b
 * This function is a wrapper of dngettext() which does not translate
Packit ae235b
 * the message if the default domain as set with textdomain() has no
Packit ae235b
 * translations for the current locale.
Packit ae235b
 *
Packit ae235b
 * See g_dgettext() for details of how this differs from dngettext()
Packit ae235b
 * proper.
Packit ae235b
 *
Packit ae235b
 * Returns: The translated string
Packit ae235b
 *
Packit ae235b
 * Since: 2.18
Packit ae235b
 */
Packit ae235b
const gchar *
Packit ae235b
g_dngettext (const gchar *domain,
Packit ae235b
             const gchar *msgid,
Packit ae235b
             const gchar *msgid_plural,
Packit ae235b
             gulong       n)
Packit ae235b
{
Packit ae235b
  if (domain && G_UNLIKELY (!_g_dgettext_should_translate ()))
Packit ae235b
    return n == 1 ? msgid : msgid_plural;
Packit ae235b
Packit ae235b
  return dngettext (domain, msgid, msgid_plural, n);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:i18n
Packit ae235b
 * @title: Internationalization
Packit ae235b
 * @short_description: gettext support macros
Packit ae235b
 * @see_also: the gettext manual
Packit ae235b
 *
Packit ae235b
 * GLib doesn't force any particular localization method upon its users.
Packit ae235b
 * But since GLib itself is localized using the gettext() mechanism, it seems
Packit ae235b
 * natural to offer the de-facto standard gettext() support macros in an
Packit ae235b
 * easy-to-use form.
Packit ae235b
 *
Packit ae235b
 * In order to use these macros in an application, you must include
Packit ae235b
 * `<glib/gi18n.h>`. For use in a library, you must include
Packit ae235b
 * `<glib/gi18n-lib.h>`
Packit ae235b
 * after defining the %GETTEXT_PACKAGE macro suitably for your library:
Packit ae235b
 * |[
Packit ae235b
 * #define GETTEXT_PACKAGE "gtk20"
Packit ae235b
 * #include <glib/gi18n-lib.h>
Packit ae235b
 * ]|
Packit ae235b
 * For an application, note that you also have to call bindtextdomain(),
Packit ae235b
 * bind_textdomain_codeset(), textdomain() and setlocale() early on in your
Packit ae235b
 * main() to make gettext() work. For example:
Packit ae235b
 * |[
Packit ae235b
 * #include <glib/gi18n.h>
Packit ae235b
 * #include <locale.h>
Packit ae235b
 *
Packit ae235b
 * int
Packit ae235b
 * main (int argc, char **argv)
Packit ae235b
 * {
Packit ae235b
 *   setlocale (LC_ALL, "");
Packit ae235b
 *   bindtextdomain (GETTEXT_PACKAGE, DATADIR "/locale");
Packit ae235b
 *   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
Packit ae235b
 *   textdomain (GETTEXT_PACKAGE);
Packit ae235b
 *
Packit ae235b
 *   // Rest of your application.
Packit ae235b
 * }
Packit ae235b
 * ]|
Packit ae235b
 * where `DATADIR` is as typically provided by automake.
Packit ae235b
 *
Packit ae235b
 * For a library, you only have to call bindtextdomain() and
Packit ae235b
 * bind_textdomain_codeset() in your initialization function. If your library
Packit ae235b
 * doesn't have an initialization function, you can call the functions before
Packit ae235b
 * the first translated message.
Packit ae235b
 *
Packit ae235b
 * The
Packit ae235b
 * [gettext manual](http://www.gnu.org/software/gettext/manual/gettext.html#Maintainers)
Packit ae235b
 * covers details of how to integrate gettext into a project’s build system and
Packit ae235b
 * workflow.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * _:
Packit ae235b
 * @String: the string to be translated
Packit ae235b
 *
Packit ae235b
 * Marks a string for translation, gets replaced with the translated string
Packit ae235b
 * at runtime.
Packit ae235b
 *
Packit ae235b
 * Since: 2.4
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * Q_:
Packit ae235b
 * @String: the string to be translated, with a '|'-separated prefix
Packit ae235b
 *     which must not be translated
Packit ae235b
 *
Packit ae235b
 * Like _(), but handles context in message ids. This has the advantage
Packit ae235b
 * that the string can be adorned with a prefix to guarantee uniqueness
Packit ae235b
 * and provide context to the translator.
Packit ae235b
 *
Packit ae235b
 * One use case given in the gettext manual is GUI translation, where one
Packit ae235b
 * could e.g. disambiguate two "Open" menu entries as "File|Open" and
Packit ae235b
 * "Printer|Open". Another use case is the string "Russian" which may
Packit ae235b
 * have to be translated differently depending on whether it's the name
Packit ae235b
 * of a character set or a language. This could be solved by using
Packit ae235b
 * "charset|Russian" and "language|Russian".
Packit ae235b
 *
Packit ae235b
 * See the C_() macro for a different way to mark up translatable strings
Packit ae235b
 * with context.
Packit ae235b
 *
Packit ae235b
 * If you are using the Q_() macro, you need to make sure that you pass
Packit ae235b
 * `--keyword=Q_` to xgettext when extracting messages.
Packit ae235b
 * If you are using GNU gettext >= 0.15, you can also use
Packit ae235b
 * `--keyword=Q_:1g` to let xgettext split the context
Packit ae235b
 * string off into a msgctxt line in the po file.
Packit ae235b
 *
Packit ae235b
 * Returns: the translated message
Packit ae235b
 *
Packit ae235b
 * Since: 2.4
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * C_:
Packit ae235b
 * @Context: a message context, must be a string literal
Packit ae235b
 * @String: a message id, must be a string literal
Packit ae235b
 *
Packit ae235b
 * Uses gettext to get the translation for @String. @Context is
Packit ae235b
 * used as a context. This is mainly useful for short strings which
Packit ae235b
 * may need different translations, depending on the context in which
Packit ae235b
 * they are used.
Packit ae235b
 * |[
Packit ae235b
 * label1 = C_("Navigation", "Back");
Packit ae235b
 * label2 = C_("Body part", "Back");
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * If you are using the C_() macro, you need to make sure that you pass
Packit ae235b
 * `--keyword=C_:1c,2` to xgettext when extracting messages.
Packit ae235b
 * Note that this only works with GNU gettext >= 0.15.
Packit ae235b
 *
Packit ae235b
 * Returns: the translated message
Packit ae235b
 *
Packit ae235b
 * Since: 2.16
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * N_:
Packit ae235b
 * @String: the string to be translated
Packit ae235b
 *
Packit ae235b
 * Only marks a string for translation. This is useful in situations
Packit ae235b
 * where the translated strings can't be directly used, e.g. in string
Packit ae235b
 * array initializers. To get the translated string, call gettext()
Packit ae235b
 * at runtime.
Packit ae235b
 * |[
Packit ae235b
 * {
Packit ae235b
 *   static const char *messages[] = {
Packit ae235b
 *     N_("some very meaningful message"),
Packit ae235b
 *     N_("and another one")
Packit ae235b
 *   };
Packit ae235b
 *   const char *string;
Packit ae235b
 *   ...
Packit ae235b
 *   string
Packit ae235b
 *     = index > 1 ? _("a default message") : gettext (messages[index]);
Packit ae235b
 *
Packit ae235b
 *   fputs (string);
Packit ae235b
 *   ...
Packit ae235b
 * }
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * Since: 2.4
Packit ae235b
 */
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * NC_:
Packit ae235b
 * @Context: a message context, must be a string literal
Packit ae235b
 * @String: a message id, must be a string literal
Packit ae235b
 *
Packit ae235b
 * Only marks a string for translation, with context.
Packit ae235b
 * This is useful in situations where the translated strings can't
Packit ae235b
 * be directly used, e.g. in string array initializers. To get the
Packit ae235b
 * translated string, you should call g_dpgettext2() at runtime.
Packit ae235b
 *
Packit ae235b
 * |[
Packit ae235b
 * {
Packit ae235b
 *   static const char *messages[] = {
Packit ae235b
 *     NC_("some context", "some very meaningful message"),
Packit ae235b
 *     NC_("some context", "and another one")
Packit ae235b
 *   };
Packit ae235b
 *   const char *string;
Packit ae235b
 *   ...
Packit ae235b
 *   string
Packit ae235b
 *     = index > 1 ? g_dpgettext2 (NULL, "some context", "a default message")
Packit ae235b
 *                 : g_dpgettext2 (NULL, "some context", messages[index]);
Packit ae235b
 *
Packit ae235b
 *   fputs (string);
Packit ae235b
 *   ...
Packit ae235b
 * }
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * If you are using the NC_() macro, you need to make sure that you pass
Packit ae235b
 * `--keyword=NC_:1c,2` to xgettext when extracting messages.
Packit ae235b
 * Note that this only works with GNU gettext >= 0.15. Intltool has support
Packit ae235b
 * for the NC_() macro since version 0.40.1.
Packit ae235b
 *
Packit ae235b
 * Since: 2.18
Packit ae235b
 */
Packit ae235b