We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Dates not getting localised in browse tables
seems like the dates are not getting localised as they should

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pootle/apps/pootle_app/panels.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) Pootle contributors.
4 #
5 # This file is a part of the Pootle project. It is distributed under the GPL3
6 # or later license. See the LICENSE file for a copy of the license and the
7 # AUTHORS file for copyright and authorship information.
8 
9 import re
10 
11 from django.utils.safestring import mark_safe
12 
13 from pootle.core.browser import get_table_headings
14 from pootle.core.decorators import persistent_property
15 from pootle.core.views.panels import TablePanel
16 
17 from pootle.i18n.dates import timesince
18 
19 
20 class ChildrenPanel(TablePanel):
21     panel_name = "children"
22     _table_fields = (
23         'name', 'progress', 'activity',
24         'total', 'need-translation',
25         'suggestions', 'critical')
26 
27     @property
28     def table_fields(self):
29         fields = (
30             ("name", "total")
31             if self.view.is_templates_context
32             else self._table_fields)
33         if self.view.has_admin_access:
34             fields += ('last-updated', )
35         return fields
36 
37     @property
38     def children(self):
39         return self.view.object_children
40 
41     @property
42     def table(self):
43         if self.view.object_children:
44             return {
45                 'id': self.view.view_name,
46                 'fields': self.table_fields,
47                 'headings': get_table_headings(self.table_fields),
48                 'rows': self.view.object_children}
49 
50     @persistent_property
51     def _content(self):
52         return self.render()
53 
54     @property
55     def child_update_times(self):
56         _times = {}
57         for child in self.children:
58             if not child.get("stats"):
59                 continue
60             last_created_unit = (
61                 timesince(child["stats"]["last_created_unit"]["creation_time"])
62                 if child["stats"].get("last_created_unit")
63                 else None)
64             last_submission = (
65                 timesince(child["stats"]["last_submission"]["mtime"])
66                 if child["stats"].get("last_submission")
67                 else None)
68             _times[child["code"]] = (last_submission, last_created_unit)
69         return _times
70 
71     @property
72     def content(self):
73         return self.update_times(self._content)
74 
75     def get_context_data(self):
76         return dict(
77             table=self.table,
78             can_translate=self.view.can_translate)
79 
80     def update_times(self, content):
81         times = {}
82         update_times = self.child_update_times.items()
83         for name, (last_submission, last_created_unit) in update_times:
84             if last_submission:
85                 times[
86                     "_XXX_LAST_SUBMISSION_%s_LAST_SUBMISSION_XXX_"
87                     % name] = last_submission
88             if last_created_unit:
89                 times[
90                     "_XXX_LAST_CREATED_%s_LAST_CREATED_XXX_"
91                     % name] = last_created_unit
92         if times:
93             regex = re.compile("(%s)" % "|".join(map(re.escape, times.keys())))
94             return mark_safe(
95                 regex.sub(
96                     lambda match: times[match.string[match.start():match.end()]],
97                     content))
98         return content
99
```

Path: `pootle/i18n/dates.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) Pootle contributors.
4 #
5 # This file is a part of the Pootle project. It is distributed under the GPL3
6 # or later license. See the LICENSE file for a copy of the license and the
7 # AUTHORS file for copyright and authorship information.
8 
9 import locale as system_locale
10 import os
11 from datetime import datetime
12 
13 from babel.dates import format_timedelta
14 
15 from django.utils import translation
16 
17 
18 class LocalDate(object):
19 
20     def __init__(self):
21         if not self.locale_code and not os.name == "nt":
22             self.set_locale()
23 
24     @property
25     def default_locale(self):
26         return translation.to_locale(translation.get_language())
27 
28     def set_locale(self):
29         system_locale.setlocale(
30             system_locale.LC_ALL,
31             (self.default_locale, 'UTF-8'))
32 
33     @property
34     def locale_code(self):
35         return system_locale.getlocale()[0]
36 
37     def format_timesince(self, timestamp, locale=None):
38         return format_timedelta(
39             datetime.now()
40             - datetime.fromtimestamp(
41                 timestamp),
42             locale=(
43                 locale
44                 or self.locale_code
45                 or self.default_locale))
46 
47 
48 localdate = LocalDate()
49 
50 
51 def timesince(timestamp, locale=None):
52     return localdate.format_timesince(timestamp, locale=locale)
53
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pootle/apps/pootle_app/panels.py b/pootle/apps/pootle_app/panels.py
--- a/pootle/apps/pootle_app/panels.py
+++ b/pootle/apps/pootle_app/panels.py
@@ -58,11 +58,15 @@
             if not child.get("stats"):
                 continue
             last_created_unit = (
-                timesince(child["stats"]["last_created_unit"]["creation_time"])
+                timesince(
+                    child["stats"]["last_created_unit"]["creation_time"],
+                    locale=self.view.request_lang)
                 if child["stats"].get("last_created_unit")
                 else None)
             last_submission = (
-                timesince(child["stats"]["last_submission"]["mtime"])
+                timesince(
+                    child["stats"]["last_submission"]["mtime"],
+                    locale=self.view.request_lang)
                 if child["stats"].get("last_submission")
                 else None)
             _times[child["code"]] = (last_submission, last_created_unit)
