1 // locale.hxx -- FlightGear Localization Support
3 // Written by Thorsten Brehm, started April 2012.
5 // Copyright (C) 2012 Thorsten Brehm - brehmt (at) gmail com
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.
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.
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.
21 #ifndef __FGLOCALE_HXX
22 #define __FGLOCALE_HXX
26 #include <simgear/props/props.hxx>
28 ///////////////////////////////////////////////////////////////////////////////
29 // FGLocale //////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////////
35 FGLocale(SGPropertyNode* root);
39 * Select the locale's primary language. When no language is given (NULL),
40 * a default is determined matching the system locale.
42 bool selectLanguage (const char* language = NULL);
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
50 bool loadResource (const char* resource);
53 * Obtain a single string from the localized resource matching the given identifier.
54 * Selected context refers to "menu", "options", "dialog" etc.
56 const char* getLocalizedString (const char* id, const char* resource, const char* Default=NULL);
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.
63 simgear::PropertyList getLocalizedStrings(const char* id, const char* resource);
66 * Obtain default font for current locale.
68 const char* getDefaultFont (const char* fallbackFont);
71 * Simple UTF8 to Latin1 encoder.
73 static void utf8toLatin1 (std::string& s);
76 * Obtain user's default language setting.
78 const char* getUserLanguage();
82 * Find property node matching given language.
84 SGPropertyNode* findLocaleNode (const std::string& language);
87 * Load resource data for given locale node.
89 bool loadResource (SGPropertyNode* localeNode, const char* resource);
92 * Obtain a single string from locale node matching the given identifier and context.
94 const char* getLocalizedString (SGPropertyNode *localeNode, const char* id, const char* context);
97 * Obtain a list of strings from locale node matching the given identifier and context.
99 simgear::PropertyList getLocalizedStrings(SGPropertyNode *localeNode, const char* id, const char* context);
101 SGPropertyNode_ptr _intl;
102 SGPropertyNode_ptr _currentLocale;
103 SGPropertyNode_ptr _defaultLocale;
106 #endif // __FGLOCALE_HXX