FS2_Open
Open source remastering of the Freespace 2 engine
localize.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef __FREESPACE2_LOCALIZATION_UTILITIES_HEADER_FILE
13 #define __FREESPACE2_LOCALIZATION_UTILITIES_HEADER_FILE
14 
15 #include "globalincs/pstypes.h"
16 #include "graphics/font.h"
17 
18 // ------------------------------------------------------------------------------------------------------------
19 // LOCALIZE DEFINES/VARS
20 //
21 
22 // language defines
23 #define LCL_ENGLISH 0
24 #define LCL_GERMAN 1
25 #define LCL_FRENCH 2
26 #define LCL_POLISH 3
27 
28 #define FS2_OPEN_DEFAULT_LANGUAGE 0
29 
30 // for language name strings
31 #define LCL_LANG_NAME_LEN 32
32 
33 // language info table
34 typedef struct lang_info {
35  char lang_name[LCL_LANG_NAME_LEN + 1]; // literal name of the language
36  char lang_ext[LCL_LANG_NAME_LEN + 1]; // the extension used for adding to names on disk access
37  ubyte special_char_indexes[MAX_FONTS]; // where in the font do we have the special characters for this language
38  // note: treats 0 as "none" since a zero offset in a font makes no sense
39  // i.e. all the normal chars start at zero
40  int checksum; // used for language auto-detection
41 } lang_info;
42 
43 // These are the original languages supported by FS2. The code expects these languages to be supported even if the tables don't
44 #define NUM_BUILTIN_LANGUAGES 4
46 
48 
49 // following is the offset where special characters start in our font
50 extern int Lcl_special_chars;
51 
52 // use these to replace *_BUILD values
53 // only 1 will be active at a time
54 extern int Lcl_fr;
55 extern int Lcl_gr;
56 extern int Lcl_pl;
57 extern int Lcl_english;
58 
59 
60 // ------------------------------------------------------------------------------------------------------------
61 // LOCALIZE FUNCTIONS
62 //
63 
64 // initialize localization, if no language is passed - use the language specified in the registry
65 void lcl_init(int lang = -1);
66 
67 // shutdown localization
68 void lcl_close();
69 
70 // initialize the xstr table
71 void lcl_xstr_init();
72 
73 // free the xstr table
74 void lcl_xstr_close();
75 
76 // determine what language we're running in, see LCL_* defines above
77 int lcl_get_language();
78 
79 // returns the current language character string
80 void lcl_get_language_name(char *lang_name);
81 
82 // set our current language
83 void lcl_set_language(int lang);
84 
85 // get a fonts special characters index
86 ubyte lcl_get_font_index(int font_num);
87 
88 // NOTE : generally you should only care about the above functions. Below are very low level functions
89 // which should already be well entrenched in FreeSpace. If you think you need to use one of the below
90 // functions - ask first :)
91 // externalization of table/mission files (only parse routines ever need to deal with these functions) -----------------------
92 
93 // maybe add on an appropriate subdirectory when opening a localized file
94 void lcl_add_dir(char *current_path);
95 
96 // maybe add localized directory to full path with file name when opening a localized file
97 int lcl_add_dir_to_path_with_filename(char *current_path, size_t path_max);
98 
99 // Goober5000
100 void lcl_replace_stuff(char *text, size_t max_len);
101 void lcl_replace_stuff(SCP_string &text);
102 
103 // Karajorma
104 void lcl_fred_replace_stuff(char *text, size_t max_len);
106 
107 // get the localized version of the string. if none exists, return the original string
108 // valid input to this function includes :
109 // "this is some text"
110 // XSTR("wheeee", -1)
111 // XSTR("whee", 20)
112 // and these should cover all the externalized string cases
113 // fills in id if non-NULL. a value of -2 indicates it is not an external string
114 void lcl_ext_localize(const char *in, char *out, size_t max_len, int *id = NULL);
115 void lcl_ext_localize(const SCP_string &in, SCP_string &out, int *id = NULL);
116 
117 // translate the specified string based upon the current language
118 const char *XSTR(const char *str, int index);
119 int lcl_get_xstr_offset(int index, int res);
120 
121 void lcl_translate_wep_name_gr(char *name);
122 void lcl_translate_ship_name_gr(char *name);
129 
130 #endif // defined __FREESPACE2_LOCALIZATION_UTILITIES_HEADER_FILE
int Lcl_special_chars
Definition: localize.cpp:43
void lcl_get_language_name(char *lang_name)
Definition: localize.cpp:1121
GLuint index
Definition: Glext.h:5608
void lcl_xstr_init()
Definition: localize.cpp:408
ubyte special_char_indexes[MAX_FONTS]
Definition: localize.h:37
char lang_name[LCL_LANG_NAME_LEN+1]
Definition: localize.h:35
void lcl_translate_targetbox_name_pl(char *name)
Definition: localize.cpp:1453
int Lcl_gr
Definition: localize.cpp:48
int checksum
Definition: localize.h:40
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
void lcl_translate_ship_name_gr(char *name)
Definition: localize.cpp:1388
GLuint in
Definition: Glext.h:9087
int Lcl_fr
Definition: localize.cpp:47
#define NUM_BUILTIN_LANGUAGES
Definition: localize.h:44
void lcl_translate_medal_name_gr(char *name)
Definition: localize.cpp:1502
void lcl_translate_targetbox_name_gr(char *name)
Definition: localize.cpp:1401
void lcl_add_dir(char *current_path)
Definition: localize.cpp:504
void lcl_close()
int Lcl_pl
Definition: localize.cpp:49
void lcl_translate_brief_icon_name_pl(char *name)
Definition: localize.cpp:1300
void lcl_fred_replace_stuff(char *text, size_t max_len)
Definition: localize.cpp:610
#define MAX_FONTS
Definition: font.h:17
SCP_vector< lang_info > Lcl_languages
Definition: localize.cpp:32
struct lang_info lang_info
int lcl_get_xstr_offset(int index, int res)
Definition: localize.cpp:872
int lcl_add_dir_to_path_with_filename(char *current_path, size_t path_max)
Definition: localize.cpp:536
unsigned char ubyte
Definition: pstypes.h:62
ubyte lcl_get_font_index(int font_num)
Definition: localize.cpp:495
GLuint const GLchar * name
Definition: Glext.h:5608
const char * XSTR(const char *str, int index)
Definition: localize.cpp:851
void lcl_translate_wep_name_gr(char *name)
Definition: localize.cpp:1134
void lcl_init(int lang=-1)
Definition: localize.cpp:107
lang_info Lcl_builtin_languages[NUM_BUILTIN_LANGUAGES]
Definition: localize.cpp:36
void lcl_xstr_close()
Definition: localize.cpp:449
void lcl_translate_medal_name_pl(char *name)
Definition: localize.cpp:1563
#define LCL_LANG_NAME_LEN
Definition: localize.h:31
void lcl_set_language(int lang)
Definition: localize.cpp:470
char lang_ext[LCL_LANG_NAME_LEN+1]
Definition: localize.h:36
int lcl_get_language()
Definition: localize.cpp:176
void lcl_ext_localize(const char *in, char *out, size_t max_len, int *id=NULL)
Definition: localize.cpp:831
void lcl_replace_stuff(char *text, size_t max_len)
Definition: localize.cpp:573
void lcl_translate_brief_icon_name_gr(char *name)
Definition: localize.cpp:1153
int Lcl_english
Definition: localize.cpp:50
GLuint res
Definition: Glext.h:9084