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
This commit is contained in:
Paul Davis 2010-01-20 18:02:57 +00:00
parent 2bbbcd5bdb
commit 039447dc55
7 changed files with 118 additions and 28 deletions

View File

@ -16,6 +16,10 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <string>
#include <ctype.h>
#include <stdlib.h>
#include <pbd/error.h>
#include <gtkmm2ext/gtkapplication.h>
#include <gdk/gdkquartz.h>
#undef check
@ -26,6 +30,14 @@
#include "actions.h"
#include "opts.h"
#include <CoreFoundation/CFLocale.h>
#import <CoreFoundation/CFString.h>
#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>
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);
}

View File

@ -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 <libintl.h>

View File

@ -66,6 +66,8 @@ static const char* localedir = LOCALEDIR;
#include <sys/param.h>
#include <fstream>
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);

View File

@ -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 <libintl.h>

View File

@ -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 <libintl.h>

View File

@ -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 <libintl.h>

View File

@ -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