Greenbone Security Assistant  8.0.0
gsad_i18n.h File Reference

I18n support for Greenbone Security Assistant. More...

#include <glib.h>
Include dependency graph for gsad_i18n.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEFAULT_GSAD_LANGUAGE   "en"
 Default language code, used when Accept-Language header is missing. More...
 

Functions

gchar * accept_language_to_env_fmt (const char *)
 Convert an Accept-Language string to the LANGUAGE env variable form. More...
 

Detailed Description

I18n support for Greenbone Security Assistant.

Definition in file gsad_i18n.h.

Macro Definition Documentation

◆ DEFAULT_GSAD_LANGUAGE

#define DEFAULT_GSAD_LANGUAGE   "en"

Default language code, used when Accept-Language header is missing.

Definition at line 33 of file gsad_i18n.h.

Function Documentation

◆ accept_language_to_env_fmt()

gchar* accept_language_to_env_fmt ( const char *  accept_language)

Convert an Accept-Language string to the LANGUAGE env variable form.

Converts the language preferences as defined in a HTTP Accept-Language header to a colon-separated list of language codes as used by gettext in the LANGUAGE environment variable.

Parameters
[in]accept_languageHTTP Accept-Language header text.
Returns
Newly allocated string of language codes as used by gettext. If accept_language is NULL or it doesn't contain a language DEFAULT_GSAD_LANGUAGE is returned.

Definition at line 62 of file gsad_i18n.c.

63 {
64  if (accept_language == NULL)
65  return g_strdup (DEFAULT_GSAD_LANGUAGE);
66 
67  gchar *language;
68  // TODO: Convert to a colon-separated list of codes instead of
69  // just extracting the first one
70  gchar **prefs, *pref;
71  prefs = g_strsplit_set (accept_language, ",;", -1);
72 
73  pref = prefs[0];
74  if (pref)
75  {
76  char *pos;
77  g_strstrip (pref);
78  pos = pref;
79  while (pos[0] != '\0')
80  {
81  if (pos[0] == '-')
82  pos[0] = '_';
83  pos++;
84  };
85  }
86  language = g_strdup (pref ? pref : DEFAULT_GSAD_LANGUAGE);
87  g_strfreev (prefs);
88 
89  return language;
90 }
#define DEFAULT_GSAD_LANGUAGE
Default language code, used when Accept-Language header is missing.
Definition: gsad_i18n.h:33

References DEFAULT_GSAD_LANGUAGE.

Referenced by handle_gmp_post(), and handle_setup_credentials().

Here is the caller graph for this function: