summaryrefslogtreecommitdiff
path: root/include/localemgr.h
blob: ac9492c7d75ccce403d01b394e17b7056a6865ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/******************************************************************************
 *
 *  localemgr.h -	definition of class LocaleMgr used to interact with
 *			registered locales for a sword installation
 *
 * $Id: localemgr.h 2833 2013-06-29 06:40:28Z chrislit $
 *
 * Copyright 2000-2013 CrossWire Bible Society (http://www.crosswire.org)
 *	CrossWire Bible Society
 *	P. O. Box 2528
 *	Tempe, AZ  85280-2528
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation version 2.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 */

#ifndef LOCALEMGR_H
#define LOCALEMGR_H

#include <map>
#include <list>

#include <defs.h>
#include <swbuf.h>

SWORD_NAMESPACE_START

class SWLocale;
 
typedef std::list<SWBuf> StringList;
typedef std::map < SWBuf, SWLocale *, std::less < SWBuf > > LocaleMap;
/**
* The LocaleMgr class handles all the different locales of Sword.
* It provides functions to get a list of all available locales,
* to get the default locale name and to get it.
* The other functions are not interesting for frontend programmers.
*
* To get the default locale name use @see getDefaultLocaleName
* To set the default locale name use @see setDefaultLocaleName
* To get the locale for a language name use @see getLocale
* To get a list of availble locales use @see getAvailableLocales
*/
class SWDLLEXPORT LocaleMgr {
private:
	void deleteLocales();
	char *defaultLocaleName;
	LocaleMgr(const LocaleMgr &);
	friend class __staticsystemLocaleMgr;
protected:
	LocaleMap *locales;
	static LocaleMgr *systemLocaleMgr;

public:

	/** Default constructor of  LocaleMgr
	* You do normally not need this constructor, use LocaleMgr::getSystemLocaleMgr() instead.
	*/
	LocaleMgr(const char *iConfigPath = 0);

	/**
	* Default destructor of LocaleMgr
	*/
	virtual ~LocaleMgr();

	/** Get the locale connected with the name "name".
	*
	* @param name The name of the locale you want to have. For example use getLocale("de") to get the locale for the German language.
	* @return Returns the locale object if the locale with the name given as parameter was found. If it wasn't found return NULL.
	*/
	virtual SWLocale *getLocale(const char *name);

	/** Get the list of available locales.
	*
	* @return Returns a list of strings, which contains the names of the available locales.
	*/
	virtual StringList getAvailableLocales();

	/** Returns translated text.
	* This function uses both parameters to return the translated version of the given text.
	*
	* @param text The text to translate into the language given by the first parameter.
	* @param localeName The name of the locale Sword should use
	* @return Returns the translated text.
	*/
	virtual const char *translate(const char *text, const char *localeName = 0);

	/** Get the default locale name. To set it use @see setDefaultLocaleName
	*
	* @return Returns the default locale name
	*/
	virtual const char *getDefaultLocaleName();

	/** Set the new standard locale of Sword.
	*
	* @param name The name of the new default locale  
	*/
	virtual void setDefaultLocaleName(const char *name);

	/** The LocaleMgr object used globally in the Sword world.
	* Do not create your own LocaleMgr, use this static object instead.
	*/
	static LocaleMgr *getSystemLocaleMgr();
	static void setSystemLocaleMgr(LocaleMgr *newLocaleMgr);

	/** Augment this localmgr with all locale.conf files in a directory
	*/
	virtual void loadConfigDir(const char *ipath);

};

SWORD_NAMESPACE_END
#endif