From 1726efed12b6b82d8af033b544fe4fea06d2dba2 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Fri, 28 Oct 2005 08:04:44 +0000 Subject: [PATCH] GetPreferredLanguage. --- .../src/arch/ArchHooks/ArchHooks_darwin.cpp | 17 ++++++++++++++++- stepmania/src/arch/ArchHooks/ArchHooks_darwin.h | 12 ++---------- .../src/archutils/Darwin/PreferredLanguage.m | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 stepmania/src/archutils/Darwin/PreferredLanguage.m diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp index a994e3e8cd..46181dd3b4 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp @@ -230,6 +230,21 @@ void ArchHooks_darwin::DumpDebugInfo() LOG->Info("Memory: %ld MB total, %ld MB swap", ram, vRam); } +// In archutils/darwin/PreferredLanguage.m +extern "C" +{ + extern char *GetPreferredLanguage(); +} + +CString ArchHooks_darwin::GetPreferredLanguage() +{ + char *lang = ::GetPreferredLanguage(); + CString ret = lang; + + free(lang); + return ret.ToUpper(); +} + void ArchHooks_darwin::EnterTimeCriticalSection() { #if 0 @@ -295,7 +310,7 @@ int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate ) } /* - * (c) 2003-2004 Steve Checkoway + * (c) 2003-2005 Steve Checkoway * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.h b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.h index ab6f7c6fe6..c4ad3b995a 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.h @@ -1,13 +1,5 @@ #ifndef ARCH_HOOKS_DARWIN_H #define ARCH_HOOKS_DARWIN_H -/* - * ArchHooks_darwin.h - * stepmania - * - * Created by Steve Checkoway on Tue Jul 15 2003. - * Copyright (c) 2003 Steve Checkoway. All rights reserved. - * - */ #include "ArchHooks.h" class RageMutex; @@ -18,7 +10,7 @@ public: ArchHooks_darwin(); ~ArchHooks_darwin(); void DumpDebugInfo(); - + CString GetPreferredLanguage(); void EnterTimeCriticalSection(); void ExitTimeCriticalSection(); @@ -34,7 +26,7 @@ protected: #endif /* ARCH_HOOKS_DARWIN_H */ /* - * (c) 2003-2004 Steve Checkoway + * (c) 2003-2005 Steve Checkoway * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a diff --git a/stepmania/src/archutils/Darwin/PreferredLanguage.m b/stepmania/src/archutils/Darwin/PreferredLanguage.m new file mode 100644 index 0000000000..b3c663edab --- /dev/null +++ b/stepmania/src/archutils/Darwin/PreferredLanguage.m @@ -0,0 +1,14 @@ +#import "Cocoa/Cocoa.h" + +char *GetPreferredLanguage() +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSUserDefaults *def = [NSUserDefaults standardUserDefaults]; + NSArray *languages = [def objectForKey:@"AppleLanguages"]; + const char *lang = [[languages objectAtIndex:0] UTF8String]; + char *ret = (char *)malloc( strlen(lang) + 1 ); + + strcpy(ret, lang); + [pool release]; + return ret; +}