[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: First ES translation patch and something else



Дана Friday 30 October 2009 16:11:35 Ernesto Domato написа:
> On Fri, Oct 30, 2009 at 04:42, Nikola Smolenski <smolensk@xxxxxxxx> wrote:
> > For another game I made (never implemented) a patch that reads the
> > system locale, perhaps that would be even better. I could adapt it for
> > CF if Jens approves.
>
> Yeah, I know that. Did you do it cross-platform?, because I have no
> experience programming for other platform other than Linux and I'd
> like to see how you managed it. Maybe we could make an hybrid that if
> no locale is defined on the configuration file it tries to get it from
> the system locale and if that fails too, it could use my approach.

Well, it is cross-platform in that it works properly with KDE and Gnome, but 
other than that, no. I don't know how to do it on Windows, and of course have 
no idea how to do it on embedded systems.

// Find the user's preferred language
// @author Nikola Smolenski <smolensk@xxxxxxxx>
// TODO: Windows, Mac

char strDesktopLang[64] = "", *t;

// Desktop environment detection done according to
// http://flyback.googlecode.com/svn/trunk/src/desktop.py
if(getenv("KDE_FULL_SESSION") || getenv("KDE_MULTIHEAD")) {
	// We're in KDE! Language detection done according to
	// http://faqs.pcbsd.org/index.php?action=artikel&id=332
	if(fDesktopConfig.Load(JString(getenv("HOME")) 
+ "/.kde/share/config/kdeglobals", "rb")) {
		while(fDesktopConfig.NextLine()) {
			sscanf(fDesktopConfig.GetPos(), "Language = %63s", strDesktopLang);
			if(strDesktopLang[0]) break;
		}
	}
}

if(!strDesktopLang[0]) {
	// If we're not in KDE or haven't found the language
	// there, try ~/.dmrc (it should be common across DEs)
	if(fDesktopConfig.Load(JString(getenv("HOME")) + "/.dmrc", "rb")) {
		while(fDesktopConfig.NextLine()) {
			sscanf(fDesktopConfig.GetPos(), "Language = %63s", strDesktopLang);
			if(strDesktopLang[0]) break;
		}
	}
}

if(!strDesktopLang[0]) {
	// If that didn't work, at least try $LANG
	strncpy(strDesktopLang, getenv("LANG"), 63);
}

// Cut off country code if it exists
t = strchr(strDesktopLang, '_');
if(t) *t = '\0';