Ticket #6353: trac-jsi18n.patch
| File trac-jsi18n.patch, 5.1 KB (added by jonas, 2 months ago) |
|---|
-
setup.py
21 21 extra['message_extractors'] = { 22 22 'trac': [ 23 23 ('**.py', 'python', None), 24 ('**.js', 'javascript', None), 24 25 ('**/templates/**.html', 'genshi', None), 25 26 ('**/templates/**.txt', 'genshi', { 26 27 'template_class': 'genshi.template:TextTemplate' -
trac/htdocs/js/blame.js
74 74 message = $('<div class="message">').css("position", "absolute") 75 75 .append($('<div class="inlinebuttons">') 76 76 .append($('<input value="Close" type="button">').click(hide))) 77 .append($('<div>').html(data || "<strong> (no changeset information)</strong>"))77 .append($('<div>').html(data || "<strong>" + _("(no changeset information)") + "</strong>")) 78 78 .appendTo("body"); 79 79 80 80 // workaround non-clickable "Close" issue in Firefox -
trac/templates/jsi18ncatalog.js
1 var _c = {}; 2 #for msgid, string in catalog._catalog.items() 3 #choose 4 #when msgid == '' 5 #end 6 #when isinstance(msgid, (list, tuple)) 7 _c['${javascript_quote(msgid[0])}', ${msgid[1] and 'true' or 'false'}] = '${javascript_quote(string)}'; 8 #end 9 #otherwise 10 _c['${javascript_quote(msgid)}'] = '${javascript_quote(string)}'; 11 #end 12 #end 13 #end 14 15 function gettext(msgid) { 16 var value = _c[msgid]; 17 if(typeof(value) == 'undefined') { 18 return msgid; 19 } 20 else { 21 return value; 22 } 23 } 24 _ = gettext; 25 -
trac/web/chrome.py
43 43 from trac.util.compat import partial 44 44 from trac.util.html import plaintext 45 45 from trac.util.text import pretty_size, obfuscate_email_address, \ 46 shorten_line, unicode_quote_plus, to_unicode 46 shorten_line, unicode_quote_plus, to_unicode, \ 47 javascript_quote 47 48 from trac.util.datefmt import pretty_timedelta, format_datetime, format_date, \ 48 49 format_time, http_date, utc 49 from trac.util.translation import _ 50 from trac.util.translation import _, get_translations 50 51 from trac.web.api import IRequestHandler, ITemplateStreamFilter, HTTPNotFound 51 52 from trac.web.href import Href 52 53 from trac.wiki import IWikiSyntaxProvider … … 427 428 def __init__(self, req): 428 429 self.base_path = req.base_path 429 430 self.chrome = chrome 431 self.href = req.href 430 432 fakereq = FakeRequest(req) 431 433 432 434 htdocs_location = self.htdocs_location or req.href.chrome('common') … … 444 446 add_script(fakereq, 'common/js/noconflict.js') 445 447 add_script(fakereq, 'common/js/trac.js') 446 448 add_script(fakereq, 'common/js/search.js') 449 add_script(fakereq, '/jsi18n/' + str(req.locale)) 447 450 448 451 # Shortcut icon 449 452 chrome['icon'] = self.get_icon_data(req) … … 685 688 if content_type is None: 686 689 content_type = 'text/html' 687 690 method = {'text/html': 'xhtml', 688 'text/plain': 'text'}.get(content_type, 'xml') 691 'text/plain': 'text', 692 'text/javascript': 'text'}.get(content_type, 'xml') 689 693 690 694 template = self.load_template(filename, method=method) 691 695 data = self.populate_data(req, data) … … 785 789 return stream 786 790 return inner 787 791 792 793 class JSI18NModule(Component): 794 795 implements(IRequestHandler) 796 797 # IRequestHandler methods 798 799 def match_request(self, req): 800 match = re.match('/jsi18n/([^/]+)$', req.path_info) 801 if match: 802 req.args['locale'] = match.group(1) 803 return True 804 805 def process_request(self, req): 806 # FIXME: actually get the locale specified in the url 807 data = {'catalog': get_translations(), 808 'javascript_quote': javascript_quote} 809 # FIXME: Figure out which cache headers to set 810 return "jsi18ncatalog.js", data, 'text/javascript' 811 -
trac/util/text.py
63 63 except UnicodeError: 64 64 return unicode(text, locale.getpreferredencoding(), 'replace') 65 65 66 def javascript_quote(text): 67 return text.replace('\\', '\\\\').replace('\r', '\\r') \ 68 .replace('\n', '\\n').replace('\t', '\\t') \ 69 .replace("'", "\\'") 70 66 71 def unicode_quote(value, safe='/'): 67 72 """A unicode aware version of urllib.quote""" 68 73 return quote(value.encode('utf-8'), safe)
