Freeciv-3.3: /fast/freeciv/nightly/main/common/name_translation.h Source File

Freeciv-3.3

Loading...
Searching...
No Matches
name_translation.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifndef FC__NAME_TRANSLATION_H
15#define FC__NAME_TRANSLATION_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21/* utility */
22#include "fcintl.h"
23#include "support.h"
24
25/* common */
26#include "fc_types.h" /* MAX_LEN_NAME */
27
28/* Don't allow other modules to access directly to the fields. */
29#define vernacular _private_vernacular_
30#define rulename _private_rulename_
31#define translated _private_translated_
32
33/* Ruleset strings (such as names) are kept in their original vernacular
34 * as well as being translated to the current locale. */
35 struct name_translation {
36 const char *translated; /* String doesn't need freeing. */
37 char vernacular[MAX_LEN_NAME]; /* Original string,
38 * used for comparisons. */
39 char rulename[MAX_LEN_NAME]; /* Name used in savefiles etc.
40 Often the same as 'vernacular'. */
41};
42
43/* Inititalization macro. */
44#define NAME_INIT { NULL, "\0", "\0" }
45
46/************************************************************************/
49 static inline void name_init(struct name_translation *ptrans)
50{
51 ptrans->vernacular[0] = ptrans->rulename[0] = '\0';
52 ptrans->translated = NULL;
53}
54
55/************************************************************************/
60 static inline void names_set(struct name_translation *ptrans,
61 const char *domain,
62 const char *vernacular_name,
63 const char *rule_name)
64{
65 static const char name_too_long[] = "Name \"%s\" too long; truncating.";
66
67 (void) sz_loud_strlcpy(ptrans->vernacular, vernacular_name, name_too_long);
68 (void) sz_loud_strlcpy(ptrans->rulename,
69 rule_name ? rule_name : Qn_(vernacular_name),
70 name_too_long);
71
72 if (ptrans->vernacular[0] != '\0') {
73 /* Translate now. */
74 if (domain == NULL) {
75 ptrans->translated = Q_(ptrans->vernacular);
76 } else {
77 ptrans->translated = skip_intl_qualifier_prefix(DG_(domain, ptrans->vernacular));
78 }
79 } else {
80 ptrans->translated = ptrans->vernacular;
81 }
82}
83
84/************************************************************************/
88 static inline void name_set(struct name_translation *ptrans,
89 const char *domain,
90 const char *vernacular_name)
91{
92 names_set(ptrans, domain, vernacular_name, NULL);
93}
94
95/************************************************************************/
103static inline const char *
104 untranslated_name(const struct name_translation *ptrans)
105{
106 return ptrans->vernacular;
107}
108
109/************************************************************************/
112 static inline const char *rule_name_get(const struct name_translation *ptrans)
113{
114 return ptrans->rulename;
115}
116
117/************************************************************************/
120static inline const char *
121 name_translation_get(const struct name_translation *ptrans)
122{
123 return ptrans->translated;
124}
125
126/* Don't allow other modules to access directly to the fields. */
127#undef vernacular
128#undef rulename
129#undef translated
130
131#ifdef __cplusplus
132}
133#endif /* __cplusplus */
134
135#endif /* FC__NAME_TRANSLATION_H */
incite_cost
char * incite_cost
Definition comments.c:74
fc_types.h
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
skip_intl_qualifier_prefix
const char * skip_intl_qualifier_prefix(const char *str)
Definition fcintl.c:48
fcintl.h
Q_
#define Q_(String)
Definition fcintl.h:70
DG_
#define DG_(domain, String)
Definition fcintl.h:68
Qn_
#define Qn_(String)
Definition fcintl.h:89
name_set
static void name_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name)
Definition name_translation.h:88
rule_name_get
static const char * rule_name_get(const struct name_translation *ptrans)
Definition name_translation.h:112
name_translation_get
static const char * name_translation_get(const struct name_translation *ptrans)
Definition name_translation.h:121
untranslated_name
static const char * untranslated_name(const struct name_translation *ptrans)
Definition name_translation.h:104
names_set
static void names_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name, const char *rule_name)
Definition name_translation.h:60
name_init
static void name_init(struct name_translation *ptrans)
Definition name_translation.h:49
name_too_long
static const char name_too_long[]
Definition ruleload.c:119
sz_loud_strlcpy
#define sz_loud_strlcpy(buffer, str, errmsg)
Definition shared.h:155
name_translation
Definition name_translation.h:35
name_translation::vernacular
char vernacular[MAX_LEN_NAME]
Definition name_translation.h:37
name_translation::translated
const char * translated
Definition name_translation.h:36
name_translation::rulename
char rulename[MAX_LEN_NAME]
Definition name_translation.h:39
support.h