fixed locale support on OS X

Sat, 12 Apr 2014 13:44:53 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 12 Apr 2014 13:44:53 +0200
changeset 32
9a5f47fbc5c3
parent 31
34df61c6ec3c
child 33
458831c574f4

fixed locale support on OS X

resource/.DS_Store file | annotate | diff | comparison | revisions
resource/locales/de_DE.properties file | annotate | diff | comparison | revisions
ui/cocoa/resource.m file | annotate | diff | comparison | revisions
Binary file resource/.DS_Store has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resource/locales/de_DE.properties	Sat Apr 12 13:44:53 2014 +0200
@@ -0,0 +1,1 @@
+hello = HALLO WELT!
--- a/ui/cocoa/resource.m	Fri Apr 11 21:45:24 2014 +0200
+++ b/ui/cocoa/resource.m	Sat Apr 12 13:44:53 2014 +0200
@@ -37,16 +37,31 @@
 
 void ui_load_lang_def(char *locale, char *default_locale) {
     NSString *localeString = nil;
-    if(locale) {
+    char tmp[6];
+    if(!locale) {
+        NSString* lang = [[NSLocale currentLocale] localeIdentifier];
+        if(lang) {
+            localeString = lang;
+        } else {
+            [[NSString alloc]initWithUTF8String:default_locale];
+        }
+    } else {
         localeString = [[NSString alloc]initWithUTF8String:locale];
-    } else {
-        localeString = [[NSString alloc]initWithUTF8String:default_locale];
     }
     
     NSString *path = [[NSBundle mainBundle] pathForResource:localeString ofType:@"properties" inDirectory:@"locales"];
     
     const char *p = [path UTF8String];
-    uic_load_language_file((char*)p);
+    
+    if(uic_load_language_file((char*)p)) {
+        if(default_locale) {
+            ui_load_lang_def(default_locale, NULL);
+        } else {
+            // cannot find any language file
+            fprintf(stderr, "Ui Error: Cannot load language.\n");
+            exit(-1);
+        }
+    }
 }
 
 void ui_locales_dir(char *path) {

mercurial