1 /***********************************************************************
2  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
17 
18 #include <string.h>
19 
20 /* utility */
21 #include "mem.h"
22 
23 #include "fcintl.h"
24 
25 static bool autocap = FALSE;
26 
27 /**********************************************************************
28 Some strings are ambiguous for translation.  For example, "Game" is
29 something you play (like Freeciv!) or animals that can be hunted.
30 To distinguish strings for translation, we qualify them with a prefix
31 string of the form "?qualifier:".  So, the above two cases might be:
32   "Game"           -- when used as meaning something you play
33   "?animals:Game"  -- when used as animals to be hunted
34 Notice that only the second is qualified; the first is processed in
35 the normal gettext() manner (as at most one ambiguous string can be).
36 
37 This function tests for, and removes if found, the qualifier prefix part
38 of a string.
39 
40 This function is called by the Q_() macro and specenum.  If used in the
41 Q_() macro it should, if NLS is enabled, have called gettext() to get the
42 argument to pass to this function. Specenum use it untranslated.
43 ***********************************************************************/
skip_intl_qualifier_prefix(const char * str)44 const char *skip_intl_qualifier_prefix(const char *str)
45 {
46   const char *ptr;
47 
48   if (*str != '?') {
49     return str;
50   } else if ((ptr = strchr(str, ':'))) {
51     return (ptr + 1);
52   } else {
53     return str;			/* may be something wrong */
54   }
55 }
56 
57 /**********************************************************************
58   This function tries to capitalize first letter of the string.
59   Currently this handles just single byte UTF-8 characters, since
60   those are same as ASCII.
61 ***********************************************************************/
capitalized_string(const char * str)62 char *capitalized_string(const char *str)
63 {
64   int len = strlen(str);
65   char *result = fc_malloc(len + 1);
66 
67   fc_strlcpy(result, str, len + 1);
68 
69   if (autocap) {
70     if ((unsigned char) result[0] < 128) {
71       result[0] = fc_toupper(result[0]);
72     }
73   }
74 
75   return result;
76 }
77 
78 /**********************************************************************
79   Free capitalized string.
80 ***********************************************************************/
free_capitalized(char * str)81 void free_capitalized(char *str)
82 {
83   FC_FREE(str);
84 }
85 
86 /**********************************************************************
87   Translation opts in to automatic capitalization features.
88 ***********************************************************************/
capitalization_opt_in(void)89 void capitalization_opt_in(void)
90 {
91   autocap = TRUE;
92 }
93 
94 /**********************************************************************
95   Automatic capitalization features requested.
96 ***********************************************************************/
is_capitalization_enabled(void)97 bool is_capitalization_enabled(void)
98 {
99   return autocap;
100 }
101 
102 /**********************************************************************
103   Return directory containing locales.
104 ***********************************************************************/
get_locale_dir(void)105 const char *get_locale_dir(void)
106 {
107   return LOCALEDIR;
108 }
109