mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-26 11:52:32 +01:00
Core/Locales: Set active code page and locale used by c string functions to utf8
Closes #29455
(cherry picked from commit b299902881)
This commit is contained in:
@@ -12,6 +12,7 @@ if(WIN32 AND MSVC)
|
||||
set(sources_windows
|
||||
${CMAKE_SOURCE_DIR}/src/common/Debugging/WheatyExceptionReport.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/common/Debugging/WheatyExceptionReport.h
|
||||
${CMAKE_SOURCE_DIR}/src/common/WindowsSettings.manifest
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
|
||||
#include "Timezone.h"
|
||||
#include "Hash.h"
|
||||
#include "Locales.h"
|
||||
#include "MapUtils.h"
|
||||
#include "StringConvert.h"
|
||||
#include "Util.h"
|
||||
#include <boost/locale/date_time_facet.hpp>
|
||||
#include <boost/locale/generator.hpp>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace
|
||||
@@ -96,7 +97,11 @@ std::unordered_map<uint32, Minutes, std::identity> InitTimezoneHashDb()
|
||||
return hashToOffset;
|
||||
}
|
||||
|
||||
std::unordered_map<uint32, Minutes, std::identity> const _timezoneOffsetsByHash = InitTimezoneHashDb();
|
||||
std::unordered_map<uint32, Minutes, std::identity> const& GetTimezoneOffsetsByHash()
|
||||
{
|
||||
static std::unordered_map<uint32, Minutes, std::identity> timezoneMap = InitTimezoneHashDb();
|
||||
return timezoneMap;
|
||||
}
|
||||
|
||||
using ClientSupportedTimezone = std::pair<Minutes, std::string>;
|
||||
std::array<ClientSupportedTimezone, 11> const _clientSupportedTimezones =
|
||||
@@ -119,7 +124,7 @@ namespace Trinity::Timezone
|
||||
{
|
||||
Minutes GetOffsetByHash(uint32 hash)
|
||||
{
|
||||
if (Minutes const* offset = Containers::MapGetValuePtr(_timezoneOffsetsByHash, hash))
|
||||
if (Minutes const* offset = Containers::MapGetValuePtr(GetTimezoneOffsetsByHash(), hash))
|
||||
return *offset;
|
||||
|
||||
return 0min;
|
||||
@@ -151,8 +156,7 @@ std::string GetSystemZoneName()
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
return std::string(std::chrono::current_zone()->name());
|
||||
#else
|
||||
static std::locale calendarLocale = boost::locale::generator().generate("");
|
||||
std::unique_ptr<boost::locale::abstract_calendar> p(std::use_facet<class boost::locale::calendar_facet>(calendarLocale).create_calendar());
|
||||
std::unique_ptr<boost::locale::abstract_calendar> p(std::use_facet<class boost::locale::calendar_facet>(Locale::GetCalendarLocale()).create_calendar());
|
||||
return p->get_timezone();
|
||||
#endif
|
||||
}
|
||||
|
||||
45
src/common/Utilities/Locales.cpp
Normal file
45
src/common/Utilities/Locales.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
||||
|
||||
* 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; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Locales.h"
|
||||
#include <boost/locale/generator.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
std::locale _utf8;
|
||||
std::locale _calendar;
|
||||
}
|
||||
|
||||
void Trinity::Locale::Init()
|
||||
{
|
||||
// Change global locale from "C" to UTF-8 for c runtime functions
|
||||
_utf8 = std::locale("");
|
||||
std::locale::global(_utf8);
|
||||
|
||||
boost::locale::generator g;
|
||||
_calendar = g.generate(_utf8, "");
|
||||
}
|
||||
|
||||
std::locale const& Trinity::Locale::GetGlobalLocale()
|
||||
{
|
||||
return _utf8;
|
||||
}
|
||||
|
||||
std::locale const& Trinity::Locale::GetCalendarLocale()
|
||||
{
|
||||
return _calendar;
|
||||
}
|
||||
31
src/common/Utilities/Locales.h
Normal file
31
src/common/Utilities/Locales.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
||||
|
||||
* 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; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRINITYCORE_LOCALE_H
|
||||
#define TRINITYCORE_LOCALE_H
|
||||
|
||||
#include "Define.h"
|
||||
#include <locale>
|
||||
|
||||
namespace Trinity::Locale
|
||||
{
|
||||
TC_COMMON_API void Init();
|
||||
TC_COMMON_API std::locale const& GetGlobalLocale();
|
||||
TC_COMMON_API std::locale const& GetCalendarLocale();
|
||||
}
|
||||
|
||||
#endif // TRINITYCORE_LOCALE_H
|
||||
13
src/common/WindowsSettings.manifest
Normal file
13
src/common/WindowsSettings.manifest
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> <!-- Windows 10 -->
|
||||
</application>
|
||||
</compatibility>
|
||||
</assembly>
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "IoContext.h"
|
||||
#include "IPLocation.h"
|
||||
#include "GitRevision.h"
|
||||
#include "Locales.h"
|
||||
#include "MySQLThreading.h"
|
||||
#include "OpenSSLCrypto.h"
|
||||
#include "ProcessPriority.h"
|
||||
@@ -85,6 +86,8 @@ int main(int argc, char** argv)
|
||||
Trinity::Impl::CurrentServerProcessHolder::_type = SERVER_PROCESS_AUTHSERVER;
|
||||
signal(SIGABRT, &Trinity::AbortHandler);
|
||||
|
||||
Trinity::Locale::Init();
|
||||
|
||||
auto configFile = fs::absolute(_TRINITY_REALM_CONFIG);
|
||||
std::string configService;
|
||||
auto vm = GetConsoleArguments(argc, argv, configFile, configService);
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "GitRevision.h"
|
||||
#include "InstanceSaveMgr.h"
|
||||
#include "IoContext.h"
|
||||
#include "Locales.h"
|
||||
#include "MapManager.h"
|
||||
#include "Metric.h"
|
||||
#include "MySQLThreading.h"
|
||||
@@ -126,6 +127,8 @@ extern int main(int argc, char** argv)
|
||||
Trinity::Impl::CurrentServerProcessHolder::_type = SERVER_PROCESS_WORLDSERVER;
|
||||
signal(SIGABRT, &Trinity::AbortHandler);
|
||||
|
||||
Trinity::Locale::Init();
|
||||
|
||||
auto configFile = fs::absolute(_TRINITY_CORE_CONFIG);
|
||||
std::string configService;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "dbcfile.h"
|
||||
#include "Banner.h"
|
||||
#include "Locales.h"
|
||||
#include "mpq_libmpq04.h"
|
||||
#include "StringFormat.h"
|
||||
|
||||
@@ -1120,6 +1121,8 @@ inline void CloseMPQFiles()
|
||||
|
||||
int main(int argc, char * arg[])
|
||||
{
|
||||
Trinity::Locale::Init();
|
||||
|
||||
Trinity::Banner::Show("Map & DBC Extractor", [](char const* text) { printf("%s\n", text); }, nullptr);
|
||||
|
||||
HandleArgs(argc, arg);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "Banner.h"
|
||||
#include "DBCFileLoader.h"
|
||||
#include "Locales.h"
|
||||
#include "MapBuilder.h"
|
||||
#include "PathCommon.h"
|
||||
#include "Timer.h"
|
||||
@@ -297,6 +298,8 @@ std::unordered_map<uint32, uint8> LoadLiquid()
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Trinity::Locale::Init();
|
||||
|
||||
Trinity::Banner::Show("MMAP generator", [](char const* text) { printf("%s\n", text); }, nullptr);
|
||||
|
||||
unsigned int threads = std::thread::hardware_concurrency();
|
||||
|
||||
@@ -20,9 +20,12 @@
|
||||
|
||||
#include "TileAssembler.h"
|
||||
#include "Banner.h"
|
||||
#include "Locales.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Trinity::Locale::Init();
|
||||
|
||||
Trinity::Banner::Show("VMAP assembler", [](char const* text) { std::cout << text << std::endl; }, nullptr);
|
||||
|
||||
std::string src = "Buildings";
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "dbcfile.h"
|
||||
#include "StringFormat.h"
|
||||
#include "vmapexport.h"
|
||||
#include "Locales.h"
|
||||
#include "wdtfile.h"
|
||||
#include "wmo.h"
|
||||
#include "mpq_libmpq04.h"
|
||||
@@ -406,6 +407,8 @@ bool processArgv(int argc, char ** argv, const char *versionString)
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
Trinity::Locale::Init();
|
||||
|
||||
Trinity::Banner::Show("VMAP data extractor", [](char const* text) { printf("%s\n", text); }, nullptr);
|
||||
|
||||
bool success = true;
|
||||
|
||||
Reference in New Issue
Block a user