Remove fribidi and tinygettext in server only build

This commit is contained in:
Benau 2018-07-07 01:22:26 +08:00
parent 106d4c3c08
commit 9c3aae554e
19 changed files with 113 additions and 32 deletions

View File

@ -19,7 +19,6 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
option(SERVER_ONLY "Create a server only (i.e. no graphics or sound)" OFF)
option(USE_FRIBIDI "Support for right-to-left languages" ON)
option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON)
option(USE_SYSTEM_ANGELSCRIPT "Use system angelscript instead of built-in angelscript. If you enable this option, make sure to use a compatible version." OFF)
option(USE_SYSTEM_ENET "Use system ENET instead of the built-in version, when available." ON)
@ -27,6 +26,8 @@ option(USE_SYSTEM_GLEW "Use system GLEW instead of the built-in version, when av
CMAKE_DEPENDENT_OPTION(BUILD_RECORDER "Build opengl recorder" ON
"NOT SERVER_ONLY;NOT APPLE" OFF)
CMAKE_DEPENDENT_OPTION(USE_FRIBIDI "Support for right-to-left languages" ON
"NOT SERVER_ONLY" OFF)
if(APPLE)
list(APPEND CMAKE_PREFIX_PATH /usr/local/opt)

View File

@ -87,6 +87,7 @@ void FontManager::loadFonts()
*/
void FontManager::unitTesting()
{
#ifndef SERVER_ONLY
std::vector<std::string> list = *(translations->getLanguageList());
const int cur_log_level = Log::getLogLevel();
for (const std::string& lang : list)
@ -134,5 +135,5 @@ void FontManager::unitTesting()
}
}
}
#endif
} // unitTesting

View File

@ -192,7 +192,9 @@ void CreditsScreen::loadedFromFile()
m_sections.push_back( new CreditsSection("Translations"));
for (unsigned int i = 1; i < translator.size(); i = i + MAX_PER_SCREEN)
{
#ifndef SERVER_ONLY
line = stringw(translations->getCurrentLanguageName().c_str());
#endif
CreditsEntry entry(line);
getCurrentSection()->addEntry( entry );

View File

@ -85,7 +85,7 @@ void OptionsScreenLanguage::init()
// I18N: in the language choice, to select the same language as the OS
list_widget->addItem("system", _("System Language"));
#ifndef SERVER_ONLY
const std::vector<std::string>* lang_list = translations->getLanguageList();
const int amount = (int)lang_list->size();
@ -109,7 +109,7 @@ void OptionsScreenLanguage::init()
list_widget->addItem(nice_name_2_id[nice_lang_list[i]],
nice_lang_list[i]);
}
#endif
list_widget->setSelectionID( list_widget->getItemID(UserConfigParams::m_language) );
// Forbid changing language while in-game, since this crashes (changing the language involves

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include <assert.h>
#include "dictionary.hpp"
@ -246,3 +248,4 @@ std::set<wchar_t> Dictionary::get_all_used_chars()
} // namespace tinygettext
/* EOF */
#endif

View File

@ -18,6 +18,8 @@
#ifndef HEADER_TINYGETTEXT_DICTIONARY_HPP
#define HEADER_TINYGETTEXT_DICTIONARY_HPP
#ifndef SERVER_ONLY
#include <map>
#include <vector>
#include <string>
@ -135,3 +137,4 @@ public:
#endif
/* EOF */
#endif

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "dictionary_manager.hpp"
#include "utils/log.hpp"
@ -297,3 +299,4 @@ std::string DictionaryManager::convertFilename2Language(const std::string &s_in)
/* EOF */
#endif

View File

@ -18,6 +18,8 @@
#ifndef HEADER_TINYGETTEXT_DICTIONARY_MANAGER_HPP
#define HEADER_TINYGETTEXT_DICTIONARY_MANAGER_HPP
#ifndef SERVER_ONLY
#include <map>
#include <set>
#include <string>
@ -103,3 +105,4 @@ private:
#endif
/* EOF */
#endif

View File

@ -18,6 +18,8 @@
#ifndef HEADER_TINYGETTEXT_FILE_SYSTEM_HPP
#define HEADER_TINYGETTEXT_FILE_SYSTEM_HPP
#ifndef SERVER_ONLY
#include <vector>
#include <memory>
#include <iosfwd>
@ -39,4 +41,4 @@ public:
#endif
/* EOF */
#endif

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "language.hpp"
#include "utils/string_utils.hpp"
@ -579,3 +581,5 @@ Language::operator!=(const Language& rhs)
} // namespace tinygettext
/* EOF */
#endif

