]> git.mxchange.org Git - flightgear.git/blob - src/Main/locale.hxx
ATIS upgrade
[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
26 #include <simgear/props/props.hxx>
27
28 ///////////////////////////////////////////////////////////////////////////////
29 // FGLocale  //////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////////
31
32 class FGLocale
33 {
34 public:
35     FGLocale(SGPropertyNode* root);
36     virtual ~FGLocale();
37
38     /**
39      * Select the locale's primary language. When no language is given (NULL),
40      * a default is determined matching the system locale.
41      */
42     bool        selectLanguage      (const char* language = NULL);
43
44     /**
45      * Load strings for requested resource, i.e. "menu", "options", "dialogs".
46      * Loads data for current and default locale (the latter is the fallback).
47      * Result is stored below the "strings" node in the property tree of the
48      * respective locale.
49      */
50     bool        loadResource        (const char* resource);
51
52     /**
53      * Obtain a single string from the localized resource matching the given identifier.
54      * Selected context refers to "menu", "options", "dialog" etc.
55      */
56     const char* getLocalizedString  (const char* id, const char* resource, const char* Default=NULL);
57
58     /**
59       * Obtain a list of strings from the localized resource matching the given identifier.
60       * Selected context refers to "menu", "options", "dialog" etc.
61       * Returns a list of (string) properties.
62       */
63     simgear::PropertyList getLocalizedStrings(const char* id, const char* resource);
64
65     /**
66      * Obtain default font for current locale.
67      */
68     const char* getDefaultFont      (const char* fallbackFont);
69
70     /**
71      * Simple UTF8 to Latin1 encoder.
72      */
73     static void utf8toLatin1        (std::string& s);
74
75     /**
76      * Obtain user's default language setting.
77      */
78     const char* getUserLanguage();
79
80 protected:
81     /**
82      * Find property node matching given language.
83      */
84     SGPropertyNode* findLocaleNode      (const std::string& language);
85
86     /**
87      * Load resource data for given locale node.
88      */
89     bool            loadResource        (SGPropertyNode* localeNode, const char* resource);
90
91     /**
92      * Obtain a single string from locale node matching the given identifier and context.
93      */
94     const char*     getLocalizedString  (SGPropertyNode *localeNode, const char* id, const char* context);
95
96     /**
97      * Obtain a list of strings from locale node matching the given identifier and context.
98      */
99     simgear::PropertyList getLocalizedStrings(SGPropertyNode *localeNode, const char* id, const char* context);
100
101     SGPropertyNode_ptr _intl;
102     SGPropertyNode_ptr _currentLocale;
103     SGPropertyNode_ptr _defaultLocale;
104 };
105
106 #endif // __FGLOCALE_HXX