File: name_translation.h

package info (click to toggle)
freeciv 2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 212,508 kB
  • sloc: ansic: 443,831; cpp: 29,541; sh: 7,982; makefile: 7,886; python: 1,933; xml: 945
file content (135 lines) | stat: -rw-r--r-- 5,154 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/***********************************************************************
 Freeciv - Copyright (C) 2004 - The Freeciv Project
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
***********************************************************************/

#ifndef FC__NAME_TRANSLATION_H
#define FC__NAME_TRANSLATION_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* utility */
#include "fcintl.h"
#include "support.h"

/* common */
#include "fc_types.h" /* MAX_LEN_NAME */

/* Don't allow other modules to access directly to the fields. */
#define vernacular _private_vernacular_
#define rulename   _private_rulename_
#define translated _private_translated_

/* Ruleset strings (such as names) are kept in their original vernacular
 * as well as being translated to the current locale. */
struct name_translation {
  const char *translated;               /* String doesn't need freeing. */
  char vernacular[MAX_LEN_NAME];        /* Original string,
                                         * used for comparisons. */
  char rulename[MAX_LEN_NAME];          /* Name used in savefiles etc.
                                           Often the same as 'vernacular'. */
};

/* Inititalization macro. */
#define NAME_INIT { NULL, "\0", "\0" }

/****************************************************************************
  Initializes a name translation structure.
****************************************************************************/
static inline void name_init(struct name_translation *ptrans)
{
  ptrans->vernacular[0] = ptrans->rulename[0] = '\0';
  ptrans->translated = NULL;
}

/****************************************************************************
  Set the untranslated and rule names of the name translation structure.
  If rule_name is NULL, use vernacular_name for it (after removing any i18n
  qualifier).
****************************************************************************/
static inline void names_set(struct name_translation *ptrans,
                             const char *domain,
                             const char *vernacular_name,
                             const char *rule_name)
{
  static const char name_too_long[] = "Name \"%s\" too long; truncating.";

  (void) sz_loud_strlcpy(ptrans->vernacular, vernacular_name, name_too_long);
  (void) sz_loud_strlcpy(ptrans->rulename,
                         rule_name ? rule_name : Qn_(vernacular_name),
                         name_too_long);

  if (ptrans->vernacular[0] != '\0') {
    /* Translate now. */
    if (domain == NULL) {
      ptrans->translated = Q_(ptrans->vernacular);
    } else {
      ptrans->translated = skip_intl_qualifier_prefix(DG_(domain, ptrans->vernacular));
    }
  } else {
    ptrans->translated = ptrans->vernacular;
  }
}

/****************************************************************************
  Set the untranslated name of the name translation structure.
  Assumes the rule name should be based on the vernacular.
****************************************************************************/
static inline void name_set(struct name_translation *ptrans,
                            const char *domain,
                            const char *vernacular_name)
{
  names_set(ptrans, domain, vernacular_name, NULL);
}

/****************************************************************************
  Return the untranslated (vernacular) name of the name translation
  structure.
  Rarely used; you usually want name_translation() or rule_name().
  Note that this does not discard any translation qualifiers! -- if this
  string is to be displayed to the user (unlikely), the caller must call
  Qn_() on it.
****************************************************************************/
static inline const char *
    untranslated_name(const struct name_translation *ptrans)
{
  return ptrans->vernacular;
}

/****************************************************************************
  Return the rule name of the name translation structure.
****************************************************************************/
static inline const char *rule_name_get(const struct name_translation *ptrans)
{
  return ptrans->rulename;
}

/****************************************************************************
  Return the translated name of the name translation structure.
****************************************************************************/
static inline const char *
    name_translation_get(const struct name_translation *ptrans)
{
  return ptrans->translated;
}

/* Don't allow other modules to access directly to the fields. */
#undef vernacular
#undef rulename
#undef translated

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* FC__NAME_TRANSLATION_H */