View File

@ -18,6 +18,8 @@
#ifndef HEADER_TINYGETTEXT_LANGUAGE_HPP
#define HEADER_TINYGETTEXT_LANGUAGE_HPP
#ifndef SERVER_ONLY
#include <string>
namespace tinygettext {
@ -89,3 +91,5 @@ inline bool operator<(const Language& lhs, const Language& rhs) {
#endif
/* EOF */
#endif

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "plural_forms.hpp"
#include <map>
@ -114,3 +116,4 @@ PluralForms::from_string(const std::string& str)
} // namespace tinygettext
/* EOF */
#endif

View File

@ -18,6 +18,8 @@
#ifndef HEADER_TINYGETTEXT_PLURAL_FORMS_HPP
#define HEADER_TINYGETTEXT_PLURAL_FORMS_HPP
#ifndef SERVER_ONLY
#include <string>
namespace tinygettext {
@ -59,3 +61,4 @@ public:
#endif
/* EOF */
#endif

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "po_parser.hpp"
#include <iostream>
@ -496,3 +498,4 @@ POParser::parse()
} // namespace tinygettext
/* EOF */
#endif

View File

@ -18,6 +18,8 @@
#ifndef HEADER_TINYGETTEXT_PO_PARSER_HPP
#define HEADER_TINYGETTEXT_PO_PARSER_HPP
#ifndef SERVER_ONLY
#include <iosfwd>
#include <string>
@ -76,3 +78,4 @@ private:
#endif
/* EOF */
#endif

View File

@ -15,6 +15,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SERVER_ONLY
#include "stk_file_system.hpp"
#include <sys/types.h>
@ -53,3 +55,5 @@ StkFileSystem::open_file(const std::string& filename)
} // namespace tinygettext
/* EOF */
#endif

View File

