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
25 #include <cstdarg> // for va_start/_end
27 #include <simgear/props/props.hxx>
29 ///////////////////////////////////////////////////////////////////////////////
30 // FGLocale //////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////////////////
36 FGLocale(SGPropertyNode* root);
40 * Select the locale's primary language. When no language is given (NULL),
41 * a default is determined matching the system locale.
43 bool selectLanguage (const char* language = NULL);
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
51 bool loadResource (const char* resource);
54 * Obtain a single string from the localized resource matching the given identifier.
55 * Selected context refers to "menu", "options", "dialog" etc.
57 const char* getLocalizedString (const char* id, const char* resource, const char* Default=NULL);
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.
64 simgear::PropertyList getLocalizedStrings(const char* id, const char* resource);
67 * Obtain default font for current locale.
69 const char* getDefaultFont (const char* fallbackFont);
72 * Obtain a message string, from a localized resource ID, and use it as
73 * a printf format string.
75 std::string localizedPrintf(const char* id, const char* resource, ... );
77 std::string vlocalizedPrintf(const char* id, const char* resource, va_list args);
80 * Simple UTF8 to Latin1 encoder.
82 static void utf8toLatin1 (std::string& s);
88 * Find property node matching given language.
90 SGPropertyNode* findLocaleNode (const std::string& language);
93 * Load resource data for given locale node.
95 bool loadResource (SGPropertyNode* localeNode, const char* resource);
98 * Obtain a single string from locale node matching the given identifier and context.
100 const char* getLocalizedString (SGPropertyNode *localeNode, const char* id, const char* context);
103 * Obtain a list of strings from locale node matching the given identifier and context.
105 simgear::PropertyList getLocalizedStrings(SGPropertyNode *localeNode, const char* id, const char* context);
108 * Obtain user's default language setting.
110 string_list getUserLanguage();
112 SGPropertyNode_ptr _intl;
113 SGPropertyNode_ptr _currentLocale;
114 SGPropertyNode_ptr _defaultLocale;
117 // global translation wrappers
119 const char* fgTrMsg(const char* key);
120 std::string fgTrPrintfMsg(const char* key, ...);
123 #endif // __FGLOCALE_HXX