[PATCH] Support for gettext in MacOSX application bundle

Henrik Brautaset Aronsen subsurface at henrik.synth.no
Mon Oct 15 05:44:01 PDT 2012


Den 15.10.12 14:32, skrev Henrik Brautaset Aronsen:
> The MacOSX applications bundle needs to be told where to bind the
> text domain from.
>
> Also copy the gettext .mo files in the install-macosx target.

I forgot a "const".  Here's an updated patch.

H
-------------- next part --------------
From d1fa90233dbc57521b4e3e7f97214b00d0cfb47d Mon Sep 17 00:00:00 2001
From: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
Date: Mon, 15 Oct 2012 14:29:04 +0200
Subject: [PATCH] Support for gettext in MacOSX application bundle

The MacOSX applications bundle needs to be told where to bind the
text domain from.

Also copy the gettext .mo files in the install-macosx target.

Signed-off-by: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
---
 Makefile  |  4 ++++
 dive.h    |  1 +
 linux.c   |  5 +++++
 macos.c   | 13 +++++++++++++
 main.c    |  3 ++-
 windows.c |  5 +++++
 6 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index e747c5a..af2284f 100644
--- a/Makefile
+++ b/Makefile
@@ -154,6 +154,10 @@ install-macosx: $(NAME)
 	$(INSTALL) $(MACOSXFILES)/Info.plist $(MACOSXINSTALL)/Contents/
 	$(INSTALL) $(ICONFILE) $(MACOSXINSTALL)/Contents/Resources/
 	$(INSTALL) $(MACOSXFILES)/Subsurface.icns $(MACOSXINSTALL)/Contents/Resources/
+	$(INSTALL) -d -m 755 $(addprefix $(MACOSXINSTALL)/Contents/Resources/,$(dir $(MSGOBJS)))
+	for MSG in $(MSGOBJS); do\
+		install $$MSG  $(MACOSXINSTALL)/Contents/Resources/$$MSG;\
+	done
 
 file.o: file.c dive.h file.h
 	$(CC) $(CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(XSLT) $(ZIP) -c file.c
diff --git a/dive.h b/dive.h
index 42c09b5..fb1a1ba 100644
--- a/dive.h
+++ b/dive.h
@@ -435,6 +435,7 @@ extern const char *star_strings[];
 extern const char *default_filename;
 extern const char *existing_filename;
 extern const char *subsurface_default_filename(void);
+extern const char *subsurface_gettext_domainpath(void);
 extern void subsurface_command_line_init(gint *, gchar ***);
 extern void subsurface_command_line_exit(gint *, gchar ***);
 #define AIR_PERMILLE 209
diff --git a/linux.c b/linux.c
index f60f917..b97e54f 100644
--- a/linux.c
+++ b/linux.c
@@ -84,6 +84,11 @@ const char *subsurface_default_filename()
 	}
 }
 
+const char *subsurface_gettext_domainpath()
+{
+	return "./locale";
+}
+
 void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
 		GtkWidget *vbox, GtkUIManager *ui_manager)
 {
diff --git a/macos.c b/macos.c
index 3cc4ddf..3d9c9b5 100644
--- a/macos.c
+++ b/macos.c
@@ -104,6 +104,19 @@ const char *subsurface_default_filename()
 	}
 }
 
+const char *subsurface_gettext_domainpath()
+{
+	CFBundleRef mainBundle = CFBundleGetMainBundle();
+	CFURLRef localeURL = CFBundleCopyResourceURL(mainBundle, CFSTR("locale"), CFSTR(""), NULL);
+	if (localeURL) {
+		CFStringRef localePath = CFURLCopyFileSystemPath(localeURL, kCFURLPOSIXPathStyle);
+		CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
+		const char *path = CFStringGetCStringPtr(localePath, encodingMethod);
+		return path;
+	}
+	return "./locale";
+}
+
 static void show_main_window(GtkWidget *w, gpointer data)
 {
 	gtk_widget_show(main_window);
diff --git a/main.c b/main.c
index 1ca484d..5439825 100644
--- a/main.c
+++ b/main.c
@@ -230,7 +230,8 @@ int main(int argc, char **argv)
 	 * so that it uses the correct system directory when
 	 * subsurface isn't run from the local directory */
 	setlocale( LC_ALL, "" );
-	bindtextdomain("subsurface", "./locale");
+	const char *path = subsurface_gettext_domainpath();
+	bindtextdomain("subsurface", path);
 	bind_textdomain_codeset("subsurface", "utf-8");
 	textdomain("subsurface");
 	output_units = SI_units;
diff --git a/windows.c b/windows.c
index eedeccf..b099193 100644
--- a/windows.c
+++ b/windows.c
@@ -151,6 +151,11 @@ const char *subsurface_default_filename()
 	}
 }
 
+const char *subsurface_gettext_domainpath()
+{
+	return "./locale";
+}
+
 void subsurface_ui_setup(GtkSettings *settings, GtkWidget *menubar,
 		GtkWidget *vbox, GtkUIManager *ui_manager)
 {
-- 
1.7.11.5


More information about the subsurface mailing list