r19260 - gnucash/trunk/src/gnome-utils - OSX: Use the language list instead of the locale
John Ralls
jralls at code.gnucash.org
Tue Jun 15 18:47:35 EDT 2010
Author: jralls
Date: 2010-06-15 18:47:35 -0400 (Tue, 15 Jun 2010)
New Revision: 19260
Trac: http://svn.gnucash.org/trac/changeset/19260
Modified:
gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
Log:
OSX: Use the language list instead of the locale
Language list is better than locale:
* Locale is only one choice, language list gives user several chances
before defaulting to english.
* Locale is set on the Formats page in System Preferences>Language &
Text and labelled "Region", which makes one think that it's separate
from language choices.
* This new code looks at only the first two letters, so any time
(e.g.) German is selected as the language it will use the de_DE
localization. This will have to be elaborated if we ever get
regional language translations.
Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c 2010-06-15 21:41:47 UTC (rev 19259)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c 2010-06-15 22:47:35 UTC (rev 19260)
@@ -310,8 +310,9 @@
NSArray *prefix_comps = [[prefix pathComponents]
arrayByAddingObjectsFromArray: components];
NSString *docs_dir = [NSString pathWithComponents: prefix_comps];
- NSString * cur_locale = [[NSLocale currentLocale] localeIdentifier] ;
- BOOL dir, exists;
+ NSArray *languages = [[NSUserDefaults standardUserDefaults]
+ objectForKey: @"AppleLanguages"];
+ BOOL dir;
subdir = [[[subdir lowercaseString] componentsSeparatedByString: @" "]
componentsJoinedByString: @"-"];
if (![[NSFileManager defaultManager] fileExistsAtPath: docs_dir]) {
@@ -322,17 +323,37 @@
[pool release];
return;
}
- exists = [[NSFileManager defaultManager]
- fileExistsAtPath: [docs_dir
- stringByAppendingPathComponent: cur_locale]
- isDirectory: &dir];
- if (exists && dir)
- url = [NSURL
- fileURLWithPath: [[[[docs_dir
- stringByAppendingPathComponent: cur_locale]
- stringByAppendingPathComponent: subdir]
- stringByAppendingPathComponent: tag]
- stringByAppendingPathExtension: @"html"]];
+ if ([languages count] > 0) {
+ NSEnumerator *lang_iter = [languages objectEnumerator];
+ NSString *path;
+ NSString *this_lang;
+ while(this_lang = [lang_iter nextObject]) {
+ NSArray *elements;
+ unsigned int paths;
+ NSString *completed_path = [NSString alloc];
+ this_lang = [this_lang stringByTrimmingCharactersInSet:
+ [NSCharacterSet characterSetWithCharactersInString:
+ @"\""]];
+ elements = [this_lang componentsSeparatedByString: @"-"];
+ this_lang = [elements objectAtIndex: 0];
+ path = [docs_dir stringByAppendingPathComponent: this_lang];
+ paths = [path completePathIntoString: &completed_path
+ caseSensitive: FALSE
+ matchesIntoArray: NULL filterTypes: NULL];
+ if (paths > 1 &&
+ [[NSFileManager defaultManager]
+ fileExistsAtPath: completed_path
+ isDirectory: &dir])
+ if (dir) {
+ url = [NSURL fileURLWithPath:
+ [[[completed_path
+ stringByAppendingPathComponent: subdir]
+ stringByAppendingPathComponent: tag]
+ stringByAppendingPathExtension: @"html"]];
+ break;
+ }
+ }
+ }
if (!url)
url = [NSURL
fileURLWithPath: [[[[docs_dir
@@ -342,7 +363,7 @@
stringByAppendingPathExtension: @"html"]];
}
-/* It's a lot easier in a bundle! */
+/* It's a lot easier in a bundle! OSX finds the best translation for us. */
else
url = [NSURL fileURLWithPath: [[NSBundle mainBundle]
pathForResource: tag
@@ -350,7 +371,14 @@
inDirectory: subdir ]];
/* Now just open the URL in the default app for opening URLs */
- [[NSWorkspace sharedWorkspace] openURL: url];
+ if (url)
+ [[NSWorkspace sharedWorkspace] openURL: url];
+ else {
+ const gchar *message =
+ _("GnuCash could not find the files for the help documentation. "
+ "This is likely because the 'gnucash-docs' package is not installed.");
+ gnc_error_dialog(NULL, "%s", message);
+ }
[pool release];
}
#elif defined G_OS_WIN32 /* G_OS_WIN32 */
More information about the gnucash-changes
mailing list