mirror of
https://github.com/anope/anope.git
synced 2026-06-26 20:56:39 +02:00
Pretty large coding style cleanup, in source doc
cleanup, and allow protocol mods to depend on each other
This commit is contained in:
+26
-20
@@ -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 : "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user