diff --git a/pootle/i18n/dates.py b/pootle/i18n/dates.py
--- a/pootle/i18n/dates.py
+++ b/pootle/i18n/dates.py
@@ -49,4 +49,6 @@
 
 
 def timesince(timestamp, locale=None):
+    if locale:
+        locale = translation.to_locale(locale)
     return localdate.format_timesince(timestamp, locale=locale)

{"golden_diff": "diff --git a/pootle/apps/pootle_app/panels.py b/pootle/apps/pootle_app/panels.py\n--- a/pootle/apps/pootle_app/panels.py\n+++ b/pootle/apps/pootle_app/panels.py\n@@ -58,11 +58,15 @@\n             if not child.get(\"stats\"):\n                 continue\n             last_created_unit = (\n-                timesince(child[\"stats\"][\"last_created_unit\"][\"creation_time\"])\n+                timesince(\n+                    child[\"stats\"][\"last_created_unit\"][\"creation_time\"],\n+                    locale=self.view.request_lang)\n                 if child[\"stats\"].get(\"last_created_unit\")\n                 else None)\n             last_submission = (\n-                timesince(child[\"stats\"][\"last_submission\"][\"mtime\"])\n+                timesince(\n+                    child[\"stats\"][\"last_submission\"][\"mtime\"],\n+                    locale=self.view.request_lang)\n                 if child[\"stats\"].get(\"last_submission\")\n                 else None)\n             _times[child[\"code\"]] = (last_submission, last_created_unit)\ndiff --git a/pootle/i18n/dates.py b/pootle/i18n/dates.py\n--- a/pootle/i18n/dates.py\n+++ b/pootle/i18n/dates.py\n@@ -49,4 +49,6 @@\n \n \n def timesince(timestamp, locale=None):\n+    if locale:\n+        locale = translation.to_locale(locale)\n     return localdate.format_timesince(timestamp, locale=locale)\n", "issue": "Dates not getting localised in browse tables\nseems like the dates are not getting localised as they should\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nimport re\n\nfrom django.utils.safestring import mark_safe\n\nfrom pootle.core.browser import get_table_headings\nfrom pootle.core.decorators import persistent_property\nfrom pootle.core.views.panels import TablePanel\n\nfrom pootle.i18n.dates import timesince\n\n\nclass ChildrenPanel(TablePanel):\n    panel_name = \"children\"\n    _table_fields = (\n        'name', 'progress', 'activity',\n        'total', 'need-translation',\n        'suggestions', 'critical')\n\n    @property\n    def table_fields(self):\n        fields = (\n            (\"name\", \"total\")\n            if self.view.is_templates_context\n            else self._table_fields)\n        if self.view.has_admin_access:\n            fields += ('last-updated', )\n        return fields\n\n    @property\n    def children(self):\n        return self.view.object_children\n\n    @property\n    def table(self):\n        if self.view.object_children:\n            return {\n                'id': self.view.view_name,\n                'fields': self.table_fields,\n                'headings': get_table_headings(self.table_fields),\n                'rows': self.view.object_children}\n\n    @persistent_property\n    def _content(self):\n        return self.render()\n\n    @property\n    def child_update_times(self):\n        _times = {}\n        for child in self.children:\n            if not child.get(\"stats\"):\n                continue\n            last_created_unit = (\n                timesince(child[\"stats\"][\"last_created_unit\"][\"creation_time\"])\n                if child[\"stats\"].get(\"last_created_unit\")\n                else None)\n            last_submission = (\n                timesince(child[\"stats\"][\"last_submission\"][\"mtime\"])\n                if child[\"stats\"].get(\"last_submission\")\n                else None)\n            _times[child[\"code\"]] = (last_submission, last_created_unit)\n        return _times\n\n    @property\n    def content(self):\n        return self.update_times(self._content)\n\n    def get_context_data(self):\n        return dict(\n            table=self.table,\n            can_translate=self.view.can_translate)\n\n    def update_times(self, content):\n        times = {}\n        update_times = self.child_update_times.items()\n        for name, (last_submission, last_created_unit) in update_times:\n            if last_submission:\n                times[\n                    \"_XXX_LAST_SUBMISSION_%s_LAST_SUBMISSION_XXX_\"\n                    % name] = last_submission\n            if last_created_unit:\n                times[\n                    \"_XXX_LAST_CREATED_%s_LAST_CREATED_XXX_\"\n                    % name] = last_created_unit\n        if times:\n            regex = re.compile(\"(%s)\" % \"|\".join(map(re.escape, times.keys())))\n            return mark_safe(\n                regex.sub(\n                    lambda match: times[match.string[match.start():match.end()]],\n                    content))\n        return content\n", "path": "pootle/apps/pootle_app/panels.py"}, {"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nimport locale as system_locale\nimport os\nfrom datetime import datetime\n\nfrom babel.dates import format_timedelta\n\nfrom django.utils import translation\n\n\nclass LocalDate(object):\n\n    def __init__(self):\n        if not self.locale_code and not os.name == \"nt\":\n            self.set_locale()\n\n    @property\n    def default_locale(self):\n        return translation.to_locale(translation.get_language())\n\n    def set_locale(self):\n        system_locale.setlocale(\n            system_locale.LC_ALL,\n            (self.default_locale, 'UTF-8'))\n\n    @property\n    def locale_code(self):\n        return system_locale.getlocale()[0]\n\n    def format_timesince(self, timestamp, locale=None):\n        return format_timedelta(\n            datetime.now()\n            - datetime.fromtimestamp(\n                timestamp),\n            locale=(\n                locale\n                or self.locale_code\n                or self.default_locale))\n\n\nlocaldate = LocalDate()\n\n\ndef timesince(timestamp, locale=None):\n    return localdate.format_timesince(timestamp, locale=locale)\n", "path": "pootle/i18n/dates.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nimport re\n\nfrom django.utils.safestring import mark_safe\n\nfrom pootle.core.browser import get_table_headings\nfrom pootle.core.decorators import persistent_property\nfrom pootle.core.views.panels import TablePanel\n\nfrom pootle.i18n.dates import timesince\n\n\nclass ChildrenPanel(TablePanel):\n    panel_name = \"children\"\n    _table_fields = (\n        'name', 'progress', 'activity',\n        'total', 'need-translation',\n        'suggestions', 'critical')\n\n    @property\n    def table_fields(self):\n        fields = (\n            (\"name\", \"total\")\n            if self.view.is_templates_context\n            else self._table_fields)\n        if self.view.has_admin_access:\n            fields += ('last-updated', )\n        return fields\n\n    @property\n    def children(self):\n        return self.view.object_children\n\n    @property\n    def table(self):\n        if self.view.object_children:\n            return {\n                'id': self.view.view_name,\n                'fields': self.table_fields,\n                'headings': get_table_headings(self.table_fields),\n                'rows': self.view.object_children}\n\n    @persistent_property\n    def _content(self):\n        return self.render()\n\n    @property\n    def child_update_times(self):\n        _times = {}\n        for child in self.children:\n            if not child.get(\"stats\"):\n                continue\n            last_created_unit = (\n                timesince(\n                    child[\"stats\"][\"last_created_unit\"][\"creation_time\"],\n                    locale=self.view.request_lang)\n                if child[\"stats\"].get(\"last_created_unit\")\n                else None)\n            last_submission = (\n                timesince(\n                    child[\"stats\"][\"last_submission\"][\"mtime\"],\n                    locale=self.view.request_lang)\n                if child[\"stats\"].get(\"last_submission\")\n                else None)\n            _times[child[\"code\"]] = (last_submission, last_created_unit)\n        return _times\n\n    @property\n    def content(self):\n        return self.update_times(self._content)\n\n    def get_context_data(self):\n        return dict(\n            table=self.table,\n            can_translate=self.view.can_translate)\n\n    def update_times(self, content):\n        times = {}\n        update_times = self.child_update_times.items()\n        for name, (last_submission, last_created_unit) in update_times:\n            if last_submission:\n                times[\n                    \"_XXX_LAST_SUBMISSION_%s_LAST_SUBMISSION_XXX_\"\n                    % name] = last_submission\n            if last_created_unit:\n                times[\n                    \"_XXX_LAST_CREATED_%s_LAST_CREATED_XXX_\"\n                    % name] = last_created_unit\n        if times:\n            regex = re.compile(\"(%s)\" % \"|\".join(map(re.escape, times.keys())))\n            return mark_safe(\n                regex.sub(\n                    lambda match: times[match.string[match.start():match.end()]],\n                    content))\n        return content\n", "path": "pootle/apps/pootle_app/panels.py"}, {"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nimport locale as system_locale\nimport os\nfrom datetime import datetime\n\nfrom babel.dates import format_timedelta\n\nfrom django.utils import translation\n\n\nclass LocalDate(object):\n\n    def __init__(self):\n        if not self.locale_code and not os.name == \"nt\":\n            self.set_locale()\n\n    @property\n    def default_locale(self):\n        return translation.to_locale(translation.get_language())\n\n    def set_locale(self):\n        system_locale.setlocale(\n            system_locale.LC_ALL,\n            (self.default_locale, 'UTF-8'))\n\n    @property\n    def locale_code(self):\n        return system_locale.getlocale()[0]\n\n    def format_timesince(self, timestamp, locale=None):\n        return format_timedelta(\n            datetime.now()\n            - datetime.fromtimestamp(\n                timestamp),\n            locale=(\n                locale\n                or self.locale_code\n                or self.default_locale))\n\n\nlocaldate = LocalDate()\n\n\ndef timesince(timestamp, locale=None):\n    if locale:\n        locale = translation.to_locale(locale)\n    return localdate.format_timesince(timestamp, locale=locale)\n", "path": "pootle/i18n/dates.py"}]}