International.vala 1.01 KB
Newer Older
1
/* Copyright 2016 Software Freedom Conservancy Inc.
2 3
 *
 * This software is licensed under the GNU LGPL (version 2.1 or later).
4
 * See the COPYING file in this distribution.
5 6 7 8 9 10 11 12 13 14
 */

extern const string _LANG_SUPPORT_DIR;

public const string TRANSLATABLE = "translatable";

namespace InternationalSupport {
const string SYSTEM_LOCALE = "";
const string LANGUAGE_SUPPORT_DIRECTORY = _LANG_SUPPORT_DIR;

15
void init(string package_name, string[] args, string locale = SYSTEM_LOCALE) {
16 17
    Intl.setlocale(LocaleCategory.ALL, locale);

18
    Intl.bindtextdomain(package_name, get_langpack_dir_path(args));
19 20 21
    Intl.bind_textdomain_codeset(package_name, "UTF-8");
    Intl.textdomain(package_name);
}
22 23 24

private string get_langpack_dir_path(string[] args) {
    File local_langpack_dir =
25
        File.new_for_path(Environment.find_program_in_path(args[0])).get_parent().get_parent().get_child(
26 27 28 29 30
        "locale-langpack");

    return (local_langpack_dir.query_exists(null)) ? local_langpack_dir.get_path() :
        LANGUAGE_SUPPORT_DIRECTORY;
}
31 32
}