Skip to content

Commit

Permalink
Merge pull request #46 from christianwgd/master
Browse files Browse the repository at this point in the history
Localization of datetime formats in email list
  • Loading branch information
tonioo committed Oct 11, 2016
2 parents c26339e + 62c15b2 commit bbc87f1
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 75 deletions.
37 changes: 30 additions & 7 deletions modoboa_webmail/lib/imapheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,38 @@
import email

import chardet
from django.conf import settings

from django.utils import timezone
from django.utils.formats import date_format

from modoboa.lib.email_utils import EmailAddress
from modoboa.lib.signals import get_request


__all__ = [
'parse_from', 'parse_to', 'parse_message_id', 'parse_date',
'parse_reply_to', 'parse_cc', 'parse_subject'
]

# date and time formats for email list
# according to https://en.wikipedia.org/wiki/Date_format_by_country
# and https://en.wikipedia.org/wiki/Date_and_time_representation_by_country
DATETIME_FORMATS = {
"cs": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
"de": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
"en": {'SHORT': 'l, P', 'LONG': 'N j, Y P'},
"es": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
"fr": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
"it": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
"ja_JP": {'SHORT': 'l, P', 'LONG': 'N j, Y P'},
"nl": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
"pt_PT": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
"pt_BR": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
"ru": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
"sv": {'SHORT': 'l, H:i', 'LONG': 'd. N Y H:i'},
}


def to_unicode(value):
"""Try to convert a string to unicode.
Expand Down Expand Up @@ -83,18 +104,20 @@ def parse_reply_to(value, **kwargs):
"""
return parse_address_list(value, **kwargs)


def parse_date(value, **kwargs):
"""Parse a Date: header."""
tmp = email.utils.parsedate_tz(value)
if not tmp:
return value
tz = timezone.get_current_timezone()
ndate = tz.localize(
datetime.datetime.fromtimestamp(email.utils.mktime_tz(tmp)))
if timezone.now() - ndate > datetime.timedelta(7):
return date_format(ndate, "DATETIME_FORMAT")
return ndate.strftime("%a %H:%M")
ndate = datetime.datetime.fromtimestamp(email.utils.mktime_tz(tmp))
if ndate.tzinfo is not None:
tz = timezone.get_current_timezone()
ndate = tz.localize(datetime.datetime.fromtimestamp(ndate))
current_language = get_request().user.language
if datetime.datetime.now() - ndate > datetime.timedelta(7):
return date_format(ndate, DATETIME_FORMATS[current_language]['LONG'])
return date_format(ndate, DATETIME_FORMATS[current_language]['SHORT'])



def parse_message_id(value, **kwargs):
Expand Down
10 changes: 4 additions & 6 deletions modoboa_webmail/locale/cs_CZ/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Modoboa\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-05 15:04+0200\n"
"POT-Creation-Date: 2016-10-05 18:15+0200\n"
"PO-Revision-Date: 2015-01-06 10:05+0000\n"
"Last-Translator: Miroslav Abrahám <miris@kunago.com>\n"
"Language-Team: Czech (Czech Republic) (http://www.transifex.com/projects/p/"
Expand Down Expand Up @@ -196,15 +196,15 @@ msgstr "Odpověď serveru"
msgid "Unknown action"
msgstr "Neznámá akce"

#: forms.py:89 templates/modoboa_webmail/compose.html.py:10
#: forms.py:89 templates/modoboa_webmail/compose.html:10
msgid "To"
msgstr "Komu"

#: forms.py:91 templates/modoboa_webmail/compose.html.py:25
#: forms.py:91 templates/modoboa_webmail/compose.html:25
msgid "Cc"
msgstr "Kopie"

#: forms.py:93 templates/modoboa_webmail/compose.html.py:30
#: forms.py:93 templates/modoboa_webmail/compose.html:30
msgid "Cci"
msgstr "BCC"

Expand Down Expand Up @@ -246,8 +246,6 @@ msgid "Inbox"
msgstr ""

#: lib/imaputils.py:546
#, fuzzy
#| msgid "Drafts folder"
msgid "Drafts"
msgstr "Složka konceptů"

Expand Down
20 changes: 9 additions & 11 deletions modoboa_webmail/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Modoboa\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-05 15:04+0200\n"
"POT-Creation-Date: 2016-10-05 18:15+0200\n"
"PO-Revision-Date: 2015-07-11 11:51+0000\n"
"Last-Translator: controlc.de\n"
"Language-Team: German (http://www.transifex.com/tonio/modoboa/language/de/)\n"
Expand Down Expand Up @@ -198,15 +198,15 @@ msgstr "Server-Antwort"
msgid "Unknown action"
msgstr "Unbekannte Aktion"

#: forms.py:89 templates/modoboa_webmail/compose.html.py:10
#: forms.py:89 templates/modoboa_webmail/compose.html:10
msgid "To"
msgstr "An"

