Debian Codegraph @

include/i18n.h

raw
1 #pragma once
2
3 #include <string>
4 #include "imodule.h"
5 #include "iradiant.h"
6
7 namespace language
8 {
9
10 class ILocalisationProvider
11 {
12 public:
13 virtual ~ILocalisationProvider() {}
14
15 typedef std::shared_ptr<ILocalisationProvider> Ptr;
16
17 // Returns the localised version of the given string
18 virtual std::string getLocalisedString(const char* stringToLocalise) = 0;
19 };
20
21 class ILanguageManager
22 {
23 public:
24 virtual ~ILanguageManager() {}
25
26 /**
27 * Registers the given provider, which will be used to resolve localised strings.
28 */
29 virtual void registerProvider(const ILocalisationProvider::Ptr& instance) = 0;
30
31 /**
32 * Removes references to the localisation provider.
33 */
34 virtual void clearProvider() = 0;
35
36 /**
37 * Returns the localised version of the given input string
38 * or the unmodified string if no suitable localisation provider
39 * was found.
40 */
41 virtual std::string getLocalisedString(const char* stringToLocalise) = 0;
42 };
43
44 }
45
46 // This is the accessor for the global language manager module
47 inline language::ILanguageManager& GlobalLanguageManager()
48 {
49 return GlobalRadiantCore().getLanguageManager();
50 }
51
52 #define GETTEXT_PACKAGE "darkradiant"
53
54 // Redefine the _() macro to return a std::string for convenience
55 #ifndef WXINTL_NO_GETTEXT_MACRO
56 #define WXINTL_NO_GETTEXT_MACRO
57 #endif
58
59 // Custom translation macros _, N_ and C_
60
61 inline std::string _(const char* s)
62 {
63 if (!module::IsGlobalModuleRegistryAvailable())
64 {
65 return s; // it's still too early for this call, return the unmodified string
66 }
67
68 if (!module::GlobalModuleRegistry().moduleExists(MODULE_RADIANT_CORE))
69 {
70 return s; // still too early
71 }
72
73 return GlobalLanguageManager().getLocalisedString(s);
74 }
75
76 // Macro used to decorate a string as localizable, such that it is recognised
77 // by the xgettext parser, but without triggering an actual function call
78 // at the place it is used. Can be used to e.g. decorate constants in the code.
79 #define N_(str) str
80
81 #ifndef C_
82 #define C_(context,text) _(text)
83 #endif