Fix windows build of tinygettext

This commit is contained in:
Benau 2020-09-09 13:36:21 +08:00
parent c51d464839
commit 1a8b5cd2e1
3 changed files with 33 additions and 0 deletions

View File

@ -81,6 +81,10 @@ else()
add_definitions(-DDISABLE_ICONV)
endif()
if (UNIX OR MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
endif()
## TinyGetText library compilation
## build list of source files

View File

@ -21,7 +21,9 @@
#include <sys/types.h>
#include <fstream>
#ifndef _WIN32
#include <dirent.h>
#endif
#include <stdlib.h>
#include <string.h>
@ -34,6 +36,9 @@ UnixFileSystem::UnixFileSystem()
std::vector<std::string>
UnixFileSystem::open_directory(const std::string& pathname)
{
#ifdef _WIN32
return std::vector<std::string>();
#else
DIR* dir = opendir(pathname.c_str());
if (!dir)
{
@ -53,6 +58,7 @@ UnixFileSystem::open_directory(const std::string& pathname)
return files;
}
#endif
}
std::unique_ptr<std::istream>

View File

@ -61,6 +61,8 @@ Translations* translations = NULL;
#endif
#ifndef SERVER_ONLY
#include "tinygettext/file_system.hpp"
std::map<std::string, std::string> Translations::m_localized_name;
std::map<std::string, std::map<std::string, irr::core::stringw> >
Translations::m_localized_country_codes;
@ -95,6 +97,27 @@ const LanguageList* Translations::getLanguageList() const
Translations::Translations() //: m_dictionary_manager("UTF-16")
{
#ifndef SERVER_ONLY
class StkFileSystem : public tinygettext::FileSystem
{
public:
std::vector<std::string> open_directory(const std::string& pathname)
{
std::set<std::string> result;
file_manager->listFiles(result, pathname);
std::vector<std::string> files;
for(const std::string& file : result)
files.push_back(file);
return files;
}
std::unique_ptr<std::istream> open_file(const std::string& filename)
{
return std::unique_ptr<std::istream>(new std::ifstream(
FileUtils::getPortableReadingPath(filename)));
}
};
m_dictionary_manager.set_filesystem(std::unique_ptr<FileSystem>(
new StkFileSystem()));
m_dictionary_manager.add_directory(
file_manager->getAsset(FileManager::TRANSLATION,""));