diff options
| author | Johannes Schickel | 2010-11-25 18:40:56 +0000 | 
|---|---|---|
| committer | Johannes Schickel | 2010-11-25 18:40:56 +0000 | 
| commit | 189c9bf216e8c802cff7087ccb6c11805ecbc0ca (patch) | |
| tree | c7ae01eb2b0d3a9281f12e4108e0e3be21d2c1ab /backends/platform/sdl/sdl.cpp | |
| parent | 601494cad4968ac2246a0c0820bfd9f01ec249ad (diff) | |
| download | scummvm-rg350-189c9bf216e8c802cff7087ccb6c11805ecbc0ca.tar.gz scummvm-rg350-189c9bf216e8c802cff7087ccb6c11805ecbc0ca.tar.bz2 scummvm-rg350-189c9bf216e8c802cff7087ccb6c11805ecbc0ca.zip  | |
OSYSTEM: Add API to query the system locale.
I also adapted the SDL backend to implement the API.
svn-id: r54479
Diffstat (limited to 'backends/platform/sdl/sdl.cpp')
| -rw-r--r-- | backends/platform/sdl/sdl.cpp | 67 | 
1 files changed, 67 insertions, 0 deletions
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 8a139e5c1b..ea7d4b0523 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -53,6 +53,12 @@  #include <time.h>	// for getTimeAndDate() +#ifdef USE_DETECTLANG +#ifndef WIN32 +#include <locale.h> +#endif // !WIN32 +#endif +  //#define SAMPLES_PER_SEC 11025  #define SAMPLES_PER_SEC 22050  //#define SAMPLES_PER_SEC 44100 @@ -586,6 +592,67 @@ void OSystem_SDL::logMessage(LogMessageType::Type type, const char *message) {  #endif  } +Common::Language OSystem_SDL::getSystemLanguage() const { +#ifdef USE_DETECTLANG +#ifdef WIN32 +	// We can not use "setlocale" (at least not for MSVC builds), since it +	// will return locales like: "English_USA.1252", thus we need a special +	// way to determine the locale string for Win32. +	char langName[9]; +	char ctryName[9]; + +	const LCID languageIdentifier = GetThreadLocale(); + +	// GetLocalInfo is only supported starting from Windows 2000, according to this: +	// http://msdn.microsoft.com/en-us/library/dd318101%28VS.85%29.aspx +	// On the other hand the locale constants used, seem to exist on Windows 98 too, +	// check this for that: http://msdn.microsoft.com/en-us/library/dd464799%28v=VS.85%29.aspx +	// +	// I am not exactly sure what is the truth now, it might be very well that this breaks +	// support for systems older than Windows 2000.... +	// +	// TODO: Check whether this (or ScummVM at all ;-) works on a system with Windows 98 for +	// example and if it does not and we still want Windows 9x support, we should definitly +	// think of another solution. +	if (GetLocaleInfo(languageIdentifier, LOCALE_SISO639LANGNAME, langName, sizeof(langName)) != 0 && +		GetLocaleInfo(languageIdentifier, LOCALE_SISO3166CTRYNAME, ctryName, sizeof(ctryName)) != 0) { +		Common::String localeName = langName; +		localeName += "_"; +		localeName += ctryName; + +		return Common::parseLanguageFromLocale(localeName.c_str()); +	} else { +		return Common::UNK_LANG; +	} +#else // WIN32 +	// Activating current locale settings +	const char *locale = "de_DE.utf8";//setlocale(LC_ALL, ""); + +	// Detect the language from the locale +	if (!locale) { +		return Common::UNK_LANG; +	} else { +		int length = 0; + +		// Strip out additional information, like +		// ".UTF-8" or the like. We do this, since +		// our translation languages are usually +		// specified without any charset information. +		for (int i = 0; locale[i]; ++i, ++length) { +			// TODO: Check whether "@" should really be checked +			// here. +			if (locale[i] == '.' || locale[i] == ' ' || locale[i] == '@') +				break; +		} + +		return Common::parseLanguageFromLocale(Common::String(locale, length).c_str()); +	} +#endif // WIN32 +#else // USE_DETECTLANG +	return Common::UNK_LANG; +#endif // USE_DETECTLANG +} +  void OSystem_SDL::setupIcon() {  	int x, y, w, h, ncols, nbytes, i;  	unsigned int rgba[256];  | 
