Crossfire Server, Trunk  R20513
Data Structures | Typedefs | Functions | Variables
languages.c File Reference
#include "global.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for languages.c:

Go to the source code of this file.

Data Structures

struct  i18n_file
 One available language. More...
 
struct  i18n_message
 One message. More...
 

Typedefs

typedef struct i18n_file i18n_file
 One available language. More...
 
typedef struct i18n_message i18n_message
 One message. More...
 

Functions

static void convert_newline (char *line)
 Replaces '
' by a newline char. More...
 
int get_language (object *op)
 Returns the i18n language index associated with the given object. More...
 
const char * i18n (const object *who, const char *code)
 Translate a message in the appropriate language. More...
 
int i18n_find_language_by_code (const char *code)
 Attenmpt to find the identifier of a language from its code. More...
 
void i18n_free (void)
 Clears all i18n-related data. More...
 
int i18n_get_language_by_code (const char *code)
 Find the identifier of a language from its code. More...
 
sstring i18n_get_language_code (int language)
 Return the code of a specified language. More...
 
void i18n_init (void)
 Initializes the i18n subsystem. More...
 
void i18n_list_languages (object *who)
 List all languages for who. More...
 
static int i18n_message_compare_code (const i18n_message *a, const i18n_message *b)
 

Variables

static int i18n_count = 0
 Number of defined languages. More...
 
static int i18n_default = -1
 Index of "English" in the i18nfiles array. More...
 
static struct i18n_filei18n_files = NULL
 Defined languages. More...
 

Typedef Documentation

typedef struct i18n_file i18n_file

One available language.

typedef struct i18n_message i18n_message

One message.

Function Documentation

static void convert_newline ( char *  line)
static

Replaces '
' by a newline char.

Since we are replacing 2 chars by 1, no overflow should happen.

Parameters
linetext to replace into.

Definition at line 151 of file languages.c.

References MAX_BUF, and snprintf.

Referenced by i18n_init().

Here is the caller graph for this function:

int get_language ( object op)

Returns the i18n language index associated with the given object.

This only has a meaning for players.

Parameters
opThe player object to get the language of
Returns
The language numerical code. If none is associated, get_language returns 0

Definition at line 55 of file languages.c.

References obj::contr, i18n_count, and pl::language.

const char* i18n ( const object who,
const char *  code 
)
int i18n_find_language_by_code ( const char *  code)

Attenmpt to find the identifier of a language from its code.

Parameters
codelanguage code.
Returns
index, -1 if not found.

Definition at line 95 of file languages.c.

References i18n_count.

Referenced by command_language(), and i18n_get_language_by_code().

Here is the caller graph for this function:

void i18n_free ( void  )

Clears all i18n-related data.

Definition at line 252 of file languages.c.

References i18n_message::code, i18n_file::count, free_string(), i18n_count, and i18n_message::message.

Referenced by cleanup().

Here is the call graph for this function:

Here is the caller graph for this function:

int i18n_get_language_by_code ( const char *  code)

Find the identifier of a language from its code.

Parameters
codelanguage's code.
Returns
language's code, or the default language if code is invalid.

Definition at line 110 of file languages.c.

References i18n_default, and i18n_find_language_by_code().

Referenced by check_login().

Here is the call graph for this function:

Here is the caller graph for this function:

sstring i18n_get_language_code ( int  language)

Return the code of a specified language.

Parameters
languageidentifier of the language.
Returns
language's code, or default language's code if identifier is invalid.

Definition at line 122 of file languages.c.

References i18n_file::code, i18n_count, and i18n_default.

Referenced by command_help(), help_topics(), and save_player().

Here is the caller graph for this function:

void i18n_init ( void  )

Initializes the i18n subsystem.

Will load all found strings. If there is an error, calls fatal().

Definition at line 168 of file languages.c.

References add_refcount(), add_string(), closedir(), i18n_message::code, i18n_file::code, convert_newline(), i18n_file::count, dirent::d_name, Settings::datadir, fatal(), free_string(), HUGE_BUF, i18n_count, i18n_default, i18n_message_compare_code(), llevDebug, llevError, LOG(), MAX_BUF, i18n_message::message, i18n_file::messages, i18n_file::name, opendir(), readdir(), SEE_LAST_ERROR, settings, and snprintf.

Referenced by init_library().

Here is the call graph for this function:

Here is the caller graph for this function:

void i18n_list_languages ( object who)

List all languages for who.

Parameters
whowho to display languages for.

Definition at line 132 of file languages.c.

References i18n_message::code, draw_ext_info_format(), i18n_count, MSG_SUBTYPE_NONE, MSG_TYPE_COMMAND, i18n_file::name, and NDI_UNIQUE.

Referenced by command_language().

Here is the call graph for this function:

Here is the caller graph for this function:

static int i18n_message_compare_code ( const i18n_message a,
const i18n_message b 
)
static

Definition at line 45 of file languages.c.

References i18n_message::code.

Referenced by i18n(), and i18n_init().

Here is the caller graph for this function:

Variable Documentation

int i18n_count = 0
static

Number of defined languages.

Definition at line 39 of file languages.c.

Referenced by get_language(), i18n(), i18n_find_language_by_code(), i18n_free(), i18n_get_language_code(), i18n_init(), and i18n_list_languages().

int i18n_default = -1
static

Index of "English" in the i18nfiles array.

Definition at line 43 of file languages.c.

Referenced by i18n_get_language_by_code(), i18n_get_language_code(), and i18n_init().

struct i18n_file* i18n_files = NULL
static

Defined languages.

Definition at line 41 of file languages.c.