From 039447dc55942416d4888a5d869598ac26f99d51 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 20 Jan 2010 18:02:57 +0000 Subject: [PATCH] actually make i18n work on OS X, and update osx_build to install .mo files (for GTK+ too) git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@6525 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/cocoacarbon.mm | 79 +++++++++++++++++++++++++++++++++++ gtk2_ardour/gettext.h | 2 +- gtk2_ardour/main.cc | 29 ++++--------- libs/ardour/gettext.h | 2 +- libs/gtkmm2ext/gettext.h | 2 +- libs/pbd/gettext.h | 2 +- tools/osx_packaging/osx_build | 30 +++++++++++-- 7 files changed, 118 insertions(+), 28 deletions(-) diff --git a/gtk2_ardour/cocoacarbon.mm b/gtk2_ardour/cocoacarbon.mm index c191ed975e..7747eaec3b 100644 --- a/gtk2_ardour/cocoacarbon.mm +++ b/gtk2_ardour/cocoacarbon.mm @@ -16,6 +16,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include +#include +#include +#include #include #include #undef check @@ -26,6 +30,14 @@ #include "actions.h" #include "opts.h" +#include +#import +#import +#import + +using namespace std; +using namespace PBD; + void ARDOUR_UI::platform_specific () { @@ -57,3 +69,70 @@ cocoa_open_url (const char* uri) return ret; } + +void +set_language_preference () +{ + if (g_getenv ("LANGUAGE") || g_getenv ("LC_ALL") || g_getenv ("LANG")) { + return; + } + + if (g_getenv ("ARDOUR_EN")) { + return; + } + + /* the gettext manual is potentially misleading about the utility of + LANGUAGE. It notes that if LANGUAGE is set to include a dialect/region-free + language code, like "it", it will assume that you mean the main + dialect (e.g. "it_IT"). But in reality, it doesn't bother looking for + locale dirs with the full name, only the short code (it doesn't + know any better). + + Since Apple's preferred language list only consists of short language codes, + if we set LANGUAGE then gettext will not look for the relevant long-form + variants. + */ + + /* how to get language preferences with CoreFoundation + */ + + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSUserDefaults* defs = [NSUserDefaults standardUserDefaults]; + NSArray* languages = [defs objectForKey:@"AppleLanguages"]; + + /* push into LANGUAGE */ + + if (languages && [languages count] > 0) { + + int i, count = [languages count]; + for (i = 0; i < count; ++i) { + if ([[languages objectAtIndex:i] + isEqualToString:@"en"]) { + count = i+1; + break; + } + } + NSRange r = { 0, count }; + NSString* s = [[languages subarrayWithRange:r] + componentsJoinedByString:@":"]; + cout << "LANGUAGE set to " << [s UTF8String] << endl; + setenv ("LANGUAGE", [s UTF8String], 0); + [s release]; + } + + /* done */ + + [pool release]; + + /* now get AppleLocale value and use that for LANG */ + + CFLocaleRef cflocale = CFLocaleCopyCurrent(); + NSString* nslocale = (NSString*) CFLocaleGetValue (cflocale, kCFLocaleIdentifier); + + /* the full POSIX locale specification allows for lots of things. that could be an issue. Silly Apple. + */ + + cout << "LANG set to " << [nslocale UTF8String] << endl; + setenv ("LANG", [nslocale UTF8String], 0); + CFRelease (cflocale); +} diff --git a/gtk2_ardour/gettext.h b/gtk2_ardour/gettext.h index 339c74ffe7..2645402e95 100644 --- a/gtk2_ardour/gettext.h +++ b/gtk2_ardour/gettext.h @@ -20,7 +20,7 @@ #define _LIBGETTEXT_H 1 /* NLS can be disabled through the configure --disable-nls option. */ -#if ENABLE_NLS +#ifdef ENABLE_NLS /* Get declarations of GNU message catalog functions. */ # include diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index 3752a67d35..b78c019488 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -66,6 +66,8 @@ static const char* localedir = LOCALEDIR; #include #include +extern void set_language_preference (); // cocoacarbon.mm + void fixup_bundle_environment () { @@ -73,26 +75,7 @@ fixup_bundle_environment () return; } - /* pull user's language preference from Cocoa and push - it into the environment. Thanks to Bjorn Winckler for - this code. - */ - - NSArray *languages = [NSLocale preferredLanguages]; - if (languages && [languages count] > 0) { - int i, count = [languages count]; - for (i = 0; i < count; ++i) { - if ([[languages objectAtIndex:i] - isEqualToString:@"en"]) { - count = i+1; - break; - } - } - NSRange r = { 0, count }; - NSString *s = [[languages subarrayWithRange:r] - componentsJoinedByString:@":"]; - setenv("LANGUAGE", [s UTF8String], 0); - } + set_language_preference (); char execpath[MAXPATHLEN+1]; uint32_t pathsz = sizeof (execpath); @@ -199,6 +182,7 @@ fixup_bundle_environment () path += "/../Resources/locale"; localedir = strdup (path.c_str()); + setenv ("GTK_LOCALEDIR", localedir, 1); /* write a pango.rc file and tell pango to use it. we'd love to put this into the Ardour.app bundle and leave it there, @@ -333,7 +317,6 @@ int main (int argc, char* argv[]) #endif Glib::thread_init(); - gtk_set_locale (); #ifdef VST_SUPPORT /* this does some magic that is needed to make GTK and Wine's own @@ -348,6 +331,10 @@ int main (int argc, char* argv[]) we use that when handling them. */ (void) bind_textdomain_codeset (PACKAGE,"UTF-8"); + + /* this really does nothing since we don't get gettext(), + only dgettext(), but whatever ... + */ (void) textdomain (PACKAGE); pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0); diff --git a/libs/ardour/gettext.h b/libs/ardour/gettext.h index 339c74ffe7..2645402e95 100644 --- a/libs/ardour/gettext.h +++ b/libs/ardour/gettext.h @@ -20,7 +20,7 @@ #define _LIBGETTEXT_H 1 /* NLS can be disabled through the configure --disable-nls option. */ -#if ENABLE_NLS +#ifdef ENABLE_NLS /* Get declarations of GNU message catalog functions. */ # include diff --git a/libs/gtkmm2ext/gettext.h b/libs/gtkmm2ext/gettext.h index 339c74ffe7..2645402e95 100644 --- a/libs/gtkmm2ext/gettext.h +++ b/libs/gtkmm2ext/gettext.h @@ -20,7 +20,7 @@ #define _LIBGETTEXT_H 1 /* NLS can be disabled through the configure --disable-nls option. */ -#if ENABLE_NLS +#ifdef ENABLE_NLS /* Get declarations of GNU message catalog functions. */ # include diff --git a/libs/pbd/gettext.h b/libs/pbd/gettext.h index 339c74ffe7..2645402e95 100644 --- a/libs/pbd/gettext.h +++ b/libs/pbd/gettext.h @@ -20,7 +20,7 @@ #define _LIBGETTEXT_H 1 /* NLS can be disabled through the configure --disable-nls option. */ -#if ENABLE_NLS +#ifdef ENABLE_NLS /* Get declarations of GNU message catalog functions. */ # include diff --git a/tools/osx_packaging/osx_build b/tools/osx_packaging/osx_build index c4e79cf236..d0a338c86c 100755 --- a/tools/osx_packaging/osx_build +++ b/tools/osx_packaging/osx_build @@ -30,7 +30,7 @@ while [ $# -gt 0 ] ; do APPNAME=Ardour ; shift ;; --mixbus) MIXBUS=1; - WITH_NLS= ; + WITH_NLS=1 ; SAE= ; INTERNAL_JACK=; WITH_LADSPA=; @@ -38,7 +38,7 @@ while [ $# -gt 0 ] ; do PRODUCT_PKG_DIR=MixBus; APPNAME=Mixbus ; shift ;; - --public) WITH_NLS= ; + --public) WITH_NLS=1 ; SAE= ; INTERNAL_JACK=; WITH_LADSPA=1; @@ -212,11 +212,34 @@ fi # copy locale files if test x$WITH_NLS != x ; then echo "NLS support ..." - for file in ../../gtk2_ardour/*.mo + echo "I hope you remembered to run scons msgupdate!" + LINGUAS= + for file in ../../gtk2_ardour/*.mo do lang=`basename $file | sed 's/\.mo//'` mkdir -p $Locale/$lang/LC_MESSAGES cp $file $Locale/$lang/LC_MESSAGES/gtk2_ardour.mo + LINGUAS="$LINGUAS $lang" + done + for file in ../../libs/ardour/*.mo + do + lang=`basename $file | sed 's/\.mo//'` + mkdir -p $Locale/$lang/LC_MESSAGES + cp $file $Locale/$lang/LC_MESSAGES/libardour.mo + done + for l in $LINGUAS + do + if [ -d $GTKQUARTZ_ROOT/share/locale/$l ] ; then + echo "Copying GTK i18n files for $l..." + cp -r $GTKQUARTZ_ROOT/share/locale/$l $Locale + else + # try with just the language spec + just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'` + if [ -d $GTKQUARTZ_ROOT/share/locale/$just_lang ] ; then + echo "Copying GTK i18n files for $just_lang..." + cp -r $GTKQUARTZ_ROOT/share/locale/$just_lang $Locale + fi + fi done else echo "Skipping NLS support" @@ -453,6 +476,7 @@ else fi echo "Building DMG ..." +exit 0 # UC_DMG=$APPNAME-${release_version}-${svn_version}-UC.dmg # FINAL_DMG=$APPNAME-${release_version}-${svn_version}.dmg