Actually add the i18n.[ch] files...
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4073 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
984d3e1000
commit
fe1a470ca1
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
This file is part of Warzone 2100.
|
||||||
|
Copyright (C) 2005-2008 Warzone Resurrection Project
|
||||||
|
|
||||||
|
Warzone 2100 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.
|
||||||
|
|
||||||
|
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
#include "frame.h"
|
||||||
|
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Always use fallbacks on Windows */
|
||||||
|
#if defined(WZ_OS_WIN)
|
||||||
|
# undef LOCALEDIR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(LOCALEDIR)
|
||||||
|
# define LOCALEDIR "locale"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Return the language part of the selected locale
|
||||||
|
*/
|
||||||
|
const char* getLanguage(void)
|
||||||
|
{
|
||||||
|
static char language[4] = { '\0' }; // ISO639 language code has to fit in!
|
||||||
|
static BOOL haveLanguage = FALSE;
|
||||||
|
|
||||||
|
#ifdef ENABLE_NLS
|
||||||
|
if ( ! haveLanguage ) // only get language name once for speed optimization
|
||||||
|
{
|
||||||
|
char *localeName = setlocale(LC_MESSAGES, NULL);
|
||||||
|
char *delim = NULL;
|
||||||
|
|
||||||
|
haveLanguage = TRUE;
|
||||||
|
|
||||||
|
if ( !localeName )
|
||||||
|
{
|
||||||
|
return language; // Return empty string on errors
|
||||||
|
}
|
||||||
|
|
||||||
|
strlcpy(language, localeName, sizeof(language));
|
||||||
|
|
||||||
|
delim = strchr(language, '_');
|
||||||
|
|
||||||
|
if ( !delim )
|
||||||
|
{
|
||||||
|
delim = strchr(language, '.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( delim )
|
||||||
|
{
|
||||||
|
*delim = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // ENABLE_NLS
|
||||||
|
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Set the prefered language
|
||||||
|
* \param locale The locale, NOT just the language part
|
||||||
|
*/
|
||||||
|
void setLanguage(const char* locale)
|
||||||
|
{
|
||||||
|
setlocale(LC_ALL, locale);
|
||||||
|
setlocale(LC_NUMERIC, "C"); // set radix character to the period (".")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void initI18n(void)
|
||||||
|
{
|
||||||
|
setLanguage(WZ_SYSTEM_LOCALE); // Default to system locale till config is parsed
|
||||||
|
#if defined(WZ_OS_WIN)
|
||||||
|
{
|
||||||
|
// Retrieve an absolute path to the locale directory
|
||||||
|
char localeDir[PATH_MAX];
|
||||||
|
strlcpy(localeDir, PHYSFS_getBaseDir(), sizeof(localeDir));
|
||||||
|
strlcat(localeDir, "\\" LOCALEDIR, sizeof(localeDir));
|
||||||
|
|
||||||
|
// Set locale directory and translation domain name
|
||||||
|
(void)bindtextdomain(PACKAGE, localeDir);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void)bindtextdomain(PACKAGE, LOCALEDIR);
|
||||||
|
#endif
|
||||||
|
(void)textdomain(PACKAGE);
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
This file is part of Warzone 2100.
|
||||||
|
Copyright (C) 2005-2008 Warzone Resurrection Project
|
||||||
|
|
||||||
|
Warzone 2100 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.
|
||||||
|
|
||||||
|
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
#ifndef _i18n_h
|
||||||
|
#define _i18n_h
|
||||||
|
|
||||||
|
/* Check the header files have been included from frame.h if they
|
||||||
|
* are used outside of the framework library.
|
||||||
|
*/
|
||||||
|
#if !defined(_frame_h) && !defined(FRAME_LIB_INCLUDE)
|
||||||
|
# error Framework header files MUST be included from frame.h ONLY.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "gettext.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define WZ_SYSTEM_LOCALE ""
|
||||||
|
|
||||||
|
#if !defined(LC_MESSAGES)
|
||||||
|
# define LC_MESSAGES 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define _(String) gettext(String)
|
||||||
|
#define N_(String) gettext_noop(String)
|
||||||
|
|
||||||
|
// Context sensitive strings
|
||||||
|
#define P_(Context, String) pgettext(Context, String)
|
||||||
|
// Non literal context sensitive strings
|
||||||
|
#define PE_(Context, String) pgettext_expr(Context, String)
|
||||||
|
// Make xgettext recognize the context
|
||||||
|
#define NP_(Context, String) gettext_noop(String)
|
||||||
|
|
||||||
|
|
||||||
|
extern WZ_DECL_CONST const char* getLanguage(void);
|
||||||
|
extern void setLanguage(const char* locale);
|
||||||
|
extern void initI18n(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _i18n_h
|
Loading…
Reference in New Issue