2009-02-28 19:46:47 -05:00
|
|
|
// $Id: transation.cpp 839 2006-10-24 00:01:56Z hiker $
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2006, 2007, 2008 Joerg Henrichs
|
|
|
|
//
|
|
|
|
// 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 3
|
|
|
|
// 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, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
|
2009-05-25 00:29:09 -04:00
|
|
|
// Note: the irrlicht include is only here (and esp. before including
|
|
|
|
// translation.hpp, which contradicts our style rule) to avoid the
|
|
|
|
// warning message " 'swprintf' : macro redefinition"
|
|
|
|
// This happens if libintl.h is included before irrlicht.h (since
|
|
|
|
// both files redefine swprintf).
|
|
|
|
|
2009-03-11 23:49:31 -04:00
|
|
|
#include "utils/translation.hpp"
|
|
|
|
|
2010-01-10 22:34:36 -05:00
|
|
|
#include <assert.h>
|
2009-12-13 20:40:54 -05:00
|
|
|
#include <locale.h>
|
2010-01-07 19:23:31 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <iostream>
|
|
|
|
|
2010-01-11 16:50:30 -05:00
|
|
|
#include "irrlicht.h"
|
2010-01-07 19:23:31 -05:00
|
|
|
|
2010-01-11 16:50:30 -05:00
|
|
|
#include "io/file_manager.hpp"
|
2009-12-13 20:40:54 -05:00
|
|
|
|
2010-01-11 18:22:44 -05:00
|
|
|
// set to 1 to debug i18n
|
|
|
|
#define TRANSLATE_VERBOSE 0
|
|
|
|
|
2009-02-28 19:46:47 -05:00
|
|
|
|
|
|
|
Translations* translations=NULL;
|
2010-01-11 18:22:44 -05:00
|
|
|
bool remove_bom = false;
|
2009-02-28 19:46:47 -05:00
|
|
|
|
2010-01-11 16:50:30 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2010-01-07 19:23:31 -05:00
|
|
|
Translations::Translations()
|
|
|
|
{
|
2010-01-11 16:50:30 -05:00
|
|
|
#ifdef ENABLE_NLS
|
2009-02-28 19:46:47 -05:00
|
|
|
// LC_ALL does not work, sscanf will then not always be able
|
|
|
|
// to scan for example: s=-1.1,-2.3,-3.3 correctly, which is
|
|
|
|
// used in driveline files.
|
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
|
|
|
// Windows does not have LC_MESSAGES
|
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
#else
|
|
|
|
setlocale(LC_MESSAGES, "");
|
|
|
|
#endif
|
|
|
|
bindtextdomain (PACKAGE, file_manager->getTranslationDir().c_str());
|
2010-01-11 18:22:44 -05:00
|
|
|
if (sizeof(wchar_t) == 4)
|
|
|
|
{
|
|
|
|
// FIXME: will probably not work on PPC maccs
|
|
|
|
bind_textdomain_codeset(PACKAGE, "UTF-32LE");
|
|
|
|
}
|
|
|
|
else if (sizeof(wchar_t) == 2)
|
|
|
|
{
|
|
|
|
bind_textdomain_codeset(PACKAGE, "UTF-16LE");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Your wchar_t is neither 2 byte-long nor 4. What now??\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-01-10 22:12:35 -05:00
|
|
|
|
2009-02-28 19:46:47 -05:00
|
|
|
textdomain (PACKAGE);
|
|
|
|
#endif
|
2009-08-30 14:21:59 -04:00
|
|
|
|
2009-02-28 19:46:47 -05:00
|
|
|
} // Translations
|
2010-01-11 16:50:30 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
const wchar_t* Translations::w_gettext(const char* original)
|
2009-08-30 15:18:05 -04:00
|
|
|
{
|
2010-01-07 19:23:31 -05:00
|
|
|
if (original[0] == '\0') return L"";
|
|
|
|
|
2010-01-11 18:22:44 -05:00
|
|
|
#if TRANSLATE_VERBOSE
|
2010-01-07 19:23:31 -05:00
|
|
|
std::cout << "Translating " << original << "\n";
|
2010-01-11 18:22:44 -05:00
|
|
|
#endif
|
2010-01-07 19:23:31 -05:00
|
|
|
|
2009-08-30 15:57:51 -04:00
|
|
|
#if ENABLE_NLS
|
2009-08-30 15:18:05 -04:00
|
|
|
const char* original_t = gettext(original);
|
2009-08-30 15:57:51 -04:00
|
|
|
#else
|
2010-01-11 16:50:30 -05:00
|
|
|
m_converted_string = core::stringw(original);
|
|
|
|
return m_converted_string.c_str();
|
2009-08-30 15:57:51 -04:00
|
|
|
#endif
|
2010-01-11 18:22:44 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
std::cout << "--> original_t==original ? " << (original_t==original) << std::endl;
|
|
|
|
int zeros = 0;
|
|
|
|
for (int n=0;; n+=1)
|
|
|
|
{
|
|
|
|
std::cout << original_t[n] << " (" << (unsigned)(original_t[n]) << ")\n";
|
|
|
|
if (original_t[n] == 0)
|
|
|
|
{
|
|
|
|
zeros++;
|
|
|
|
if (zeros >= 4) break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zeros = 0;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
2010-01-11 16:50:30 -05:00
|
|
|
if(original_t==original)
|
2010-01-10 22:12:35 -05:00
|
|
|
{
|
2010-01-11 16:50:30 -05:00
|
|
|
m_converted_string = core::stringw(original);
|
2010-01-11 18:22:44 -05:00
|
|
|
|
|
|
|
#if TRANSLATE_VERBOSE
|
|
|
|
std::wcout << L" translation : " << m_converted_string.c_str() << std::endl;
|
|
|
|
#endif
|
2010-01-11 16:50:30 -05:00
|
|
|
return m_converted_string.c_str();
|
2010-01-10 22:12:35 -05:00
|
|
|
}
|
2010-01-11 18:22:44 -05:00
|
|
|
|
|
|
|
// print
|
|
|
|
//for (int n=0;; n+=4)
|
|
|
|
|
2010-01-10 22:12:35 -05:00
|
|
|
wchar_t* out_ptr = (wchar_t*)original_t;
|
2010-01-11 18:22:44 -05:00
|
|
|
if (remove_bom) out_ptr++;
|
|
|
|
#if TRANSLATE_VERBOSE
|
|
|
|
std::wcout << L" translation : " << out_ptr << std::endl;
|
|
|
|
#endif
|
2010-01-07 19:23:31 -05:00
|
|
|
return out_ptr;
|
|
|
|
|
2009-08-30 15:18:05 -04:00
|
|
|
}
|