[sword-svn] r2532 - in trunk/bindings/objc: src test
mdbergmann at crosswire.org
mdbergmann at crosswire.org
Sun Aug 1 04:54:19 MST 2010
Author: mdbergmann
Date: 2010-08-01 04:54:19 -0700 (Sun, 01 Aug 2010)
New Revision: 2532
Added:
trunk/bindings/objc/src/SwordLocaleManager.h
trunk/bindings/objc/src/SwordLocaleManager.mm
trunk/bindings/objc/test/SetClassTest.h
trunk/bindings/objc/test/SetClassTest.m
Removed:
trunk/bindings/objc/test/Test.h
trunk/bindings/objc/test/Test.m
Log:
added SwordLocaleManager which got it's own class now so that it doesn't pollute SwordManager.
Added: trunk/bindings/objc/src/SwordLocaleManager.h
===================================================================
--- trunk/bindings/objc/src/SwordLocaleManager.h (rev 0)
+++ trunk/bindings/objc/src/SwordLocaleManager.h 2010-08-01 11:54:19 UTC (rev 2532)
@@ -0,0 +1,22 @@
+//
+// SwordLocaleManager.h
+// ObjCSword
+//
+// Created by Manfred Bergmann on 01.08.10.
+// Copyright 2010 Software by MABE. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+ at interface SwordLocaleManager : NSObject {
+}
+
++ (SwordLocaleManager *)defaultManager;
+
+/**
+ Initializes the global locale system.
+ Any created instance that needs localozed information will use it.
+ */
+- (void)initLocale;
+
+ at end
Added: trunk/bindings/objc/src/SwordLocaleManager.mm
===================================================================
--- trunk/bindings/objc/src/SwordLocaleManager.mm (rev 0)
+++ trunk/bindings/objc/src/SwordLocaleManager.mm 2010-08-01 11:54:19 UTC (rev 2532)
@@ -0,0 +1,62 @@
+//
+// SwordLocaleManager.mm
+// ObjCSword
+//
+// Created by Manfred Bergmann on 01.08.10.
+// Copyright 2010 Software by MABE. All rights reserved.
+//
+
+#import "SwordLocaleManager.h"
+
+#include <swmgr.h> // C++ Sword API
+#include <localemgr.h>
+
+ at implementation SwordLocaleManager
+
++ (SwordLocaleManager *)defaultManager {
+ static SwordLocaleManager *instance;
+ if(instance == nil) {
+ // use default path
+ instance = [[SwordLocaleManager alloc] init];
+ }
+
+ return instance;
+}
+
+- (void)initLocale {
+ // set locale swManager
+ NSString *resourcePath = [[NSBundle bundleForClass:[SwordLocaleManager class]] resourcePath];
+ NSString *localePath = [resourcePath stringByAppendingPathComponent:@"locales.d"];
+ sword::LocaleMgr *lManager = sword::LocaleMgr::getSystemLocaleMgr();
+ lManager->loadConfigDir([localePath UTF8String]);
+
+ //get the language
+ NSArray *availLocales = [NSLocale preferredLanguages];
+
+ NSString *lang = nil;
+ NSString *loc = nil;
+ BOOL haveLocale = NO;
+ // for every language, check if we know the locales
+ sword::StringList localelist = lManager->getAvailableLocales();
+ NSEnumerator *iter = [availLocales objectEnumerator];
+ while((loc = [iter nextObject]) && !haveLocale) {
+ // check if this locale is available in SWORD
+ sword::StringList::iterator it;
+ sword::SWBuf locale;
+ for(it = localelist.begin(); it != localelist.end(); ++it) {
+ locale = *it;
+ NSString *swLoc = [NSString stringWithCString:locale.c_str() encoding:NSUTF8StringEncoding];
+ if([swLoc hasPrefix:loc]) {
+ haveLocale = YES;
+ lang = loc;
+ break;
+ }
+ }
+ }
+
+ if(haveLocale) {
+ lManager->setDefaultLocaleName([lang UTF8String]);
+ }
+}
+
+ at end
Added: trunk/bindings/objc/test/SetClassTest.h
===================================================================
--- trunk/bindings/objc/test/SetClassTest.h (rev 0)
+++ trunk/bindings/objc/test/SetClassTest.h 2010-08-01 11:54:19 UTC (rev 2532)
@@ -0,0 +1,22 @@
+//
+// SetClassTest.h
+// ObjCSword
+//
+// Created by Manfred Bergmann on 12.06.10.
+// Copyright 2010 Software by MABE. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+ at protocol TestLocal
+- (void)sayHello;
+ at end
+
+ at interface Test : NSObject <TestLocal> {
+}
+
+- (void)sayHello;
+- (void)setClass:(Class<TestLocal>)classImpl;
+
+ at end
Added: trunk/bindings/objc/test/SetClassTest.m
===================================================================
--- trunk/bindings/objc/test/SetClassTest.m (rev 0)
+++ trunk/bindings/objc/test/SetClassTest.m 2010-08-01 11:54:19 UTC (rev 2532)
@@ -0,0 +1,21 @@
+//
+// TestLocal.m
+// ObjCSword
+//
+// Created by Manfred Bergmann on 12.06.10.
+// Copyright 2010 Software by MABE. All rights reserved.
+//
+
+#import "SetClassTest.h"
+
+ at implementation Test
+
+- (void)sayHello {
+ NSLog(@"TestLocal");
+}
+
+- (void)setClass:(Class<TestLocal>)classImpl {
+ object_setClass(self, classImpl);
+}
+
+ at end
Deleted: trunk/bindings/objc/test/Test.h
===================================================================
--- trunk/bindings/objc/test/Test.h 2010-08-01 11:50:46 UTC (rev 2531)
+++ trunk/bindings/objc/test/Test.h 2010-08-01 11:54:19 UTC (rev 2532)
@@ -1,22 +0,0 @@
-//
-// TestLocal.h
-// ObjCSword
-//
-// Created by Manfred Bergmann on 12.06.10.
-// Copyright 2010 Software by MABE. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-
- at protocol TestLocal
-- (void)sayHello;
- at end
-
- at interface Test : NSObject <TestLocal> {
-}
-
-- (void)sayHello;
-- (void)setClass:(Class<TestLocal>)classImpl;
-
- at end
Deleted: trunk/bindings/objc/test/Test.m
===================================================================
--- trunk/bindings/objc/test/Test.m 2010-08-01 11:50:46 UTC (rev 2531)
+++ trunk/bindings/objc/test/Test.m 2010-08-01 11:54:19 UTC (rev 2532)
@@ -1,21 +0,0 @@
-//
-// TestLocal.m
-// ObjCSword
-//
-// Created by Manfred Bergmann on 12.06.10.
-// Copyright 2010 Software by MABE. All rights reserved.
-//
-
-#import "Test.h"
-
- at implementation Test
-
-- (void)sayHello {
- NSLog(@"TestLocal");
-}
-
-- (void)setClass:(Class<TestLocal>)classImpl {
- object_setClass(self, classImpl);
-}
-
- at end
More information about the sword-cvs
mailing list