#: forms.py:91 templates/modoboa_webmail/compose.html.py:25
#: forms.py:91 templates/modoboa_webmail/compose.html:25
msgid "Cc"
msgstr "Cc"

#: forms.py:93 templates/modoboa_webmail/compose.html.py:30
#: forms.py:93 templates/modoboa_webmail/compose.html:30
msgid "Cci"
msgstr "Bcc"

Expand Down Expand Up @@ -245,25 +245,23 @@ msgstr "Verbindung zu IMAP-Server fehlgeschlagen: %s"

#: lib/imaputils.py:544
msgid "Inbox"
msgstr ""
msgstr "Eingang"

#: lib/imaputils.py:546
#, fuzzy
#| msgid "Drafts folder"
msgid "Drafts"
msgstr "Entwürfe"

#: lib/imaputils.py:547
msgid "Junk"
msgstr ""
msgstr "Werbung"

#: lib/imaputils.py:549
msgid "Sent"
msgstr ""
msgstr "Gesendet"

#: lib/imaputils.py:551
msgid "Trash"
msgstr ""
msgstr "Papierkorb"

#: modo_extension.py:16
msgid "Simple IMAP webmail"
Expand All @@ -279,7 +277,7 @@ msgstr "Hochladen…"

#: templates/modoboa_webmail/compose.html:12
msgid "This field is required"
msgstr ""
msgstr "Pflichtfeld"

#: templates/modoboa_webmail/compose_menubar.html:9
#: templates/modoboa_webmail/headers.html:4 views.py:284
Expand Down
8 changes: 4 additions & 4 deletions modoboa_webmail/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-05 15:04+0200\n"
"POT-Creation-Date: 2016-10-05 18:15+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -193,15 +193,15 @@ msgstr ""
msgid "Unknown action"
msgstr ""

#: forms.py:89 templates/modoboa_webmail/compose.html.py:10
#: forms.py:89 templates/modoboa_webmail/compose.html:10
msgid "To"
msgstr ""

#: forms.py:91 templates/modoboa_webmail/compose.html.py:25
#: forms.py:91 templates/modoboa_webmail/compose.html:25
msgid "Cc"
msgstr ""

#: forms.py:93 templates/modoboa_webmail/compose.html.py:30
#: forms.py:93 templates/modoboa_webmail/compose.html:30
msgid "Cci"
msgstr ""

Expand Down
10 changes: 4 additions & 6 deletions modoboa_webmail/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Modoboa\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-05 15:04+0200\n"
"POT-Creation-Date: 2016-10-05 18:15+0200\n"
"PO-Revision-Date: 2013-10-01 09:56+0000\n"
"Last-Translator: Pedro Gracia <lasarux@neuroomante.com>\n"
"Language-Team: Spanish (http://www.transifex.com/projects/p/modoboa/language/"
Expand Down Expand Up @@ -197,15 +197,15 @@ msgstr "Respuesta del servidor"
msgid "Unknown action"
msgstr "Acción desconocida"

#: forms.py:89 templates/modoboa_webmail/compose.html.py:10
#: forms.py:89 templates/modoboa_webmail/compose.html:10
msgid "To"
msgstr "A"

#: forms.py:91 templates/modoboa_webmail/compose.html.py:25
#: forms.py:91 templates/modoboa_webmail/compose.html:25
msgid "Cc"
msgstr "Cc"

#: forms.py:93 templates/modoboa_webmail/compose.html.py:30
#: forms.py:93 templates/modoboa_webmail/compose.html:30
msgid "Cci"
msgstr "Cco"

Expand Down Expand Up @@ -247,8 +247,6 @@ msgid "Inbox"
msgstr ""

#: lib/imaputils.py:546
#, fuzzy
#| msgid "Drafts folder"
msgid "Drafts"
msgstr "Carpeta de borradores"

Expand Down
9 changes: 4 additions & 5 deletions modoboa_webmail/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Modoboa\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-05 15:04+0200\n"
"POT-Creation-Date: 2016-10-05 18:15+0200\n"
"PO-Revision-Date: 2015-06-04 19:19+0000\n"
"Last-Translator: Antoine Nguyen <tonio@ngyn.org>\n"
"Language-Team: French (http://www.transifex.com/tonio/modoboa/language/fr/)\n"
Expand Down Expand Up @@ -193,15 +193,15 @@ msgstr "Réponse du serveur"
msgid "Unknown action"
msgstr "Action inconnue"

#: forms.py:89 templates/modoboa_webmail/compose.html.py:10
#: forms.py:89 templates/modoboa_webmail/compose.html:10
msgid "To"
msgstr "A"

#: forms.py:91 templates/modoboa_webmail/compose.html.py:25
#: forms.py:91 templates/modoboa_webmail/compose.html:25
msgid "Cc"
msgstr "Cc"

