]> git.mxchange.org Git - flightgear.git/blob - src/Main/locale.hxx
Make PerformanceDB a real subsystem
[flightgear.git] / src / Main / locale.hxx
1 // locale.hxx -- FlightGear Localization Support
2 //
3 // Written by Thorsten Brehm, started April 2012.
4 //
5 // Copyright (C) 2012 Thorsten Brehm - brehmt (at) gmail com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 #ifndef __FGLOCALE_HXX
22 #define __FGLOCALE_HXX
23
24 #include <string>
25 #include <cstdarg> // for va_start/_end
26
27 #include <simgear/props/props.hxx>
28
29 ///////////////////////////////////////////////////////////////////////////////
30 // FGLocale  //////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////////////////
32
33 class FGLocale
34 {
35 public:
36     FGLocale(SGPropertyNode* root);
37     virtual ~FGLocale();
38
39     /**
40      * Select the locale's primary language. When no language is given (NULL),
41      * a default is determined matching the system locale.
42      */
43     bool        selectLanguage      (const char* language = NULL);
44
45     /**
46      * Load strings for requested resource, i.e. "menu", "options", "dialogs".
47      * Loads data for current and default locale (the latter is the fallback).
48      * Result is stored below the "strings" node in the property tree of the
49      * respective locale.
50      */
51     bool        loadResource        (const char* resource);
52
53     /**
54      * Obtain a single string from the localized resource matching the given identifier.
55      * Selected context refers to "menu", "options", "dialog" etc.
56      */
57     const char* getLocalizedString  (const char* id, const char* resource, const char* Default=NULL);
58
59     /**
60       * Obtain a list of strings from the localized resource matching the given identifier.
61       * Selected context refers to "menu", "options", "dialog" etc.
62       * Returns a list of (string) properties.
63       */
64     simgear::PropertyList getLocalizedStrings(const char* id, const char* resource);
65
66     /**
67      * Obtain default font for current locale.
68      */
69     const char* getDefaultFont      (const char* fallbackFont);
70
71     /**
72      * Obtain a message string, from a localized resource ID, and use it as
73      * a printf format string.
74      */
75     std::string localizedPrintf(const char* id, const char* resource, ... );
76     
77     std::string vlocalizedPrintf(const char* id, const char* resource, va_list args);
78     
79     /**
80      * Simple UTF8 to Latin1 encoder.
81      */
82     static void utf8toLatin1        (std::string& s);
83
84
85
86 protected:
87     /**
88      * Find property node matching given language.
89      */
90     SGPropertyNode* findLocaleNode      (const std::string& language);
91
92     /**
93      * Load resource data for given locale node.
94      */
95     bool            loadResource        (SGPropertyNode* localeNode, const char* resource);
96
97     /**
98      * Obtain a single string from locale node matching the given identifier and context.
99      */
100     const char*     getLocalizedString  (SGPropertyNode *localeNode, const char* id, const char* context);
101
102     /**
103      * Obtain a list of strings from locale node matching the given identifier and context.
104      */
105     simgear::PropertyList getLocalizedStrings(SGPropertyNode *localeNode, const char* id, const char* context);
106
107     /**
108      * Obtain user's default language setting.
109      */
110     string_list getUserLanguage();
111     
112     SGPropertyNode_ptr _intl;
113     SGPropertyNode_ptr _currentLocale;
114     SGPropertyNode_ptr _defaultLocale;
115 };
116
117 // global translation wrappers
118
119 const char* fgTrMsg(const char* key);
120 std::string fgTrPrintfMsg(const char* key, ...);
121
122
123 #endif // __FGLOCALE_HXX