From aa0161ff926b932bbc81a4bfaf1b8256bb8966a8 Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Tue, 26 Dec 2000 19:41:52 +0000 Subject: Latest round of jcrey's I18N patches. Specifically, Mark lots of strings as translatable. SnarfHTMLTemplate(), FormatUsers(), FormatEditingOption(), FormatReminder(), GetStandardReplacements(), GetAllReplacements(), InitTemplates(): Accept optional `lang' argument. --- Mailman/HTMLFormatter.py | 223 ++++++++++++++++++++++++++--------------------- 1 file changed, 123 insertions(+), 100 deletions(-) (limited to 'Mailman/HTMLFormatter.py') diff --git a/Mailman/HTMLFormatter.py b/Mailman/HTMLFormatter.py index 4f996a386..99c864ad1 100644 --- a/Mailman/HTMLFormatter.py +++ b/Mailman/HTMLFormatter.py @@ -50,23 +50,27 @@ class HTMLFormatter: Address( Container( Link(self.GetScriptURL('listinfo'), self.real_name), - ' list run by ', owners_html, + _(' list run by '), owners_html, '
', Link(self.GetScriptURL('admin'), - '%s administrative interface' % self.real_name), + _('%s administrative interface') % self.real_name), ' (requires authorization)', '

', MailmanLogo()))).Format() - def SnarfHTMLTemplate(self, file): + def SnarfHTMLTemplate(self, file, lang=None): # XXX: hack, blech, yuk + if lang is None: + lang = self.preferred_language HTMLFormatter.InitVars(self) - filename = os.path.join(self._template_dir, file) + filename = os.path.join(self._template_dir, lang, file) f = open(filename,'r') str = f.read() f.close() return str - def FormatUsers(self, digest): + def FormatUsers(self, digest, lang=None): + if lang is None: + lang = self.preferred_language conceal_sub = mm_cfg.ConcealSubscription people = [] if digest: @@ -84,7 +88,7 @@ class HTMLFormatter: people.sort() if (num_concealed > 0): plurality = (((num_concealed > 1) and "s") or "") - concealed = ("(%d private member%s not shown)" + concealed = (_("(%d private member%s not shown)") % (num_concealed, plurality)) else: concealed = "" @@ -135,30 +139,29 @@ class HTMLFormatter: def FormatDisabledNotice(self, user): if self.GetUserOption(user, mm_cfg.DisableDelivery): - text = Center(Header(3, - "Note - your list delivery is currently" - " disabled.")).Format() + text = Center(Header(3, _( + "Note - your list delivery is currently disabled."))).Format() text = text + "\n" - text = text + ("You may have set non-delivery deliberately, or" - " it may have been triggered by bounces from your" - " delivery address. In either case, to reenable " - " delivery, change the ") + text = text + _("You may have set non-delivery deliberately, or" + " it may have been triggered by bounces from your" + " delivery address. In either case, to reenable " + " delivery, change the ") text = text + Link('#disable', - "Disable mail delivery").Format() - text = text + " option. Contact " + _("Disable mail delivery")).Format() + text = text + _(" option. Contact ") text = text + Link('mailto:' + self.GetAdminEmail(), - 'your list administrator').Format() - text = text + " if you have questions." + _("your list administrator")).Format() + text = text + _(" if you have questions.") return text else: return "" def FormatUmbrellaNotice(self, user, type): if self.umbrella_list: - return ("(Note - you are subscribing to a list of mailing lists," - " so the %s notice will be sent to the admin address" - " for your membership, %s.)

" - % (type, self.GetMemberAdminEmail(user))) + return _("(Note - you are subscribing to a list of mailing lists," + " so the %s notice will be sent to the admin address" + " for your membership, %s.)

") % ( + type, self.GetMemberAdminEmail(user)) else: return "" @@ -167,46 +170,46 @@ class HTMLFormatter: msg = "" also = "" if self.subscribe_policy == 1: - msg = msg + ("You will be sent email requesting confirmation, " - "to prevent others from gratuitously subscribing " - "you. ") + msg = msg + _("You will be sent email requesting confirmation, " + "to prevent others from gratuitously subscribing " + "you. ") if self.subscribe_policy == 2: - msg = msg + ("This is a closed list, which means your " - "subscription will be held for approval. You will " - "be notified of the administrator's decision by " - "email. ") - also = "also " + msg = msg + _("This is a closed list, which means your " + "subscription will be held for approval. You will " + "be notified of the administrator's decision by " + "email. ") + also = _("also ") if self.subscribe_policy == 3: - msg = msg + ("You will be sent email requesting confirmation, " - "to prevent others from gratuitously subscribing " - "you. Once confirmation is received, your " - "request will be held for approval by the list " - "administrator. You will be notified of the " - "administrator's decision by email. ") - also = "also " + msg = msg + _("You will be sent email requesting confirmation, " + "to prevent others from gratuitously subscribing " + "you. Once confirmation is received, your " + "request will be held for approval by the list " + "administrator. You will be notified of the " + "administrator's decision by email. ") + also = _("also ") if self.private_roster == 1: - msg = msg + ("This is %sa private list, which means that " - "the members list is not available to non-" - "members. " % also) + msg = msg + _("This is %sa private list, which means that " + "the members list is not available to non-" + "members. ") % also elif self.private_roster: - msg = msg + ("This is %sa hidden list, which means that " - "the members list is available only to the " - "list administrator. " % also) + msg = msg + _("This is %sa hidden list, which means that " + "the members list is available only to the " + "list administrator. ") % also else: - msg = msg + ("This is %sa public list, which means that the " - "members list is openly available" % also) + msg = msg + _("This is %sa public list, which means that the " + "members list is openly available") % also if self.obscure_addresses: - msg = msg + (" (but we obscure the addresses so they are " - "not easily recognizable by spammers). ") + msg = msg + _(" (but we obscure the addresses so they are " + "not easily recognizable by spammers). ") else: msg = msg + ". " if self.umbrella_list: - msg = msg + ("

(Note that this is an umbrella list, intended to" - " have only other mailing lists as members. Among" - " other things, this means that your confirmation" - " request will be sent to the '%s' account for" - " your address.)" % self.umbrella_member_suffix) + msg = msg + _("

(Note that this is an umbrella list, intended to" + " have only other mailing lists as members. Among" + " other things, this means that your confirmation" + " request will be sent to the '%s' account for" + " your address.)") % self.umbrella_member_suffix return msg @@ -230,73 +233,74 @@ class HTMLFormatter: checked = ' CHECKED' return '' % checked - def FormatEditingOption(self): + def FormatEditingOption(self, lang): "Present editing options, according to list privacy." - text = ('To change your subscription (set options like digest' - ' and delivery modes, get a reminder of your password,' - ' or unsubscribe from ' + text = (_('To change your subscription (set options like digest' + ' and delivery modes, get a reminder of your password,' + ' or unsubscribe from ') + self.real_name - + '), %senter your subscription email address:

') + + _('), %senter your subscription email address:') + + '

') if self.private_roster == 0: - text = text % "either " + text = text % _(" either ") else: text = text % "" text = (text + TextBox('info', size=30).Format() + " " - + SubmitButton('UserOptions', 'Edit Options').Format() + + SubmitButton('UserOptions', _('Edit Options')).Format() + "
") if self.private_roster == 0: - text = text + ("

... or select your entry from the" - " subscribers list (see above).") + text = text + _("

... or select your entry from " + " the subscribers list (see above).") return text def RestrictedListMessage(self, which, restriction): if not restriction: return "" elif restriction == 1: - return ("The %s is only available to the list members." + return (_("The %s is only available to the list members.)") % which) else: - return ("The %s is only available to the list" - " administrator." % which) + return (_("The %s is only available to the list" + " administrator.") % which) - def FormatRosterOptionForUser(self): - return self.RosterOption().Format() + def FormatRosterOptionForUser(self, lang): + return self.RosterOption(lang).Format() - def RosterOption(self): + def RosterOption(self, lang): "Provide avenue to subscribers roster, contingent to .private_roster." container = Container() if not self.private_roster: - container.AddItem("Click here for the list of " + container.AddItem(_("Click here for the list of ") + self.real_name - + " subscribers: ") + + _(" subscribers: ")) container.AddItem(SubmitButton('SubscriberRoster', - 'Visit Subscriber list')) + _("Visit Subscriber list"))) else: if self.private_roster == 1: - only = 'members' - whom = 'Address:' + only = _('members') + whom = _('Address:') else: - only = 'the list administrator' - whom = 'Admin address:' + only = _('the list administrator') + whom = _('Admin address:') # Solicit the user and password. - container.AddItem(self.RestrictedListMessage('subscribers list', + container.AddItem(self.RestrictedListMessage(_('subscribers list'), self.private_roster) - + "

