Unverified Commit edf11683 authored by parafin's avatar parafin Committed by Tobias Ellinghaus

fix l10n on macos

also rework a little dt_loc_* functions fixing some memleaks

(cherry picked from commit 56880c85)
parent f5fc394c
......@@ -23,7 +23,7 @@ How to make disk image with darktable application bundle (64 bit Intel only):
$ portindex ~/ports
Add "file:///Users/<username>/ports" (change <username> to your actual login) to /opt/local/etc/macports/sources.conf before [default] line.
Install required dependencies:
$ sudo port install git exiv2 libgphoto2 gtk-osx-application-gtk3 lensfun librsvg libsoup openexr json-glib flickcurl GraphicsMagick openjpeg lua webp libsecret pugixml osm-gps-map adwaita-icon-theme tango-icon-theme intltool
$ sudo port install git exiv2 libgphoto2 gtk-osx-application-gtk3 lensfun librsvg libsoup openexr json-glib flickcurl GraphicsMagick openjpeg lua webp libsecret pugixml osm-gps-map adwaita-icon-theme tango-icon-theme intltool iso-codes
To have working OpenMP (at least partly, only for C source files) you will also need gcc6:
$ sudo port install gcc6
(llvm port, which gets installed as dependency, won't compile with macosx_deployment_target set, so comment it out when llvm is built)
......
......@@ -159,4 +159,4 @@ for arg in "$@"; do
done
unset arg
exec $GTK_DEBUG_GDB "$bundle_contents"/MacOS/"$name"-bin "$@" $SPLIT_ARGS --datadir "$bundle_data"/darktable --moduledir "$bundle_lib"/darktable --localedir "$bundle_data"/locale $EXTRA_ARGS
exec $GTK_DEBUG_GDB "$bundle_contents"/MacOS/"$name"-bin "$@" $SPLIT_ARGS $EXTRA_ARGS
......@@ -22,6 +22,7 @@
<binary>${prefix}/lib/${gtkdir}/${pkg:${gtk}:gtk_binary_version}/immodules/*.so</binary>
<binary>${prefix}/lib/gdk-pixbuf-2.0/${pkg:gdk-pixbuf-2.0:gdk_pixbuf_binary_version}/loaders/*.so</binary>
<translations name="gtk30">${prefix}/share/locale</translations>
<translations name="iso_639">${prefix}/share/locale</translations>
<translations name="darktable">${prefix:dt}/share/locale</translations>
<data>${prefix:dt}/share/darktable</data>
<data>${prefix}/share/glib-2.0/schemas/org.gtk.Settings.*.gschema.xml</data>
......@@ -30,6 +31,7 @@
<data dest="${bundle}/Contents/Resources/etc/gtk-3.0/settings.ini">${project}/settings.ini</data>
<data>${prefix}/share/mime</data>
<data>${prefix}/share/curl/curl-ca-bundle.crt</data>
<data>${prefix}/share/iso-codes/json/iso_639-2.json</data>
<data dest="${bundle}/Contents/Resources/Icons.icns">${project}/Icons.icns</data>
<data dest="${bundle}/Contents/Resources/share/applications/defaults.list">${project}/defaults.list</data>
<data dest="${bundle}/Contents/Resources/share/applications/open.desktop">${project}/open.desktop</data>
......
......@@ -151,4 +151,4 @@ if expr "$1" : '^-psn_' > /dev/null; then
shift 1
fi
exec $GTK_DEBUG_GDB "$bundle_contents"/MacOS/"$name"-bin --datadir "$bundle_data"/darktable --moduledir "$bundle_lib"/darktable --localedir "$bundle_data"/locale $EXTRA_ARGS "$@"
exec $GTK_DEBUG_GDB "$bundle_contents"/MacOS/"$name"-bin $EXTRA_ARGS "$@"
......@@ -440,6 +440,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load
char *noiseprofiles_from_command = NULL;
char *datadir_from_command = NULL;
char *moduledir_from_command = NULL;
char *localedir_from_command = NULL;
char *tmpdir_from_command = NULL;
char *configdir_from_command = NULL;
char *cachedir_from_command = NULL;
......@@ -587,7 +588,8 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load
}
else if(!strcmp(argv[k], "--localedir") && argc > k + 1)
{
bindtextdomain(GETTEXT_PACKAGE, argv[++k]);
localedir_from_command = argv[++k];
bindtextdomain(GETTEXT_PACKAGE, localedir_from_command);
argv[k-1] = NULL;
argv[k] = NULL;
}
......@@ -731,6 +733,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load
#endif
dt_loc_init_datadir(datadir_from_command);
dt_loc_init_plugindir(moduledir_from_command);
dt_loc_init_localedir(localedir_from_command);
if(dt_loc_init_tmp_dir(tmpdir_from_command))
{
fprintf(stderr, "error: invalid temporary directory: %s\n", darktable.tmpdir);
......
......@@ -230,6 +230,7 @@ typedef struct darktable_t
char *progname;
char *datadir;
char *plugindir;
char *localedir;
char *tmpdir;
char *configdir;
char *cachedir;
......
......@@ -30,6 +30,10 @@
#include <config.h>
#endif
#ifdef __APPLE__
#include "osx/osx.h"
#endif
#include "darktable.h"
#include "file_location.h"
......@@ -93,44 +97,17 @@ void dt_loc_init_user_config_dir(const char *configdir)
g_free(default_config_dir);
}
#if defined(__MACH__) || defined(__APPLE__)
#ifdef __APPLE__
char *dt_loc_find_install_dir(const char *suffix, const char *searchname)
{
gchar *curr = g_get_current_dir();
int contains = 0;
char tmp[PATH_MAX] = { 0 };
for(int k = 0; searchname[k] != 0; k++)
if(searchname[k] == '/')
{
contains = 1;
break;
}
if(searchname[0] == '/') // absolute path
snprintf(tmp, sizeof(tmp), "%s", searchname);
else if(contains) // relative path
snprintf(tmp, sizeof(tmp), "%s/%s", curr, searchname);
else
{
// no idea where we have been called. use compiled in path
g_free(curr);
return NULL;
}
size_t len = MIN(strlen(tmp), sizeof(tmp));
char *t = tmp + len; // strip off bin/darktable
for(; t > tmp && *t != '/'; t--)
;
t--;
if(*t == '.' && *(t - 1) != '.')
{
for(; t > tmp && *t != '/'; t--)
;
t--;
}
for(; t > tmp && *t != '/'; t--)
;
g_strlcpy(t, suffix, sizeof(tmp) - (t - tmp));
g_free(curr);
return g_strdup(tmp);
char *result = NULL;
char *res_path = dt_osx_get_bundle_res_path();
if(res_path)
result = g_build_filename(res_path, suffix, NULL);
g_free(res_path);
return result;
}
#elif defined(_WIN32)
char *dt_loc_find_install_dir(const char *suffix, const char *searchname)
......@@ -152,8 +129,9 @@ char *dt_loc_find_install_dir(const char *suffix, const char *searchname)
*slash = '\0';
finaldir = g_build_filename(runtime_prefix, suffix, NULL);
g_free(runtime_prefix);
return g_strdup(finaldir);
return finaldir;
}
#endif
......@@ -173,37 +151,38 @@ void dt_loc_init_user_cache_dir(const char *cachedir)
void dt_loc_init_plugindir(const char *plugindir)
{
#if defined(__MACH__) || defined(__APPLE__) || defined(_WIN32)
#if defined(__APPLE__) || defined(_WIN32)
char *suffix = g_build_filename("lib", "darktable", NULL);
char *directory = dt_loc_find_install_dir(suffix, darktable.progname);
g_free(suffix);
if(plugindir || !directory)
{
darktable.plugindir = dt_loc_init_generic(plugindir, DARKTABLE_LIBDIR);
}
else
{
darktable.plugindir = directory;
}
darktable.plugindir = dt_loc_init_generic(plugindir, directory ? directory : DARKTABLE_LIBDIR);
g_free(directory);
#else
darktable.plugindir = dt_loc_init_generic(plugindir, DARKTABLE_LIBDIR);
#endif
}
void dt_loc_init_localedir(const char *localedir)
{
#if defined(__APPLE__) || defined(_WIN32)
char *suffix = g_build_filename("share", "locale", NULL);
char *directory = dt_loc_find_install_dir(suffix, darktable.progname);
g_free(suffix);
darktable.localedir = dt_loc_init_generic(localedir, directory ? directory : DARKTABLE_LOCALEDIR);
g_free(directory);
#else
darktable.localedir = dt_loc_init_generic(localedir, DARKTABLE_LOCALEDIR);
#endif
}
void dt_loc_init_datadir(const char *datadir)
{
#if defined(__MACH__) || defined(__APPLE__) || defined(_WIN32)
#if defined(__APPLE__) || defined(_WIN32)
char *suffix = g_build_filename("share", "darktable", NULL);
char *directory = dt_loc_find_install_dir(suffix, darktable.progname);
g_free(suffix);
if(datadir || !directory)
{
darktable.datadir = dt_loc_init_generic(datadir, DARKTABLE_DATADIR);
}
else
{
darktable.datadir = directory;
}
darktable.datadir = dt_loc_init_generic(datadir, directory ? directory : DARKTABLE_DATADIR);
g_free(directory);
#else
darktable.datadir = dt_loc_init_generic(datadir, DARKTABLE_DATADIR);
#endif
......@@ -215,6 +194,11 @@ void dt_loc_get_plugindir(char *plugindir, size_t bufsize)
snprintf(plugindir, bufsize, "%s", darktable.plugindir);
}
void dt_loc_get_localedir(char *localedir, size_t bufsize)
{
snprintf(localedir, bufsize, "%s", darktable.localedir);
}
void dt_loc_get_user_config_dir(char *configdir, size_t bufsize)
{
snprintf(configdir, bufsize, "%s", darktable.configdir);
......
......@@ -28,6 +28,8 @@ gchar *dt_loc_get_home_dir(const gchar *user);
void dt_loc_init_datadir(const char *datadir);
/** get the plugin dir */
void dt_loc_init_plugindir(const char *plugindir);
/** init the locale dir */
void dt_loc_init_localedir(const char *localedir);
/** get user local dir */
int dt_loc_init_tmp_dir(const char *tmpdir);
/** get user config dir */
......@@ -38,6 +40,7 @@ void dt_loc_init_user_cache_dir(const char *cachedir);
/* temporary backward_compatibility*/
void dt_loc_get_datadir(char *datadir, size_t bufsize);
void dt_loc_get_plugindir(char *plugindir, size_t bufsize);
void dt_loc_get_localedir(char *localedir, size_t bufsize);
void dt_loc_get_tmp_dir(char *tmpdir, size_t bufsize);
void dt_loc_get_user_config_dir(char *configdir, size_t bufsize);
void dt_loc_get_user_cache_dir(char *cachedir, size_t bufsize);
......
......@@ -23,6 +23,10 @@
#include <gtk/gtk.h>
#include <json-glib/json-glib.h>
#ifdef __APPLE__
#include "osx/osx.h"
#endif
#ifdef _WIN32
#include "win/dtwin.h"
#include <windows.h>
......@@ -64,13 +68,22 @@ static void get_language_names(GList *languages)
JsonReader *reader = NULL;
JsonParser *parser = NULL;
GError *error = NULL;
char *filename;
#ifdef __APPLE__
char *res_path = dt_osx_get_bundle_res_path();
#endif
#if defined(_WIN32) && !defined(MSYS2_INSTALL) // TODO: add osx?
#if defined(_WIN32) && !defined(MSYS2_INSTALL)
char datadir[PATH_MAX] = { 0 };
dt_loc_get_datadir(datadir, sizeof(datadir));
char *filename = g_build_filename(datadir, "..", "iso-codes", "json", "iso_639-2.json", NULL);
filename = g_build_filename(datadir, "..", "iso-codes", "json", "iso_639-2.json", NULL);
#else
char *filename = g_build_filename(ISO_CODES_LOCATION, "iso_639-2.json", NULL);
#ifdef __APPLE__
if(res_path)
filename = g_build_filename(res_path, "share", "iso-codes", "json", "iso_639-2.json", NULL);
else
#endif
filename = g_build_filename(ISO_CODES_LOCATION, "iso_639-2.json", NULL);
#endif
if(!g_file_test(filename, G_FILE_TEST_EXISTS))
......@@ -80,12 +93,21 @@ static void get_language_names(GList *languages)
goto end;
}
#if defined(_WIN32) && !defined(MSYS2_INSTALL) // TODO: add osx?
#if defined(_WIN32) && !defined(MSYS2_INSTALL)
// on windows we are shipping the translations of iso-codes along ours
char *localedir = g_build_filename(datadir, "..", "locale", NULL);
char localedir[PATH_MAX] = { 0 };
dt_loc_get_localedir(localedir, sizeof(localedir));
bindtextdomain("iso_639", localedir);
g_free(localedir);
#else
#ifdef __APPLE__
if(res_path)
{
char localedir[PATH_MAX] = { 0 };
dt_loc_get_localedir(localedir, sizeof(localedir));
bindtextdomain("iso_639", localedir);
}
else
#endif
bindtextdomain("iso_639", ISO_CODES_LOCALEDIR);
#endif
......@@ -199,6 +221,9 @@ static void get_language_names(GList *languages)
end:
// cleanup
#ifdef __APPLE__
g_free(res_path);
#endif
g_free(filename);
if(error) g_error_free(error);
if(reader) g_object_unref(reader);
......@@ -252,13 +277,8 @@ dt_l10n_t *dt_l10n_init(gboolean init_list)
const gchar * const * default_languages = g_get_language_names();
#ifdef _WIN32
char datadir[PATH_MAX] = { 0 };
dt_loc_get_datadir(datadir, sizeof(datadir));
char *localedir = g_build_filename(datadir, "..", "locale", NULL);
#else
char * localedir = g_strdup(DARKTABLE_LOCALEDIR);
#endif
char localedir[PATH_MAX] = { 0 };
dt_loc_get_localedir(localedir, sizeof(localedir));
GDir *dir = g_dir_open(localedir, 0, NULL);
if(dir)
{
......@@ -333,8 +353,6 @@ dt_l10n_t *dt_l10n_init(gboolean init_list)
if(selected == NULL)
result->selected = result->sys_default;
g_free(localedir);
}
else
set_locale(ui_lang, old_env);
......
......@@ -18,6 +18,8 @@
#pragma once
#include <gtk/gtk.h>
#ifdef __cplusplus
extern "C" {
#endif
......@@ -26,6 +28,7 @@ void dt_osx_autoset_dpi(GtkWidget *widget);
float dt_osx_get_ppd();
void dt_osx_disallow_fullscreen(GtkWidget *widget);
gboolean dt_osx_file_trash(const char *filename, GError **error);
char* dt_osx_get_bundle_res_path();
#ifdef __cplusplus
}
......
......@@ -23,6 +23,9 @@
#include <gtk/gtk.h>
#include <gdk/gdkquartz.h>
#include <glib.h>
#ifdef MAC_INTEGRATION
#include <gtkosxapplication.h>
#endif
#include "osx.h"
void dt_osx_autoset_dpi(GtkWidget *widget)
......@@ -100,6 +103,28 @@ gboolean dt_osx_file_trash(const char *filename, GError **error)
return TRUE;
}
char* dt_osx_get_bundle_res_path()
{
char *result = NULL;
#ifdef MAC_INTEGRATION
gchar *bundle_id;
#ifdef GTK_TYPE_OSX_APPLICATION
bundle_id = quartz_application_get_bundle_id();
if(bundle_id)
result = quartz_application_get_resource_path();
#else
bundle_id = gtkosx_application_get_bundle_id();
if(bundle_id)
result = gtkosx_application_get_resource_path();
#endif
g_free(bundle_id);
#endif
return result;
}
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment