Multiply AI want for Great Wonders by 1.5
[freeciv.git] / common / name_translation.h
blobeafea8236f957997584b2ae821d4c757f24123d1
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.
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 ***********************************************************************/
14 #ifndef FC__NAME_TRANSLATION_H
15 #define FC__NAME_TRANSLATION_H
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
21 /* utility */
22 #include "fcintl.h"
23 #include "support.h"
25 /* common */
26 #include "fc_types.h" /* MAX_LEN_NAME */
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_
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'. */
43 /* Inititalization macro. */
44 #define NAME_INIT { NULL, "\0", "\0" }
46 /****************************************************************************
47 Initializes a name translation structure.
48 ****************************************************************************/
49 static inline void name_init(struct name_translation *ptrans)
51 ptrans->vernacular[0] = ptrans->rulename[0] = '\0';
52 ptrans->translated = NULL;
55 /****************************************************************************
56 Set the untranslated and rule names of the name translation structure.
57 If rule_name is NULL, use vernacular_name for it (after removing any i18n
58 qualifier).
59 ****************************************************************************/
60 static inline void names_set(struct name_translation *ptrans,
61 const char *domain,
62 const char *vernacular_name,
63 const char *rule_name)
65 static const char name_too_long[] = "Name \"%s\" too long; truncating.";
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);
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));
79 } else {
80 ptrans->translated = ptrans->vernacular;
84 /****************************************************************************
85 Set the untranslated name of the name translation structure.
86 Assumes the rule name should be based on the vernacular.
87 ****************************************************************************/
88 static inline void name_set(struct name_translation *ptrans,
89 const char *domain,
90 const char *vernacular_name)
92 names_set(ptrans, domain, vernacular_name, NULL);
95 /****************************************************************************
96 Return the untranslated (vernacular) name of the name translation
97 structure.
98 Rarely used; you usually want name_translation() or rule_name().
99 Note that this does not discard any translation qualifiers! -- if this
100 string is to be displayed to the user (unlikely), the caller must call
101 Qn_() on it.
102 ****************************************************************************/
103 static inline const char *
104 untranslated_name(const struct name_translation *ptrans)
106 return ptrans->vernacular;
109 /****************************************************************************
110 Return the rule name of the name translation structure.
111 ****************************************************************************/
112 static inline const char *rule_name_get(const struct name_translation *ptrans)
114 return ptrans->rulename;
117 /****************************************************************************
118 Return the translated name of the name translation structure.
119 ****************************************************************************/
120 static inline const char *
121 name_translation_get(const struct name_translation *ptrans)
123 return ptrans->translated;
126 /* Don't allow other modules to access directly to the fields. */
127 #undef vernacular
128 #undef rulename
129 #undef translated
131 #ifdef __cplusplus
133 #endif /* __cplusplus */
135 #endif /* FC__NAME_TRANSLATION_H */