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 (English should always be index 0)
23 #define LCL_ENGLISH						0
24 #define LCL_GERMAN						1
25 #define LCL_FRENCH						2
26 #define LCL_POLISH						3
27 
28 #define LCL_UNTRANSLATED				10	// this should be higher than the highest builtin language
29 #define LCL_RETAIL_HYBRID				11	// ditto; this is the weird retail behavior where internal is translated but external isn't
30 #define	LCL_DEFAULT						0
31 
32 // for language name strings
33 #define LCL_LANG_NAME_LEN				32
34 
35 #define LCL_MIN_FONTS					3
36 
37 // language info table
38 typedef struct lang_info {
39 	char lang_name[LCL_LANG_NAME_LEN + 1];				// literal name of the language
40 	char lang_ext[LCL_LANG_NAME_LEN + 1];				// the extension used for adding to names on disk access
41 	SCP_vector<ubyte> special_char_indexes;				// where in the font do we have the special characters for this language
42 														// note: treats 0 as "none" since a zero offset in a font makes no sense
43 														// i.e. all the normal chars start at zero
44 	int checksum;										// used for language auto-detection
45 } lang_info;
46 
47 // These are the original languages supported by FS2. The code expects these languages to be supported even if the tables don't
48 #define NUM_BUILTIN_LANGUAGES		4
49 extern lang_info Lcl_builtin_languages[NUM_BUILTIN_LANGUAGES];
50 
51 extern SCP_vector<lang_info> Lcl_languages;
52 
53 // following is the offset where special characters start in our font
54 extern int Lcl_special_chars;
55 
56 // use these to replace *_BUILD values
57 // only 1 will be active at a time
58 extern int Lcl_fr;
59 extern int Lcl_gr;
60 extern int Lcl_pl;
61 extern int Lcl_en;
62 
63 // The currently active language. Index into Lcl_languages.
64 extern int Lcl_current_lang;
65 
66 // special check for misplaced mod data (see Mantis #2942)
67 extern bool *Lcl_unexpected_tstring_check;
68 
69 
70 // ------------------------------------------------------------------------------------------------------------
71 // LOCALIZE FUNCTIONS
72 //
73 
74 // get an index we can use to look into the array, since we now have three different ways of using English
75 // (translated, untranslated, and hybrid: internal translated, external untranslated)
76 int lcl_get_current_lang_index();
77 
78 // initialize localization, if no language is passed - use the language specified in the registry
79 void lcl_init(int lang = -1);
80 
81 // shutdown localization
82 void lcl_close();
83 
84 // initialize the xstr table
85 void lcl_xstr_init();
86 
87 // free the xstr table
88 void lcl_xstr_close();
89 
90 // returns the current language character string
91 void lcl_get_language_name(char *lang_name);
92 
93 // set our current language
94 void lcl_set_language(int lang);
95 
96 // get a fonts special characters index
97 ubyte lcl_get_font_index(int font_num);
98 
99 // NOTE : generally you should only care about the above functions. Below are very low level functions
100 //        which should already be well entrenched in FreeSpace. If you think you need to use one of the below
101 //        functions - ask first :)
102 // externalization of table/mission files (only parse routines ever need to deal with these functions) -----------------------
103 
104 // maybe add localized directory to full path with file name when opening a localized file
105 int lcl_add_dir_to_path_with_filename(char *current_path, size_t path_max);
106 
107 // Goober5000
108 void lcl_replace_stuff(char *text, size_t max_len, bool force = false);
109 void lcl_replace_stuff(SCP_string &text, bool force = false);
110 
111 // Karajorma
112 void lcl_fred_replace_stuff(char *text, size_t max_len);
113 void lcl_fred_replace_stuff(SCP_string &text);
114 
115 // get the localized version of the string. if none exists, return the original string
116 // valid input to this function includes :
117 // "this is some text"
118 // XSTR("wheeee", -1)
119 // XSTR("whee", 2000)
120 // and these should cover all the externalized string cases
121 // fills in id if non-NULL. a value of -2 indicates it is not an external string
122 void lcl_ext_localize(const char *in, char *out, size_t max_len, int *id = nullptr);
123 void lcl_ext_localize(const SCP_string &in, SCP_string &out, int *id = nullptr);
124 
125 // translate the specified string based upon the current language
126 int lcl_get_xstr_offset(int index, int res);
127 
128 void lcl_translate_wep_name_gr(char *name);
129 void lcl_translate_ship_name_gr(char *name);
130 void lcl_translate_brief_icon_name_gr(char *name);
131 void lcl_translate_brief_icon_name_pl(char *name);
132 void lcl_translate_targetbox_name_gr(char *name);
133 void lcl_translate_targetbox_name_pl(char *name);
134 void lcl_translate_medal_name_gr(char *name);
135 void lcl_translate_medal_name_pl(char *name);
136 
137 #endif	// defined __FREESPACE2_LOCALIZATION_UTILITIES_HEADER_FILE
138