Codebase list mirage / 0cbcae2
Properly set up translations Thomas Ross 3 years ago
2 changed file(s) with 38 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
2626 import os
2727 import sys
2828 import site
29 import gettext
30 import locale
2931
3032 from gi.repository import Gio, Gdk
3133
3234
35 LOCALE_DOMAIN = "mirage"
3336 MIRAGE_RESOURCE_FILE_NAME = "io.thomasross.mirage.gresource"
3437
3538
5255 return path
5356
5457 return None
58
59
60 def get_locale_directory():
61 ru_mo_file = get_data_file_path(
62 os.path.join("share", "locale", "ru", "LC_MESSAGES", "mirage.mo")
63 )
64
65 if not ru_mo_file:
66 return None
67
68 return os.path.dirname(os.path.dirname(os.path.dirname(ru_mo_file)))
5569
5670
5771 def main():
8599
86100 import mirage
87101
102 try:
103 locale.setlocale(locale.LC_ALL, "")
104 except locale.Error as e:
105 print("Could not set locale: {}.".format(e), 'Using "C".', file=sys.stderr)
106 locale.setlocale(locale.LC_ALL, "C")
107
108 locale_directory = get_locale_directory()
109 gettext.bindtextdomain(LOCALE_DOMAIN, locale_directory)
110 gettext.textdomain(LOCALE_DOMAIN)
111 translation = gettext.translation(LOCALE_DOMAIN, locale_directory, fallback=True)
112 translation.install()
113
114 try:
115 locale.bindtextdomain(LOCALE_DOMAIN, locale_directory)
116 locale.bind_textdomain_codeset(LOCALE_DOMAIN, "UTF-8")
117 locale.textdomain(LOCALE_DOMAIN)
118 except locale.error as e:
119 print(
120 "Could not bind locale domain: {}.".format(e),
121 "Not all translations will work.",
122 file=sys.stderr,
123 )
124
88125 app = mirage.Base()
89126 Gdk.threads_enter()
90127
2626 from gi.repository import Gtk, Gdk, GdkPixbuf, GLib, Gio
2727 import cairo
2828 import os, sys, getopt, configparser, string, gc
29 import random, urllib.request, gettext, locale
29 import random, urllib.request, locale
3030 import stat, time, subprocess, shutil, filecmp
3131 import tempfile, socket, threading
3232
8080
8181 def do_activate(self):
8282 Gdk.threads_init()
83
84 # FIX THIS! Does not work on windows and what happens if mo-files exists
85 # in both dirs?
86 gettext.install("mirage", "/usr/share/locale")
87 gettext.install("mirage", "/usr/local/share/locale")
8883
8984 # Constants
9085 self.open_mode_smart = 0