def setUp(self):
GettextBaseTest.setUp(self)
self.localedir = os.curdir
self.mofile = MOFILE
gettext.install('gettext', self.localedir)
python类install()的实例源码
def setUp(self):
GettextBaseTest.setUp(self)
self.localedir = os.curdir
self.mofile = MOFILE
gettext.install('gettext', self.localedir)
def enable_lazy():
"""Convenience function for configuring _() to use lazy gettext
Call this at the start of execution to enable the gettextutils._
function to use lazy gettext functionality. This is useful if
your project is importing _ directly instead of using the
gettextutils.install() way of importing the _ function.
"""
global USE_LAZY
USE_LAZY = True
def __init__(self):
gettext.install('enigma2', resolveFilename(SCOPE_LANGUAGE, ""), unicode=0, codeset="utf-8")
gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE))
gettext.textdomain("enigma2")
self.activeLanguage = 0
self.catalog = None
self.lang = {}
self.InitLang()
self.callbacks = []
def setUp(self):
GettextBaseTest.setUp(self)
self.localedir = os.curdir
self.mofile = MOFILE
gettext.install('gettext', self.localedir)
def initiate_I18N(self):
default_locale, encoding = locale.getdefaultlocale()
self.available_languages = collections.OrderedDict()
self.available_languages['System locale'] = default_locale
self.available_languages['Dansk'] = 'da_DK'
self.available_languages['English'] = 'en_US'
gettext.install('worksets', self.LOCALE_DIR)
self.change_language(self.language)
def change_language(self, language_name):
lang_code = self.available_languages[language_name]
language = gettext.translation('worksets', self.LOCALE_DIR, languages=[lang_code])
language.install()
def setUp(self):
GettextBaseTest.setUp(self)
self.localedir = os.curdir
self.mofile = MOFILE
gettext.install('gettext', self.localedir)
def setUp(self):
GettextBaseTest.setUp(self)
self.localedir = os.curdir
self.mofile = MOFILE
gettext.install('gettext', self.localedir)
def i18n(self, location):
gettext.bindtextdomain('griffith', location)
gettext.textdomain('griffith')
gtk.glade.bindtextdomain('griffith', location)
gtk.glade.textdomain('griffith')
gettext.install('griffith', location, unicode=1)
def install(self,DB):
import stat
self.backup_db(DB)
'''output=Popen(['gksudo','rmdir','/var/21'],stdout=PIPE,stderr=PIPE)
output = p.stdout.read()
print output
'''
#print subprocess.check_call('cd /tmp/smart_school', shell=True)# IF OUT PUT 0 success, if 1, fail, 3 password error
#print subprocess.call('gksu chmod +x /tmp/smart_school/install.sh',shell=True,stderr=subprocess.STDOUT)# IF OUT PUT 0 success, if 1, fail, 3 password error
os.chmod('/tmp/smart_school/install.sh', stat.S_IEXEC)
output=subprocess.call('cd /tmp/smart_school\ngksu ./install.sh',shell=True)#,stderr=subprocess.STDOUT)# IF OUT PUT 0 success, if 1, fail, 3 password error
return output # success if out put is 0
def __init__(self,check=True,install=False):
"""Init Worker Thread Class."""
Thread.__init__(self)
self.SU=software_update()
self.check_only=check # True if need to run functions to check for installation
self.install_only=install
self.stopped=False
self.start() # start the thread
def on_install(self, event): # wxGlade: update_win.<event_handler>
#self.play_animation('')
if self.button_install.Label=="Check for Update":
self.button_install.Enable(False)
self.thread=update_thread(check=True,install=False)
self.progress_bar.Hide()
elif self.button_install.Label=="Install Update":
#intallhere
self.button_install.Enable(False)
self.progress_bar.Show()
self.thread=update_thread(check=False,install=True)
event.Skip()
def bindtextdomain(app_name, locale_dir=None):
"""
Bind the domain represented by app_name to the locale directory locale_dir.
It has the effect of loading translations, enabling applications for different
languages.
app_name:
a domain to look for translations, tipically the name of an application.
locale_dir:
a directory with locales like locale_dir/lang_isocode/LC_MESSAGES/app_name.mo
If omitted or None, then the current binding for app_name is used.
"""
try:
import locale
import gettext
locale.setlocale(locale.LC_ALL, "")
gtk.glade.bindtextdomain(app_name, locale_dir)
gettext.install(app_name, locale_dir, unicode=1)
except (IOError,locale.Error), e:
#force english as default locale
try:
os.environ["LANGUAGE"] = "en_US.UTF-8"
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
gtk.glade.bindtextdomain(app_name, locale_dir)
gettext.install(app_name, locale_dir, unicode=1)
return
except:
#english didnt work, just use spanish
try:
__builtins__.__dict__["_"] = lambda x : x
except:
__builtins__["_"] = lambda x : x
def setUp(self):
GettextBaseTest.setUp(self)
self.localedir = os.curdir
self.mofile = MOFILE
gettext.install('gettext', self.localedir)
def __init__(self, **kwargs):
self.ui = None
GObject.threads_init()
listen()
Gtk.Application.__init__(self, application_id='com.github.geigi.cozy')
GLib.setenv("PULSE_PROP_media.role", "music", True)
import gettext
locale.bindtextdomain('cozy', localedir)
locale.textdomain('cozy')
gettext.install('cozy', localedir)
def __handle_client_json_api_output(out_json, op, api_inst):
"""This is the main client_json_api output handling function used for
install, update and uninstall and so on."""
if "errors" in out_json:
_generate_error_messages(out_json["status"],
out_json["errors"], cmd=op)
if "data" in out_json and "repo_status" in out_json["data"]:
display_repo_failures(out_json["data"]["repo_status"])
__display_plan_messages(api_inst, frozenset([OP_STAGE_PREP,
OP_STAGE_EXEC]))
return out_json["status"]
def enable_lazy():
"""Convenience function for configuring _() to use lazy gettext
Call this at the start of execution to enable the gettextutils._
function to use lazy gettext functionality. This is useful if
your project is importing _ directly instead of using the
gettextutils.install() way of importing the _ function.
"""
global USE_LAZY
USE_LAZY = True
def install(domain, localedir):
'''
:param domain: translation domain
:param localedir: locale directory
Installs the function _() in Python’s builtin namespace, based on
domain and localedir. Codeset is always UTF-8.
As seen below, you usually mark the strings in your application that are
candidates for translation, by wrapping them in a call to the _() function,
like this:
.. sourcecode:: python
import elib.intl
elib.intl.install('myapplication', '/path/to/usr/share/locale')
print _('This string will be translated.')
Note that this is only one way, albeit the most convenient way,
to make the _() function available to your application. Because it affects
the entire application globally, and specifically Python’s built-in
namespace, localized modules should never install _(). Instead, you should
use :func:`elib.intl.install_module` to make _() available to your module.
'''
_install(domain, localedir, True)
gettext.install(domain, localedir, unicode=True)
def add_to_desktop(self, widget, desktopEntry):
subprocess.call(['xdg-desktop-icon', 'install', '--novendor', desktopEntry.desktopFile])