2017-04-07 09:09:47 +00:00
|
|
|
namespace Dino {
|
|
|
|
|
2017-08-29 19:47:53 +00:00
|
|
|
private extern const string SYSTEM_LIBDIR_NAME;
|
|
|
|
private extern const string SYSTEM_PLUGIN_DIR;
|
|
|
|
|
2017-04-07 09:09:47 +00:00
|
|
|
public class SearchPathGenerator {
|
|
|
|
|
|
|
|
public string? exec_path { get; private set; }
|
|
|
|
|
|
|
|
public SearchPathGenerator(string? exec_path) {
|
|
|
|
this.exec_path = exec_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string get_locale_path(string gettext_package, string locale_install_dir) {
|
|
|
|
string? locale_dir = null;
|
|
|
|
if (Path.get_dirname(exec_path).contains("dino") || Path.get_dirname(exec_path) == "." || Path.get_dirname(exec_path).contains("build")) {
|
|
|
|
string exec_locale = Path.build_filename(Path.get_dirname(exec_path), "locale");
|
|
|
|
if (FileUtils.test(Path.build_filename(exec_locale, "en", "LC_MESSAGES", gettext_package + ".mo"), FileTest.IS_REGULAR)) {
|
|
|
|
locale_dir = exec_locale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return locale_dir ?? locale_install_dir;
|
|
|
|
}
|
2017-08-29 19:47:53 +00:00
|
|
|
|
|
|
|
public string[] get_plugin_paths() {
|
|
|
|
string[] search_paths = new string[0];
|
|
|
|
if (Environment.get_variable("DINO_PLUGIN_DIR") != null) {
|
|
|
|
search_paths += Environment.get_variable("DINO_PLUGIN_DIR");
|
|
|
|
}
|
|
|
|
search_paths += Path.build_filename(Environment.get_home_dir(), ".local", "lib", "dino", "plugins");
|
|
|
|
string? exec_path = this.exec_path;
|
|
|
|
if (exec_path != null) {
|
|
|
|
if (!exec_path.contains(Path.DIR_SEPARATOR_S)) {
|
|
|
|
exec_path = Environment.find_program_in_path(this.exec_path);
|
|
|
|
}
|
|
|
|
if (Path.get_dirname(exec_path).contains("dino") || Path.get_dirname(exec_path) == "." || Path.get_dirname(exec_path).contains("build")) {
|
|
|
|
search_paths += Path.build_filename(Path.get_dirname(exec_path), "plugins");
|
|
|
|
}
|
|
|
|
if (Path.get_basename(Path.get_dirname(exec_path)) == "bin") {
|
|
|
|
search_paths += Path.build_filename(Path.get_dirname(Path.get_dirname(exec_path)), SYSTEM_LIBDIR_NAME, "dino", "plugins");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
search_paths += SYSTEM_PLUGIN_DIR;
|
|
|
|
return search_paths;
|
|
|
|
}
|
2017-04-07 09:09:47 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 20:05:48 +00:00
|
|
|
public static string get_storage_dir() {
|
|
|
|
return Path.build_filename(Environment.get_user_data_dir(), "dino");
|
|
|
|
}
|
|
|
|
|
2017-04-07 09:09:47 +00:00
|
|
|
[CCode (cname = "dino_gettext", cheader_filename = "dino_i18n.h")]
|
|
|
|
public static extern unowned string _(string s);
|
|
|
|
|
2017-04-12 20:42:23 +00:00
|
|
|
[CCode (cname = "dino_ngettext", cheader_filename = "dino_i18n.h")]
|
|
|
|
public static extern unowned string n(string msgid, string plural, ulong number);
|
|
|
|
|
2017-04-07 09:09:47 +00:00
|
|
|
[CCode (cname = "bindtextdomain", cheader_filename = "libintl.h")]
|
|
|
|
private static extern unowned string? bindtextdomain(string domainname, string? dirname);
|
|
|
|
|
|
|
|
[CCode (cname = "bind_textdomain_codeset", cheader_filename = "libintl.h")]
|
|
|
|
private static extern unowned string? bind_textdomain_codeset(string domainname, string? codeset);
|
|
|
|
|
|
|
|
public static void internationalize(string gettext_package, string locales_dir) {
|
|
|
|
Intl.bind_textdomain_codeset(gettext_package, "UTF-8");
|
|
|
|
Intl.bindtextdomain(gettext_package, locales_dir);
|
|
|
|
}
|
|
|
|
|
2019-11-25 22:23:06 +00:00
|
|
|
}
|