Skip to content
Browse files

尝试将 .html 和 .js 也使用 gettext 翻译,

不过发现 xgettext 无法识别 .js 语法
  • Loading branch information...
1 parent 466f1cc commit 78fc6e2a77056f7a7f0ca0b84870f7c767d5e9bc @shellexy shellexy committed
Showing with 116 additions and 9 deletions.
  1. +2 −2 data/ext/org.hotot.gmap/entry.js
  2. +3 −3 data/ui/index.html
  3. +1 −1 hotot.cmd
  4. +3 −0 hotot/agent.py
  5. +2 −1 hotot/config.py
  6. +0 −1 hotot/db.py
  7. +6 −0 hotot/hotot.py
  8. +31 −0 hotot/i18n.py
  9. +3 −0 hotot/utils.py
  10. +11 −1 hotot/view.py
  11. +45 −0 po/POTFILES.in
  12. +8 −0 setup.cfg
  13. +1 −0 setup.py
View
4 data/ext/org.hotot.gmap/entry.js
@@ -3,9 +3,9 @@ ext.HototGMap = {
id: 'org.hotot.gmap',
-name: 'Hotot GMap',
+name: _('Hotot GMap'),
-description: 'View geolocation information of tweets.',
+description: _('View geolocation information of tweets.'),
version: '1.0',
View
6 data/ui/index.html
@@ -714,9 +714,9 @@
</div>
</div>
<div class="dialog_bottom">
- <a id="btn_prefs_restore_defaults" class="button dark" href="javascript:void(0);">Restore Defaults</a>
- <a id="btn_prefs_cancel" class="button dark" href="javascript:void(0);">Cancel</a>
- <a id="btn_prefs_ok" class="button dark" href="javascript:void(0);">OK</a>
+ <a id="btn_prefs_restore_defaults" class="button dark" href="javascript:void(0);">_("Restore Defaults")</a>
+ <a id="btn_prefs_cancel" class="button dark" href="javascript:void(0);">_("Cancel")</a>
+ <a id="btn_prefs_ok" class="button dark" href="javascript:void(0);">_("OK")</a>
</div>
</div>
View
2 hotot.cmd
@@ -1,3 +1,3 @@
-start winepython\pythonw.exe hotot\hotot.py
+start winepython\pythonw.exe -m hotot.hotot
View
3 hotot/agent.py
@@ -16,6 +16,9 @@
pynotify.init('Hotot Notification')
notify = pynotify.Notification('Init', '')
+try: import i18n
+except: from gettext import gettext as _
+
webv = None
app = None
http_code_msg_table = {
View
3 hotot/config.py
@@ -1,4 +1,4 @@
-# -*- coding:utf8 -*-
+# -*- coding: UTF-8 -*-
import os
import pickle
@@ -58,6 +58,7 @@
#others:
'exts_enabled': [],
+ 'no_use_indicator': False,
}
def getconf():
View
1 hotot/db.py
@@ -12,7 +12,6 @@
else:
CAN_EVAL_SCRIPT = True
-
DEFAULT_SCREEN_NAME = ["hotot"]
def unserialize_dict(str):
View
6 hotot/hotot.py
@@ -23,6 +23,9 @@
else:
HAS_INDICATOR = True
+try: import i18n
+except: from gettext import gettext as _
+
class MainWindow:
def __init__(self):
self.build_gui()
@@ -182,8 +185,11 @@ def on_hotkey_compose(self):
pass
def main():
+ global HAS_INDICATOR
gtk.gdk.threads_init()
config.loads();
+ if config.get('no_use_indicator'):
+ HAS_INDICATOR = False
try:
import dl
libc = dl.open('/lib/libc.so.6')
View
31 hotot/i18n.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+# -*- coding: UTF-8 -*-
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
+# Author: Huang Jiahua <jhuangjiahua@gmail.com>
+# License: LGPLv3+
+# Last modified:
+
+app = 'hotot'
+
+import os, sys
+import gettext
+import json
+
+if os.path.isdir(os.path.dirname(sys.argv[0]) + '/../build/mo'):
+ gettext.install(app, os.path.dirname(sys.argv[0]) + '/../build/mo', unicode=True)
+elif os.path.isdir(os.path.dirname(sys.argv[0]) + '/build/mo'):
+ gettext.install(app, os.path.dirname(sys.argv[0]) + '/build/mo', unicode=True)
+else:
+ gettext.install(app, unicode=True)
+
+def get_i18n_json(domain=app, localedir=None, languages=None):
+ try:
+ mofile = gettext.find(domain, localedir, languages)
+ translations = gettext.GNUTranslations(open(mofile, 'rb'))
+ return json.dumps(translations._catalog, ensure_ascii=0)
+ except:
+ return '{}'
+
+if __name__=="__main__":
+ print _('')
+
View
3 hotot/utils.py
@@ -9,6 +9,9 @@
import gtk
import mimetypes, mimetools
+try: import i18n
+except: from gettext import gettext as _
+
_browser = ''
def get_desktop_environment_name():
View
12 hotot/view.py
@@ -8,6 +8,8 @@
from webkit import WebView
import utils
+try: import i18n
+except: from gettext import gettext as _
class MainView(WebView):
def __init__(self):
@@ -32,7 +34,9 @@ def __init__(self):
self.connect('navigation-requested',
self.on_navigation_requested);
self.connect('load-finished', self.on_load_finish);
- self.open('file://'+config.get_ui_object(config.template));
+ templatefile = config.get_ui_object(config.template)
+ template = open(templatefile, 'rb').read()
+ self.load_html_string(template, 'file://' + templatefile)
pass
def ctx(self, *args):
@@ -61,6 +65,12 @@ def on_navigation_requested(self, view, webframe, request):
def on_load_finish(self, view, webframe):
self.load_finish_flag = True;
+ view.execute_script("""
+ i18n_dict = %s;
+ function _(msg){
+ return msg && i18n_dict[msg] || msg;
+ };
+ """ % i18n.get_i18n_json())
agent.webv = self
agent.apply_config()
agent.set_style_scheme()
View
45 po/POTFILES.in
@@ -0,0 +1,45 @@
+data/ui/js/ui.status_box.js
+data/ui/js/ui.dm_tabs.js
+data/ui/js/jquery.layout.js
+data/ui/js/utility.db.js
+data/ui/js/sha1.js
+data/ui/js/ui.retweet_tabs.js
+data/ui/js/ui.exts_dlg.js
+data/ui/js/twitterapi.js
+data/ui/js/ui.message_dlg.js
+data/ui/js/daemon.updater.js
+data/ui/js/ui.dialog_helper.js
+data/ui/js/ui.template.js
+data/ui/js/ui.slider.js
+data/ui/js/jquery.js
+data/ui/js/ui.about_dlg.js
+data/ui/js/ui.form_checker.js
+data/ui/js/ui.common_dlg.js
+data/ui/js/ui.prefs_dlg.js
+data/ui/js/ui.notification.js
+data/ui/js/ui.action_menu.js
+data/ui/js/ui.context_menu.js
+data/ui/js/ui.header.js
+data/ui/js/utility.console.js
+data/ui/js/ui.filter.js
+data/ui/js/ui.main.js
+data/ui/js/ui.pin_dlg.js
+data/ui/js/ui.welcome.js
+data/ui/js/base64.js
+data/ui/js/jquery.ajax-queue.js
+data/ui/js/ui.profile_dlg.js
+data/ui/js/js-oauth.js
+data/ui/index.html
+data/ext/org.hotot.imagepreview/entry.js
+data/ext/org.hotot.imageupload/entry.js
+data/ext/ext.js
+data/ext/org.hotot.gmap/entry.js
+data/ext/org.hotot.sample/entry.js
+hotot/agent.py
+hotot/db.py
+hotot/config.py
+hotot/hotot.py
+hotot/view.py
+hotot/__init__.py
+hotot/socks.py
+hotot/utils.py
View
8 setup.cfg
@@ -0,0 +1,8 @@
+[install]
+prefix=/usr
+
+[build]
+i18n = True
+
+[build_i18n]
+domain = hotot
View
1 setup.py
@@ -50,6 +50,7 @@
, glob('data/ext/org.hotot.imageupload/*')),
],
cmdclass = { "build" : build_extra.build_extra,
+ "build_i18n" : build_i18n.build_i18n,
}
)

0 comments on commit 78fc6e2

Please sign in to comment.
Something went wrong with that request. Please try again.