@ -18,6 +18,8 @@
#ifndef HEADER_TINYGETTEXT_STK_FILE_SYSTEM_HPP
#define HEADER_TINYGETTEXT_STK_FILE_SYSTEM_HPP
#ifndef SERVER_ONLY
#include "file_system.hpp"
namespace tinygettext {
@ -36,3 +38,5 @@ public:
#endif
/* EOF */
#endif

View File

@ -55,15 +55,15 @@
// Define TEST_BIDI to force right-to-left style for all languages
//#define TEST_BIDI
using namespace tinygettext;
Translations* translations = NULL;
const bool REMOVE_BOM = false;
#ifdef LINUX // m_debug
#define PACKAGE "supertuxkart"
#endif
#ifndef SERVER_ONLY
const bool REMOVE_BOM = false;
using namespace tinygettext;
/** The list of available languages; this is global so that it is cached (and remains
even if the translations object is deleted and re-created) */
typedef std::vector<std::string> LanguageList;
@ -75,6 +75,7 @@ const LanguageList* Translations::getLanguageList() const
{
return &g_language_list;
}
#endif
// ----------------------------------------------------------------------------
/** Frees the memory allocated for the result of toFribidiChar(). */
@ -178,6 +179,7 @@ wchar_t* fromFribidiChar(const FriBidiChar* str)
// ----------------------------------------------------------------------------
Translations::Translations() //: m_dictionary_manager("UTF-16")
{
#ifndef SERVER_ONLY
m_dictionary_manager.add_directory(
file_manager->getAsset(FileManager::TRANSLATION,""));
@ -416,6 +418,8 @@ Translations::Translations() //: m_dictionary_manager("UTF-16")
#ifdef TEST_BIDI
m_rtl = true;
#endif
#endif
} // Translations
// ----------------------------------------------------------------------------
@ -428,6 +432,9 @@ Translations::~Translations()
const wchar_t* Translations::fribidize(const wchar_t* in_ptr)
{
#ifdef SERVER_ONLY
return in_ptr;
#else
if (isRTLText(in_ptr))
{
// Test if this string was already fribidized
@ -467,6 +474,7 @@ const wchar_t* Translations::fribidize(const wchar_t* in_ptr)
}
else
return in_ptr;
#endif
}
bool Translations::isRTLText(const wchar_t *in_ptr)
@ -513,6 +521,13 @@ const wchar_t* Translations::w_gettext(const wchar_t* original, const char* cont
*/
const wchar_t* Translations::w_gettext(const char* original, const char* context)
{
#ifdef SERVER_ONLY
static irr::core::stringw dummy_for_server;
dummy_for_server = StringUtils::utf8ToWide(original);
return dummy_for_server.c_str();
#else
if (original[0] == '\0') return L"";
#if TRANSLATE_VERBOSE
@ -548,6 +563,7 @@ const wchar_t* Translations::w_gettext(const char* original, const char* context
#endif
return out_ptr;
#endif
}
/**
@ -573,11 +589,18 @@ const wchar_t* Translations::w_ngettext(const wchar_t* singular, const wchar_t*
*/
const wchar_t* Translations::w_ngettext(const char* singular, const char* plural, int num, const char* context)
{
static core::stringw str_buffer;
#ifdef SERVER_ONLY
str_buffer = StringUtils::utf8ToWide(singular);
return str_buffer.c_str();
#else
const std::string& res = (context == NULL ?
m_dictionary.translate_plural(singular, plural, num) :
m_dictionary.translate_ctxt_plural(context, singular, plural, num));
static core::stringw str_buffer;
str_buffer = StringUtils::utf8ToWide(res);
const wchar_t* out_ptr = str_buffer.c_str();
if (REMOVE_BOM) out_ptr++;
@ -587,28 +610,8 @@ const wchar_t* Translations::w_ngettext(const char* singular, const char* plural
#endif
return out_ptr;
}
#endif
bool Translations::isRTLLanguage() const
{
return m_rtl;
}
std::set<wchar_t> Translations::getCurrentAllChar()
{
return m_dictionary.get_all_used_chars();
}
std::string Translations::getCurrentLanguageName()
{
return m_current_language_name;
//return m_dictionary_manager.get_language().get_name();
}
std::string Translations::getCurrentLanguageNameCode()
{
return m_current_language_name_code;
}
core::stringw Translations::fribidizeLine(const core::stringw &str)
@ -662,9 +665,28 @@ core::stringw Translations::fribidizeLine(const core::stringw &str)
}
#ifndef SERVER_ONLY
std::set<wchar_t> Translations::getCurrentAllChar()
{
return m_dictionary.get_all_used_chars();
}
std::string Translations::getCurrentLanguageName()
{
return m_current_language_name;
//return m_dictionary_manager.get_language().get_name();
}
std::string Translations::getCurrentLanguageNameCode()
{
return m_current_language_name_code;
}
const std::string& Translations::getLocalizedName(const std::string& str) const
{
std::map<std::string, std::string>::const_iterator n = m_localized_name.find(str);
assert (n != m_localized_name.end());
return n->second;
}
#endif

View File

@ -21,13 +21,15 @@
#include <irrString.h>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "utils/string_utils.hpp"
#ifndef SERVER_ONLY
#include "tinygettext/tinygettext.hpp"
#endif
# define _(String, ...) (translations->fribidize(StringUtils::insertValues(translations->w_gettext(String), ##__VA_ARGS__)))
#undef _C
@ -46,6 +48,7 @@
class Translations
{
private:
#ifndef SERVER_ONLY
tinygettext::DictionaryManager m_dictionary_manager;
tinygettext::Dictionary m_dictionary;
@ -57,6 +60,7 @@ private:
std::string m_current_language_name;
std::string m_current_language_name_code;
#endif
public:
Translations();
@ -67,14 +71,22 @@ public:
const wchar_t *w_ngettext(const wchar_t* singular, const wchar_t* plural, int num, const char* context=NULL);
const wchar_t *w_ngettext(const char* singular, const char* plural, int num, const char* context=NULL);
bool isRTLLanguage() const
{
#ifdef SERVER_ONLY
return false;
#else
return m_rtl;
#endif
}
bool isRTLLanguage() const;
const wchar_t* fribidize(const wchar_t* in_ptr);
const wchar_t* fribidize(const irr::core::stringw &str) { return fribidize(str.c_str()); }
bool isRTLText(const wchar_t* in_ptr);
bool isRTLText(const irr::core::stringw &str) { return isRTLText(str.c_str()); }
#ifndef SERVER_ONLY
const std::vector<std::string>* getLanguageList() const;
std::set<wchar_t> getCurrentAllChar();
@ -84,6 +96,7 @@ public:
std::string getCurrentLanguageNameCode();
const std::string& getLocalizedName(const std::string& str) const;
#endif
private:
irr::core::stringw fribidizeLine(const irr::core::stringw &str);