def _gettext_init(): try: locale.setlocale(locale.LC_ALL, '') except locale.Error: pass unexpand = quodlibet.util.unexpand # Use the locale dir in ../build/share/locale if there is one localedir = os.path.dirname(quodlibet.const.BASEDIR) localedir = os.path.join(localedir, "build", "share", "locale") if os.path.isdir(localedir): print_d("Using local localedir: %r" % unexpand(localedir)) gettext.bindtextdomain("quodlibet", localedir) localedir = gettext.bindtextdomain("quodlibet") if os.name == "nt": import ctypes k32 = ctypes.windll.kernel32 langs = filter(None, map(locale.windows_locale.get, [k32.GetUserDefaultLCID(), k32.GetSystemDefaultLCID()])) os.environ.setdefault('LANG', ":".join(langs)) localedir = "share\\locale" try: t = gettext.translation("quodlibet", localedir, class_=GlibTranslations) except IOError: print_d("No translation found in %r" % unexpand(localedir)) t = GlibTranslations() t.install(unicode=True)
def _gettext_init(): """Call before using gettext helpers""" # set by tests if "QUODLIBET_NO_TRANS" in os.environ: return try: locale.setlocale(locale.LC_ALL, '') except locale.Error: pass if os.name == "nt": import ctypes k32 = ctypes.windll.kernel32 langs = filter(None, map(locale.windows_locale.get, [k32.GetUserDefaultUILanguage(), k32.GetSystemDefaultUILanguage()])) os.environ.setdefault('LANG', ":".join(langs)) # Use the locale dir in ../build/share/locale if there is one localedir = os.path.dirname(quodlibet.const.BASEDIR) localedir = os.path.join(localedir, "build", "share", "locale") if not os.path.isdir(localedir) and os.name == "nt": # py2exe case localedir = os.path.join( quodlibet.const.BASEDIR, "..", "..", "share", "locale") if os.path.isdir(localedir): print_d("Using local localedir: %r" % unexpand(localedir)) else: localedir = gettext.bindtextdomain("quodlibet") try: t = gettext.translation("quodlibet", localedir, class_=GlibTranslations) except IOError: print_d("No translation found in %r" % unexpand(localedir)) t = GlibTranslations() else: print_d("Translations loaded: %r" % unexpand(t.path)) debug_text = os.environ.get("QUODLIBET_TEST_TRANS") t.install(unicode=True, debug_text=debug_text)
def _gettext_init(): try: locale.setlocale(locale.LC_ALL, '') except locale.Error: pass if os.name == "nt": import ctypes k32 = ctypes.windll.kernel32 langs = filter( None, map(locale.windows_locale.get, [ k32.GetUserDefaultUILanguage(), k32.GetSystemDefaultUILanguage() ])) os.environ.setdefault('LANG', ":".join(langs)) # Use the locale dir in ../build/share/locale if there is one localedir = os.path.dirname(quodlibet.const.BASEDIR) localedir = os.path.join(localedir, "build", "share", "locale") if not os.path.isdir(localedir) and os.name == "nt": # py2exe case localedir = os.path.join(quodlibet.const.BASEDIR, "..", "..", "share", "locale") unexpand = quodlibet.util.path.unexpand if os.path.isdir(localedir): print_d("Using local localedir: %r" % unexpand(localedir)) else: localedir = gettext.bindtextdomain("quodlibet") try: t = gettext.translation("quodlibet", localedir, class_=GlibTranslations) except IOError: print_d("No translation found in %r" % unexpand(localedir)) t = GlibTranslations() else: print_d("Translations loaded: %r" % unexpand(t.path)) t.install(unicode=True)
def _gettext_init(): """Call before using gettext helpers""" # set by tests if "QUODLIBET_NO_TRANS" in environ: return set_i18n_envvars() fixup_i18n_envvars() print_d("LANGUAGE: %r" % environ.get("LANGUAGE")) print_d("LANG: %r" % environ.get("LANG")) try: locale.setlocale(locale.LC_ALL, '') except locale.Error: pass # Use the locale dir in ../build/share/locale if there is one base_dir = get_base_dir() localedir = os.path.dirname(base_dir) localedir = os.path.join(localedir, "build", "share", "locale") if not os.path.isdir(localedir) and os.name == "nt": # py2exe case localedir = os.path.join( base_dir, "..", "..", "share", "locale") if os.path.isdir(localedir): print_d("Using local localedir: %r" % unexpand(localedir)) else: localedir = gettext.bindtextdomain("quodlibet") try: t = gettext.translation("quodlibet", localedir, class_=GlibTranslations) except IOError: print_d("No translation found in %r" % unexpand(localedir)) t = GlibTranslations() else: print_d("Translations loaded: %r" % unexpand(t.path)) debug_text = environ.get("QUODLIBET_TEST_TRANS") t.install(unicode=True, debug_text=debug_text)
class TGlibTranslations(TestCase): def setUp(self): self.t = GlibTranslations() def test_ugettext(self): t = self.t.ugettext("foo") self.assertEqual(t, "foo") self.assertTrue(isinstance(t, text_type)) def test_ungettext(self): t = self.t.ungettext("foo", "bar", 1) self.assertEqual(t, "foo") self.assertTrue(isinstance(t, text_type)) t = self.t.ungettext("foo", "bar", 2) self.assertEqual(t, "bar") self.assertTrue(isinstance(t, text_type)) def test_upgettext(self): t = self.t.upgettext("ctx", "foo") self.assertEqual(t, "foo") self.assertTrue(isinstance(t, text_type)) def test_unpgettext(self): t = self.t.unpgettext("ctx", "foo", "bar", 1) self.assertEqual(t, "foo") self.assertTrue(isinstance(t, text_type)) t = self.t.unpgettext("ctx", "foo", "bar", 2) self.assertEqual(t, "bar") self.assertTrue(isinstance(t, text_type))
class TGlibTranslations(TestCase): def setUp(self): self.t = GlibTranslations() def test_ugettext(self): t = self.t.ugettext("foo") self.assertEqual(t, "foo") self.assertTrue(isinstance(t, unicode)) def test_ungettext(self): t = self.t.ungettext("foo", "bar", 1) self.assertEqual(t, "foo") self.assertTrue(isinstance(t, unicode)) t = self.t.ungettext("foo", "bar", 2) self.assertEqual(t, "bar") self.assertTrue(isinstance(t, unicode)) def test_upgettext(self): t = self.t.upgettext("ctx", "foo") self.assertEqual(t, "foo") self.assertTrue(isinstance(t, unicode)) def test_unpgettext(self): t = self.t.unpgettext("ctx", "foo", "bar", 1) self.assertEqual(t, "foo") self.assertTrue(isinstance(t, unicode)) t = self.t.unpgettext("ctx", "foo", "bar", 2) self.assertEqual(t, "bar") self.assertTrue(isinstance(t, unicode))
def setUp(self): self.t = GlibTranslations()
def __(message): """See `quodlibet._`. Avoids triggering PO scanners""" t = GlibTranslations() return t.wrap_text(t.ugettext(message))
import warnings from quodlibet.util import set_process_title, environ, cached_func from quodlibet.util import windows from quodlibet.util.path import mkdir, unexpand from quodlibet.util.i18n import GlibTranslations, set_i18n_envvars, \ fixup_i18n_envvars from quodlibet.util.dprint import print_, print_d, print_w, print_e from quodlibet.const import MinVersions, Version PLUGIN_DIRS = ["editing", "events", "playorder", "songsmenu", "playlist", "gstreamer", "covers"] GlibTranslations().install(unicode=True) class Application(object): """A main application class for controlling the application as a whole and accessing sub-modules. window - The main window which is present as long as QL is running library - The main library (see library.SongFileLibrary) librarian - The main (and atm only) librarian (see library.SongLibrarian) player - see player._base quit() - Quit the application """