예제 #1
0
void LocalizationMgr::Reload(bool first)
{
	if(first)
		return;

	QueryResult * result;
	set<string> languages;
	map<string, string> bound_languages;
	GetDistinctLanguages(languages, "creature_names_localized");
	GetDistinctLanguages(languages, "gameobject_names_localized");
	GetDistinctLanguages(languages, "items_localized");
	GetDistinctLanguages(languages, "quests_localized");
	GetDistinctLanguages(languages, "npc_text_localized");
	GetDistinctLanguages(languages, "itempages_localized");

	/************************************************************************/
	/* Read Language Bindings From Config                                   */
	/************************************************************************/
	string ls = Config.MainConfig.GetStringDefault("Localization", "LocaleBindings", "");
	vector<string> tbindings = StrSplit(ls, " ");
	for(vector<string>::iterator ztr = tbindings.begin(); ztr != tbindings.end(); ++ztr)
	{
		char lb[200];
		string ll1,ll2;
		strcpy(lb,(*ztr).c_str());

		char * lbp = strchr(lb,'=');
		if(lbp==NULL)
			continue;
		*lbp=0;
		lbp++;

		ll1 = string(lb);
		ll2 = string(lbp);
		Lower(ll1);
		Lower(ll2);

		if(languages.find(ll1) == languages.end())
		{
			bound_languages[ll1] = ll2;
			languages.insert(ll1);
		}
	}

	/************************************************************************/
	/* Generate Language IDs                                                */
	/************************************************************************/

	uint32 langid=1;
	pair<uint32,uint32> dpr;
	for(set<string>::iterator sitr = languages.begin(); sitr != languages.end(); ++sitr)
	{
		if((*sitr)=="enus")		// Default
		{
			dpr.first = *(uint32*)sitr->c_str();
			dpr.second = 0;
		}
		else
		{
			dpr.first = *(uint32*)sitr->c_str();
			dpr.second = langid++;
		}

		m_languages.push_back(dpr);
	}

	if(m_languages.size() == 0)
	{
		m_disabled = true;
		return;		// No localizations
	}
	else
		m_disabled = false;

	m_CreatureNames = new HM_NAMESPACE::hash_map<uint32, LocalizedCreatureName>[langid];
	m_GameObjectNames = new HM_NAMESPACE::hash_map<uint32, LocalizedGameObjectName>[langid];
	m_Quests = new HM_NAMESPACE::hash_map<uint32, LocalizedQuest>[langid];
	m_NpcTexts = new HM_NAMESPACE::hash_map<uint32, LocalizedNpcText>[langid];
	m_Items = new HM_NAMESPACE::hash_map<uint32, LocalizedItem>[langid];
	m_ItemPages = new HM_NAMESPACE::hash_map<uint32, LocalizedItemPage>[langid];

	/************************************************************************/
	/* Creature Names                                                       */
	/************************************************************************/
	{
		LocalizedCreatureName cn;
		string str;
		uint32 entry;
		Field * f;
		uint32 lid;

		result = WorldDatabase.Query("SELECT * FROM creature_names_localized");
		if(result)
		{
			do
			{
				f = result->Fetch();
				str = string(f[1].GetString());
				entry = f[0].GetUInt32();

				lid = GetLanguageId(str);
				if(lid == 0)
					continue;		// no loading enus stuff.. lawl

				cn.Name = strdup(f[2].GetString());
				cn.SubName = strdup(f[3].GetString());
				m_CreatureNames[lid].insert(make_pair(entry, cn));
			} while(result->NextRow());
			delete result;
		}
	}

	/************************************************************************/
	/* GameObject Names                                                     */
	/************************************************************************/
	{
		LocalizedGameObjectName gn;
		string str;
		uint32 entry;
		Field * f;
		uint32 lid;

		result = WorldDatabase.Query("SELECT * FROM gameobject_names_localized");
		if(result)
		{
			do
			{
				f = result->Fetch();
				str = string(f[1].GetString());
				entry = f[0].GetUInt32();

				lid = GetLanguageId(str);
				if(lid == 0)
					continue;		// no loading enus stuff.. lawl

				gn.Name = strdup(f[2].GetString());
				m_GameObjectNames[lid].insert(make_pair(entry, gn));
			} while(result->NextRow());
			delete result;
		}
	}

	/************************************************************************/
	/* Items                                                                */
	/************************************************************************/
	{
		LocalizedItem it;
		string str;
		uint32 entry;
		Field * f;
		uint32 lid;

		result = WorldDatabase.Query("SELECT * FROM items_localized");
		if(result)
		{
			do
			{
				f = result->Fetch();
				str = string(f[1].GetString());
				entry = f[0].GetUInt32();

				lid = GetLanguageId(str);
				if(lid == 0)
					continue;		// no loading enus stuff.. lawl

				if(m_Items[lid].find(entry) != m_Items[lid].end())
				{
					continue;
				}

				it.Name = strdup(f[2].GetString());
				it.Description = strdup(f[3].GetString());
				m_Items[lid].insert(make_pair(entry, it));
			} while(result->NextRow());
			delete result;
		}
	}

	/************************************************************************/
	/* Quests                                                               */
	/************************************************************************/
	{
		LocalizedQuest q;
		string str;
		uint32 entry;
		Field * f;
		uint32 lid;

		result = WorldDatabase.Query("SELECT * FROM quests_localized");
		if(result)
		{
			do
			{
				f = result->Fetch();
				str = string(f[1].GetString());
				entry = f[0].GetUInt32();

				lid = GetLanguageId(str);
				if(lid == 0)
					continue;		// no loading enus stuff.. lawl

				q.Title = strdup(f[2].GetString());
				q.Details = strdup(f[3].GetString());
				q.Objectives = strdup(f[4].GetString());
				q.CompletionText = strdup(f[5].GetString());
				q.IncompleteText = strdup(f[6].GetString());
				q.EndText = strdup(f[7].GetString());
				q.ObjectiveText[0] = strdup(f[8].GetString());
				q.ObjectiveText[1] = strdup(f[9].GetString());
				q.ObjectiveText[2] = strdup(f[10].GetString());
				q.ObjectiveText[3] = strdup(f[11].GetString());

				m_Quests[lid].insert(make_pair(entry, q));
			} while(result->NextRow());
			delete result;
		}
	}

	/************************************************************************/
	/* NPC Texts                                                            */
	/************************************************************************/
	{
		LocalizedNpcText nt;
		string str;
		uint32 entry;
		Field * f;
		uint32 lid;
		uint32 counter;

		result = WorldDatabase.Query("SELECT * FROM npc_text_localized");
		if(result)
		{
			do
			{
				f = result->Fetch();
				str = string(f[1].GetString());
				entry = f[0].GetUInt32();

				lid = GetLanguageId(str);
				if(lid == 0)
					continue;		// no loading enus stuff.. lawl

				counter = 2;
				for(uint32 i = 0; i < 8; i++)
				{
					nt.Texts[i][0] = strdup(f[counter++].GetString());
					nt.Texts[i][1] = strdup(f[counter++].GetString());
				}

				m_NpcTexts[lid].insert(make_pair(entry, nt));
			} while(result->NextRow());
			delete result;
		}
	}
	/************************************************************************/
	/* Item Pages                                                           */
	/************************************************************************/
	{
		LocalizedItemPage nt;
		string str;
		uint32 entry;
		Field * f;
		uint32 lid;

		result = WorldDatabase.Query("SELECT * FROM itempages_localized");
		if(result)
		{
			do
			{
				f = result->Fetch();
				str = string(f[1].GetString());
				entry = f[0].GetUInt32();

				lid = GetLanguageId(str);
				if(lid == 0)
					continue;		// no loading enus stuff.. lawl

				nt.Text = strdup(f[2].GetString());
				m_ItemPages[lid].insert(make_pair(entry, nt));
			} while(result->NextRow());
			delete result;
		}
	}

	/************************************************************************/
	/* Apply all the language bindings.                                     */
	/************************************************************************/
	for(map<string,string>::iterator itr = bound_languages.begin(); itr != bound_languages.end(); itr++)
	{
		uint32 source_language_id = GetLanguageId(itr->second);
		uint32 dest_language_id = GetLanguageId(itr->first);
		if(source_language_id==0 || dest_language_id == 0)
		{
			Log.Error("LocalizationMgr", "Invalid locale conversion string specified: %u->%u (%s->%s)", source_language_id, dest_language_id, itr->second.c_str(), itr->first.c_str());
			continue;
		}

		/* duplicate the hashmaps (we can save the pointers here) */
		CopyHashMap<LocalizedItem>(&m_Items[source_language_id], &m_Items[dest_language_id]);
		CopyHashMap<LocalizedCreatureName>(&m_CreatureNames[source_language_id], &m_CreatureNames[dest_language_id]);
		CopyHashMap<LocalizedGameObjectName>(&m_GameObjectNames[source_language_id], &m_GameObjectNames[dest_language_id]);
		CopyHashMap<LocalizedItemPage>(&m_ItemPages[source_language_id], &m_ItemPages[dest_language_id]);
		CopyHashMap<LocalizedQuest>(&m_Quests[source_language_id], &m_Quests[dest_language_id]);
		CopyHashMap<LocalizedNpcText>(&m_NpcTexts[source_language_id], &m_NpcTexts[dest_language_id]);
	}
}
예제 #2
0
void LocalizationMgr::Reload(bool first)
{
    if (first)
        return;

    QueryResult* result;
    std::set<std::string> languages;
    std::map<std::string, std::string> bound_languages;
    GetDistinctLanguages(languages, "creature_names_localized");
    GetDistinctLanguages(languages, "gameobject_names_localized");
    GetDistinctLanguages(languages, "items_localized");
    GetDistinctLanguages(languages, "quests_localized");
    GetDistinctLanguages(languages, "npc_text_localized");
    GetDistinctLanguages(languages, "itempages_localized");
    GetDistinctLanguages(languages, "gossip_menu_option_localized");
    GetDistinctLanguages(languages, "worldstring_tables_localized");
    GetDistinctLanguages(languages, "worldbroadcast_localized");
    GetDistinctLanguages(languages, "worldmap_info_localized");
    GetDistinctLanguages(languages, "npc_monstersay_localized");

    /// Read Language Bindings From Config
    std::string ls = Config.MainConfig.GetStringDefault("Localization", "LocaleBindings", "");
    std::vector<std::string> tbindings = StrSplit(ls, " ");
    for (std::vector<std::string>::iterator ztr = tbindings.begin(); ztr != tbindings.end(); ++ztr)
    {
        char lb[MAX_LOCALIZED_CHAR];
        std::string ll1, ll2;
        strncpy(lb, (*ztr).c_str(), MAX_LOCALIZED_CHAR);
        lb[MAX_LOCALIZED_CHAR - 1] = '\0';

        char* lbp = strchr(lb, '=');
        if (lbp == NULL)
            continue;
        *lbp = 0;
        lbp++;

        ll1 = std::string(lb);
        ll2 = std::string(lbp);
        Lower(ll1);
        Lower(ll2);

        if (languages.find(ll1) == languages.end())
        {
            bound_languages[ll1] = ll2;
            languages.insert(ll1);
        }
    }

    /// Generate Language IDs
    uint32 langid = 1;
    std::pair<uint32, uint32> dpr;
    for (std::set<std::string>::iterator sitr = languages.begin(); sitr != languages.end(); ++sitr)
    {
        if ((*sitr) == "enus")        // Default
        {
            dpr.first = *(uint32*)sitr->c_str();
            dpr.second = 0;
        }
        else
        {
            dpr.first = *(uint32*)sitr->c_str();
            dpr.second = langid++;
        }

        m_languages.push_back(dpr);
    }

    if (m_languages.size() == 0)
    {
        m_disabled = true;
        return;                 // No localizations
    }
    else
        m_disabled = false;

    m_CreatureNames = new std::unordered_map<uint32, LocalizedCreatureName>[langid];
    m_GameObjectNames = new std::unordered_map<uint32, LocalizedGameObjectName>[langid];
    m_Quests = new std::unordered_map<uint32, LocalizedQuest>[langid];
    m_NpcTexts = new std::unordered_map<uint32, LocalizedNpcText>[langid];
    m_Items = new std::unordered_map<uint32, LocalizedItem>[langid];
    m_ItemPages = new std::unordered_map<uint32, LocalizedItemPage>[langid];
    m_CreatureText = new std::unordered_map<uint32, LocalizedCreatureText>[langid];
    m_GossipMenuOption = new std::unordered_map<uint32, LocalizedGossipMenuOption>[langid];
    m_WorldStrings = new std::unordered_map<uint32, LocalizedWorldStringTable>[langid];
    m_WorldBroadCast = new std::unordered_map<uint32, LocalizedWorldBroadCast>[langid];
    m_WorldMapInfo = new std::unordered_map<uint32, LocalizedWorldMapInfo>[langid];
    m_MonsterSay = new std::unordered_map<uint32, LocalizedMonstersay>[langid];

    //////////////////////////////////////////////////////////////////////////////////////////
    // Creature Names
    {
        LocalizedCreatureName cn;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM creature_names_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;        // no loading enUS stuff.. lawl

                cn.Name = strdup(f[2].GetString());
                cn.SubName = strdup(f[3].GetString());
                m_CreatureNames[lid].insert(std::make_pair(entry, cn));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // GameObject Names
    {
        LocalizedGameObjectName gn;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM gameobject_names_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;        // no loading enUS stuff.. lawl

                gn.Name = strdup(f[2].GetString());
                m_GameObjectNames[lid].insert(std::make_pair(entry, gn));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // Items
    {
        LocalizedItem it;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM items_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;        // no loading enUS stuff.. lawl

                if (m_Items[lid].find(entry) != m_Items[lid].end())
                {
                    continue;
                }

                it.Name = strdup(f[2].GetString());
                it.Description = strdup(f[3].GetString());
                m_Items[lid].insert(std::make_pair(entry, it));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // Quests
    {
        LocalizedQuest q;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM quests_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;        // no loading enUS stuff.. lawl

                q.Title = strdup(f[2].GetString());
                q.Details = strdup(f[3].GetString());
                q.Objectives = strdup(f[4].GetString());
                q.CompletionText = strdup(f[5].GetString());
                q.IncompleteText = strdup(f[6].GetString());
                q.EndText = strdup(f[7].GetString());
                q.ObjectiveText[0] = strdup(f[8].GetString());
                q.ObjectiveText[1] = strdup(f[9].GetString());
                q.ObjectiveText[2] = strdup(f[10].GetString());
                q.ObjectiveText[3] = strdup(f[11].GetString());

                m_Quests[lid].insert(std::make_pair(entry, q));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // NPC Texts
    {
        LocalizedNpcText nt;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;
        uint32 counter;

        result = WorldDatabase.Query("SELECT * FROM npc_text_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;        // no loading enUS stuff.. lawl

                counter = 2;
                for (uint8 i = 0; i < 8; ++i)
                {
                    nt.Texts[i][0] = strdup(f[counter++].GetString());
                    nt.Texts[i][1] = strdup(f[counter++].GetString());
                }

                m_NpcTexts[lid].insert(std::make_pair(entry, nt));
            }
            while (result->NextRow());
            delete result;
        }
    }
    //////////////////////////////////////////////////////////////////////////////////////////
    // Item Pages
    {
        LocalizedItemPage nt;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM itempages_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;        // no loading enUS stuff.. lawl

                nt.Text = strdup(f[2].GetString());
                m_ItemPages[lid].insert(std::make_pair(entry, nt));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // Creature Text
    {
        LocalizedCreatureText nt;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM npc_script_text_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;

                nt.Text = strdup(f[2].GetString());
                m_CreatureText[lid].insert(std::make_pair(entry, nt));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // Gossip Menu Option
    {
        LocalizedGossipMenuOption nt;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM gossip_menu_option_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;

                nt.Text = strdup(f[2].GetString());
                m_GossipMenuOption[lid].insert(std::make_pair(entry, nt));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // World Common Message
    {
        LocalizedWorldStringTable nt;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM worldstring_tables_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;

                nt.Text = strdup(f[2].GetString());
                m_WorldStrings[lid].insert(std::make_pair(entry, nt));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // World BroadCast Messages
    {
        LocalizedWorldBroadCast nt;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM worldbroadcast_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;

                nt.Text = strdup(f[2].GetString());
                m_WorldBroadCast[lid].insert(std::make_pair(entry, nt));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // World MapInfo Entry Name
    {
        LocalizedWorldMapInfo nt;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        result = WorldDatabase.Query("SELECT * FROM worldmap_info_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;

                nt.Text = strdup(f[2].GetString());
                m_WorldMapInfo[lid].insert(std::make_pair(entry, nt));
            }
            while (result->NextRow());
            delete result;
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////////
    // NPC Monstersay
    {
        LocalizedMonstersay ms;
        std::string str;
        uint32 entry;
        Field* f;
        uint32 lid;

        sLog.outString("Loading npc_monstersay_localized rows...");
        result = WorldDatabase.Query("SELECT * FROM npc_monstersay_localized");
        if (result)
        {
            do
            {
                f = result->Fetch();
                str = std::string(f[1].GetString());
                entry = f[0].GetUInt32();

                lid = GetLanguageId(str);
                if (lid == 0)
                    continue;        // no loading enUS stuff.. lawl

                ms.monstername = strdup(f[2].GetString());
                ms.text0 = strdup(f[3].GetString());
                ms.text1 = strdup(f[4].GetString());
                ms.text2 = strdup(f[5].GetString());
                ms.text3 = strdup(f[6].GetString());
                ms.text4 = strdup(f[7].GetString());

                m_MonsterSay[lid].insert(std::make_pair(entry, ms));
            }
            while (result->NextRow());
            delete result;
        }
    }


    //////////////////////////////////////////////////////////////////////////////////////////
    // Apply all the language bindings.
    for (std::map<std::string, std::string>::iterator itr = bound_languages.begin(); itr != bound_languages.end(); ++itr)
    {
        uint32 source_language_id = GetLanguageId(itr->second);
        uint32 dest_language_id = GetLanguageId(itr->first);
        if (source_language_id == 0 || dest_language_id == 0)
        {
            sLog.Error("LocalizationMgr", "Invalid locale conversion string specified: %u->%u (%s->%s)", source_language_id, dest_language_id, itr->second.c_str(), itr->first.c_str());
            continue;
        }

        // duplicate the hashmaps (we can save the pointers here)
        CopyHashMap<LocalizedItem>(&m_Items[source_language_id], &m_Items[dest_language_id]);
        CopyHashMap<LocalizedCreatureName>(&m_CreatureNames[source_language_id], &m_CreatureNames[dest_language_id]);
        CopyHashMap<LocalizedGameObjectName>(&m_GameObjectNames[source_language_id], &m_GameObjectNames[dest_language_id]);
        CopyHashMap<LocalizedItemPage>(&m_ItemPages[source_language_id], &m_ItemPages[dest_language_id]);
        CopyHashMap<LocalizedQuest>(&m_Quests[source_language_id], &m_Quests[dest_language_id]);
        CopyHashMap<LocalizedNpcText>(&m_NpcTexts[source_language_id], &m_NpcTexts[dest_language_id]);
        CopyHashMap<LocalizedCreatureText>(&m_CreatureText[source_language_id], &m_CreatureText[dest_language_id]);
        CopyHashMap<LocalizedGossipMenuOption>(&m_GossipMenuOption[source_language_id], &m_GossipMenuOption[dest_language_id]);
        CopyHashMap<LocalizedWorldStringTable>(&m_WorldStrings[source_language_id], &m_WorldStrings[dest_language_id]);
        CopyHashMap<LocalizedWorldBroadCast>(&m_WorldBroadCast[source_language_id], &m_WorldBroadCast[dest_language_id]);
        CopyHashMap<LocalizedWorldMapInfo>(&m_WorldMapInfo[source_language_id], &m_WorldMapInfo[dest_language_id]);
        CopyHashMap<LocalizedMonstersay>(&m_MonsterSay[source_language_id], &m_MonsterSay[dest_language_id]);
    }
}