diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/Time/Timezone.cpp | 14 | ||||
| -rw-r--r-- | src/common/Utilities/Locales.cpp | 45 | ||||
| -rw-r--r-- | src/common/Utilities/Locales.h | 31 | ||||
| -rw-r--r-- | src/common/WindowsSettings.manifest | 13 |
4 files changed, 98 insertions, 5 deletions
diff --git a/src/common/Time/Timezone.cpp b/src/common/Time/Timezone.cpp index 6bc5773edc3..9748078fe9f 100644 --- a/src/common/Time/Timezone.cpp +++ b/src/common/Time/Timezone.cpp @@ -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 } diff --git a/src/common/Utilities/Locales.cpp b/src/common/Utilities/Locales.cpp new file mode 100644 index 00000000000..b4048b9c3f3 --- /dev/null +++ b/src/common/Utilities/Locales.cpp @@ -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; +} diff --git a/src/common/Utilities/Locales.h b/src/common/Utilities/Locales.h new file mode 100644 index 00000000000..b60ad0bbf2f --- /dev/null +++ b/src/common/Utilities/Locales.h @@ -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 diff --git a/src/common/WindowsSettings.manifest b/src/common/WindowsSettings.manifest new file mode 100644 index 00000000000..b7da14cfe5c --- /dev/null +++ b/src/common/WindowsSettings.manifest @@ -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> |
