Freeciv-3.2
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. */
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/************************************************************************/
49static inline void name_init(struct name_translation *ptrans)
50{
51 ptrans->vernacular[0] = ptrans->rulename[0] = '\0';
52 ptrans->translated = NULL;
53}
54
55/************************************************************************/
60static 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
68 (void) sz_loud_strlcpy(ptrans->rulename,
69 rule_name ? rule_name : Qn_(vernacular_name),
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/************************************************************************/
88static inline void name_set(struct name_translation *ptrans,
89 const char *domain,
90 const char *vernacular_name)
91{
93}
94
95/************************************************************************/
103static inline const char *
105{
106 return ptrans->vernacular;
107}
108
109/************************************************************************/
112static inline const char *rule_name_get(const struct name_translation *ptrans)
113{
114 return ptrans->rulename;
115}
116
117/************************************************************************/
120static inline const char *
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 */
char * incite_cost
Definition comments.c:75
#define MAX_LEN_NAME
Definition fc_types.h:66
const char * skip_intl_qualifier_prefix(const char *str)
Definition fcintl.c:48
#define Q_(String)
Definition fcintl.h:70
#define DG_(domain, String)
Definition fcintl.h:68
#define Qn_(String)
Definition fcintl.h:89
static void name_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name)
static const char * rule_name_get(const struct name_translation *ptrans)
static const char * name_translation_get(const struct name_translation *ptrans)
static const char * untranslated_name(const struct name_translation *ptrans)
static void names_set(struct name_translation *ptrans, const char *domain, const char *vernacular_name, const char *rule_name)
static void name_init(struct name_translation *ptrans)
static const char name_too_long[]
Definition ruleset.c:119
#define sz_loud_strlcpy(buffer, str, errmsg)
Definition shared.h:155
char vernacular[MAX_LEN_NAME]
const char * translated
char rulename[MAX_LEN_NAME]