Enter your " + + _("

Enter your ") + string.lower(whom[:-1]) - + " and password to visit" - " the subscribers list:

" + + _(" and password to visit" + " the subscribers list:

") + whom + " ") container.AddItem(self.FormatBox('roster-email')) - container.AddItem(" Password: " + container.AddItem(_("Password: ") + self.FormatSecureBox('roster-pw') + "  ") container.AddItem(SubmitButton('SubscriberRoster', - 'Visit Subscriber List')) + _('Visit Subscriber List'))) container.AddItem("
") return container @@ -323,13 +327,16 @@ class HTMLFormatter: def FormatButton(self, name, text='Submit'): return '' % (name, text) - def FormatReminder(self): + def FormatReminder(self, lang): if self.send_reminders: - return 'Once a month, your password will be emailed to you as a reminder.' + return _('Once a month, your password will be emailed to you as' + ' a reminder.') return '' - def ParseTags(self, template, replacements): - text = self.SnarfHTMLTemplate(template) + def ParseTags(self, template, replacements, lang=None): + if lang is None: + lang = self.preferred_language + text = self.SnarfHTMLTemplate(template, lang) parts = regsub.splitx(text, ']*>') i = 1 while i < len(parts): @@ -343,9 +350,15 @@ class HTMLFormatter: # This needs to wait until after the list is inited, so let's build it # when it's needed only. - def GetStandardReplacements(self): + def GetStandardReplacements(self, lang=None): + if lang is None: + lang = self.preferred_language dmember_len = len(self.GetDigestMembers()) member_len = len(self.GetMembers()) + values = self.GetAvailableLanguages() + legend = map(_, map(Utils.GetLanguageDescr, values)) + selected = values.index(self.preferred_language) + return { '' : self.GetMailmanFooter(), '' : self.real_name, @@ -358,7 +371,7 @@ class HTMLFormatter: '' : '', '' : self.FormatSubscriptionMsg(), '' : \ - self.RestrictedListMessage('current archive', + self.RestrictedListMessage(_('current archive'), self.archive_private), '' : `member_len`, '' : `dmember_len`, @@ -366,30 +379,40 @@ class HTMLFormatter: '' : '%s' % self.GetListEmail(), '' : '%s' % self.GetRequestEmail(), '' : self.GetAdminEmail(), - '' : self.FormatReminder(), + '' : self.FormatReminder(self.preferred_language), '' : self.host_name, + '' : SelectOptions('language', values, legend, + selected).Format(), } - def GetAllReplacements(self): + def GetAllReplacements(self, lang=None): """ returns standard replaces plus formatted user lists in a dict just like GetStandardReplacements. """ - d = self.GetStandardReplacements() - d.update({"": self.FormatUsers(0), - "": self.FormatUsers(1)}) + if lang is None: + lang = self.preferred_language + d = self.GetStandardReplacements(lang) + d.update({"": self.FormatUsers(0, lang), + "": self.FormatUsers(1, lang)}) return d - def InitTemplates(self): + def InitTemplates(self, langs=None): def ExtensionFilter(item): return item[-5:] == '.html' - files = filter(ExtensionFilter, os.listdir(mm_cfg.TEMPLATE_DIR)) - Utils.MakeDirTree(self._template_dir) - for filename in files: - file1 = open(os.path.join(mm_cfg.TEMPLATE_DIR, filename), 'r') - text = file1.read() - file1.close() - file2 = open(os.path.join(self._template_dir, filename), 'w+') - file2.write(text) - file2.close() + if not langs: + langs = [mm_cfg.DEFAULT_SERVER_LANGUAGE] + + for L in langs: + files = filter(ExtensionFilter, + os.listdir(os.path.join(mm_cfg.TEMPLATE_DIR, L))) + Utils.MakeDirTree(os.path.join(self._template_dir, L)) + + for filename in files: + file1 = open(os.path.join(mm_cfg.TEMPLATE_DIR, L, filename)) + text = file1.read() + file1.close() + file2 = open(os.path.join(self._template_dir, L, filename), 'w+') + file2.write(text) + file2.close() -- cgit v1.2.3-70-g09d2