summaryrefslogtreecommitdiff
path: root/src/language.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-11-22 00:50:33 -0500
committerAdam <Adam@anope.org>2012-11-22 00:50:33 -0500
commitd33a0f75a5c0c584fbb7cc0076da36d494f39494 (patch)
tree7b2274cc833c793c0f5595660cbd4d715de52ffd /src/language.cpp
parent368d469631763e9c8bf399980d0ac7c5b5664d39 (diff)
Pretty large coding style cleanup, in source doc
cleanup, and allow protocol mods to depend on each other
Diffstat (limited to 'src/language.cpp')
-rw-r--r--src/language.cpp46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/language.cpp b/src/language.cpp
index c62a950aa..1e1f9e704 100644
--- a/src/language.cpp
+++ b/src/language.cpp
@@ -7,65 +7,71 @@
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
+ *
*/
#include "services.h"
#include "modules.h"
#include "commands.h"
#include "config.h"
-#include "extern.h"
+#include "language.h"
#if GETTEXT_FOUND
# include <libintl.h>
#endif
-std::vector<Anope::string> languages;
-std::vector<Anope::string> domains;
+std::vector<Anope::string> Language::Languages;
+std::vector<Anope::string> Language::Domains;
-void InitLanguages()
+void Language::InitLanguages()
{
#if GETTEXT_FOUND
- languages.clear();
+ Log(LOG_DEBUG) << "Initializing Languages...";
+
+ Languages.clear();
spacesepstream sep(Config->Languages);
Anope::string language;
while (sep.GetToken(language))
{
- if (!IsFile(locale_dir + "/" + language + "/LC_MESSAGES/anope.mo"))
+ if (!IsFile(Anope::LocaleDir + "/" + language + "/LC_MESSAGES/anope.mo"))
{
Log() << "Error loading language " << language << ", file does not exist!";
}
else
{
Log(LOG_DEBUG) << "Found language file " << language;
- languages.push_back(language);
+ Languages.push_back(language);
}
}
- if (!bindtextdomain("anope", locale_dir.c_str()))
+ if (!bindtextdomain("anope", Anope::LocaleDir.c_str()))
Log() << "Error calling bindtextdomain, " << Anope::LastError();
else
- Log(LOG_DEBUG) << "Successfully bound anope to " << locale_dir;
+ Log(LOG_DEBUG) << "Successfully bound anope to " << Anope::LocaleDir;
setlocale(LC_ALL, "");
#else
- Log() << "Can not load languages, gettext is not installed";
+ Log() << "Unable to initialize languages, gettext is not installed";
#endif
}
-const char *translate(const char *string)
+const char *Language::Translate(const char *string)
{
- return anope_gettext(Config->NSDefLanguage.c_str(), string);
+ return Translate(Config->NSDefLanguage.c_str(), string);
}
-const char *translate(User *u, const char *string)
+const char *Language::Translate(User *u, const char *string)
{
- return translate(u ? u->Account() : NULL, string);
+ if (u && u->Account())
+ return Translate(u->Account(), string);
+ else
+ return Translate(string);
}
-const char *translate(const NickCore *nc, const char *string)
+const char *Language::Translate(const NickCore *nc, const char *string)
{
- return anope_gettext(nc ? nc->language.c_str() : Config->NSDefLanguage.c_str(), string);
+ return Translate(nc ? nc->language.c_str() : Config->NSDefLanguage.c_str(), string);
}
#if GETTEXT_FOUND
@@ -73,7 +79,7 @@ const char *translate(const NickCore *nc, const char *string)
/* Used by gettext to make it always dynamically load language strings (so we can drop them in while Anope is running) */
extern "C" int _nl_msg_cat_cntr;
-const char *anope_gettext(const char *lang, const char *string)
+const char *Language::Translate(const char *lang, const char *string)
{
if (!string || !*string || !lang || !*lang)
return string ? string : "";
@@ -95,8 +101,8 @@ const char *anope_gettext(const char *lang, const char *string)
setlocale(LC_ALL, "en_US");
#endif
const char *translated_string = dgettext("anope", string);
- for (unsigned i = 0; translated_string == string && i < domains.size(); ++i)
- translated_string = dgettext(domains[i].c_str(), string);
+ for (unsigned i = 0; translated_string == string && i < Domains.size(); ++i)
+ translated_string = dgettext(Domains[i].c_str(), string);
#ifdef _WIN32
SetThreadLocale(MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), SORT_DEFAULT));
#else
@@ -108,7 +114,7 @@ const char *anope_gettext(const char *lang, const char *string)
return translated_string;
}
#else
-const char *anope_gettext(const char *lang, const char *string)
+const char *Language::Translate(const char *lang, const char *string)
{
return string != NULL ? string : "";
}