#: forms.py:93 templates/modoboa_webmail/compose.html.py:30
#: forms.py:93 templates/modoboa_webmail/compose.html:30
msgid "Cci"
msgstr "Cci"

Expand Down Expand Up @@ -243,7 +243,6 @@ msgid "Inbox"
msgstr "Boîte de réception"

#: lib/imaputils.py:546
#| msgid "Drafts folder"
msgid "Drafts"
msgstr "Brouillons"

Expand Down
10 changes: 4 additions & 6 deletions modoboa_webmail/locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Modoboa\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-05 15:04+0200\n"
"POT-Creation-Date: 2016-10-05 18:15+0200\n"
"PO-Revision-Date: 2015-10-11 11:49+0000\n"
"Last-Translator: Rocco <mors10@hotmail.com>\n"
"Language-Team: Italian (http://www.transifex.com/tonio/modoboa/language/"
Expand Down Expand Up @@ -198,15 +198,15 @@ msgstr "Risposta del server"
msgid "Unknown action"
msgstr "Azione sconosciuta"

#: forms.py:89 templates/modoboa_webmail/compose.html.py:10
#: forms.py:89 templates/modoboa_webmail/compose.html:10
msgid "To"
msgstr "A"

#: forms.py:91 templates/modoboa_webmail/compose.html.py:25
#: forms.py:91 templates/modoboa_webmail/compose.html:25
msgid "Cc"
msgstr "Cc"

#: forms.py:93 templates/modoboa_webmail/compose.html.py:30
#: forms.py:93 templates/modoboa_webmail/compose.html:30
msgid "Cci"
msgstr "Cci"

Expand Down Expand Up @@ -248,8 +248,6 @@ msgid "Inbox"
msgstr ""

#: lib/imaputils.py:546
#, fuzzy
#| msgid "Drafts folder"
msgid "Drafts"
msgstr "Bozze"

Expand Down
10 changes: 4 additions & 6 deletions modoboa_webmail/locale/nl_NL/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Modoboa\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-05 15:04+0200\n"
"POT-Creation-Date: 2016-10-05 18:15+0200\n"
"PO-Revision-Date: 2014-12-31 11:37+0000\n"
"Last-Translator: TuxBrother <vrijwilligerswerk@wij.rs>\n"
"Language-Team: Dutch (Netherlands) (http://www.transifex.com/projects/p/"
Expand Down Expand Up @@ -196,15 +196,15 @@ msgstr "Antwoord van server"
msgid "Unknown action"
msgstr "Onbekende actie"

#: forms.py:89 templates/modoboa_webmail/compose.html.py:10
#: forms.py:89 templates/modoboa_webmail/compose.html:10
msgid "To"
msgstr "Naar"

#: forms.py:91 templates/modoboa_webmail/compose.html.py:25
#: forms.py:91 templates/modoboa_webmail/compose.html:25
msgid "Cc"
msgstr "CC"

#: forms.py:93 templates/modoboa_webmail/compose.html.py:30
#: forms.py:93 templates/modoboa_webmail/compose.html:30
msgid "Cci"
msgstr "BCc"

Expand Down Expand Up @@ -246,8 +246,6 @@ msgid "Inbox"
msgstr ""

#: lib/imaputils.py:546
#, fuzzy
#| msgid "Drafts folder"
msgid "Drafts"
msgstr "Concepten"

Expand Down
10 changes: 4 additions & 6 deletions modoboa_webmail/locale/pt_BR/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Modoboa\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-05 15:04+0200\n"
"POT-Creation-Date: 2016-10-05 18:15+0200\n"
"PO-Revision-Date: 2015-08-10 20:41+0000\n"
"Last-Translator: Rafael Barretto Alves <ch3yd@hotmail.com>\n"
"Language-Team: Portuguese (Brazil) (http://www.transifex.com/tonio/modoboa/"
Expand Down Expand Up @@ -197,15 +197,15 @@ msgstr "Resposta do servidor"
msgid "Unknown action"
msgstr "Ação desconhecida"

#: forms.py:89 templates/modoboa_webmail/compose.html.py:10
#: forms.py:89 templates/modoboa_webmail/compose.html:10
msgid "To"
msgstr "Para"

#: forms.py:91 templates/modoboa_webmail/compose.html.py:25
#: forms.py:91 templates/modoboa_webmail/compose.html:25
msgid "Cc"
msgstr "Cc"

#: forms.py:93 templates/modoboa_webmail/compose.html.py:30
#: forms.py:93 templates/modoboa_webmail/compose.html:30
msgid "Cci"
msgstr "Cci"

Expand Down Expand Up @@ -247,8 +247,6 @@ msgid "Inbox"
msgstr ""

#: lib/imaputils.py:546
#, fuzzy
#| msgid "Drafts folder"
msgid "Drafts"
msgstr "Pasta para Rascunhos"

Expand Down

0 comments on commit bbc87f1

Please sign in to comment.