We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Languages in languages drop down menu are messed
Hi,

the languages in the languages drop down menu are in a pretty mess now. It seems that they are not sorted anymore now, neither by language name nor by locale.

Regards,
Michael

--- 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/core/views/base.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 from django.urls import reverse
10 from django.utils.decorators import method_decorator
11 from django.utils.functional import cached_property
12 from django.utils.translation import get_language
13 from django.views.decorators.cache import never_cache
14 from django.views.generic import DetailView
15 
16 from pootle.core.delegate import site_languages
17 from pootle.core.url_helpers import get_path_parts
18 from pootle.i18n.gettext import ugettext as _
19 from pootle_app.models.permissions import check_permission
20 from pootle_misc.util import ajax_required
21 
22 from .decorators import requires_permission, set_permissions
23 from .mixins import GatherContextMixin, PootleJSONMixin
24 
25 
26 class PootleDetailView(GatherContextMixin, DetailView):
27     translate_url_path = ""
28     browse_url_path = ""
29     resource_path = ""
30     view_name = ""
31     sw_version = 0
32     ns = "pootle.core"
33 
34     @property
35     def browse_url(self):
36         return reverse(
37             self.browse_url_path,
38             kwargs=self.url_kwargs)
39 
40     @property
41     def cache_key(self):
42         return (
43             "%s.%s.%s.%s"
44             % (self.page_name,
45                self.view_name,
46                self.object.data_tool.cache_key,
47                self.request_lang))
48 
49     @property
50     def request_lang(self):
51         return get_language()
52 
53     @cached_property
54     def has_admin_access(self):
55         return check_permission('administrate', self.request)
56 
57     @property
58     def language(self):
59         if self.tp:
60             return self.tp.language
61 
62     @property
63     def permission_context(self):
64         return self.get_object()
65 
66     @property
67     def pootle_path(self):
68         return self.object.pootle_path
69 
70     @property
71     def project(self):
72         if self.tp:
73             return self.tp.project
74 
75     @property
76     def tp(self):
77         return None
78 
79     @property
80     def translate_url(self):
81         return reverse(
82             self.translate_url_path,
83             kwargs=self.url_kwargs)
84 
85     @set_permissions
86     @requires_permission("view")
87     def dispatch(self, request, *args, **kwargs):
88         # get funky with the request 8/
89         return super(PootleDetailView, self).dispatch(request, *args, **kwargs)
90 
91     @property
92     def languages(self):
93         languages = site_languages.get()
94         return (
95             languages.all_languages
96             if self.has_admin_access
97             else languages.languages)
98 
99     def get_context_data(self, *args, **kwargs):
100         return {
101             'object': self.object,
102             'pootle_path': self.pootle_path,
103             'project': self.project,
104             'language': self.language,
105             "all_languages": self.languages,
106             'translation_project': self.tp,
107             'has_admin_access': self.has_admin_access,
108             'resource_path': self.resource_path,
109             'resource_path_parts': get_path_parts(self.resource_path),
110             'translate_url': self.translate_url,
111             'browse_url': self.browse_url,
112             'paths_placeholder': _("Entire Project"),
113             'unit_api_root': "/xhr/units/"}
114 
115 
116 class PootleJSON(PootleJSONMixin, PootleDetailView):
117 
118     @never_cache
119     @method_decorator(ajax_required)
120     @set_permissions
121     @requires_permission("view")
122     def dispatch(self, request, *args, **kwargs):
123         return super(PootleJSON, self).dispatch(request, *args, **kwargs)
124 
125 
126 class PootleAdminView(DetailView):
127 
128     @set_permissions
129     @requires_permission("administrate")
130     def dispatch(self, request, *args, **kwargs):
131         return super(PootleAdminView, self).dispatch(request, *args, **kwargs)
132 
133     @property
134     def permission_context(self):
135         return self.get_object().directory
136 
137     def post(self, *args, **kwargs):
138         return self.get(*args, **kwargs)
139
```
--- 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/core/views/base.py b/pootle/core/views/base.py
--- a/pootle/core/views/base.py
+++ b/pootle/core/views/base.py
@@ -6,6 +6,8 @@
 # or later license. See the LICENSE file for a copy of the license and the
 # AUTHORS file for copyright and authorship information.
 
+from collections import OrderedDict
+
 from django.urls import reverse
 from django.utils.decorators import method_decorator
 from django.utils.functional import cached_property
@@ -91,10 +93,18 @@
     @property
     def languages(self):
         languages = site_languages.get()
-        return (
+        languages = (
             languages.all_languages
             if self.has_admin_access
             else languages.languages)
+        lang_map = {
+            v: k
+            for k, v
+            in languages.items()}
+        return OrderedDict(
+            (lang_map[v], v)
+            for v
+            in sorted(languages.values()))
 
     def get_context_data(self, *args, **kwargs):
         return {

{"golden_diff": "diff --git a/pootle/core/views/base.py b/pootle/core/views/base.py\n--- a/pootle/core/views/base.py\n+++ b/pootle/core/views/base.py\n@@ -6,6 +6,8 @@\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 \n+from collections import OrderedDict\n+\n from django.urls import reverse\n from django.utils.decorators import method_decorator\n from django.utils.functional import cached_property\n@@ -91,10 +93,18 @@\n     @property\n     def languages(self):\n         languages = site_languages.get()\n-        return (\n+        languages = (\n             languages.all_languages\n             if self.has_admin_access\n             else languages.languages)\n+        lang_map = {\n+            v: k\n+            for k, v\n+            in languages.items()}\n+        return OrderedDict(\n+            (lang_map[v], v)\n+            for v\n+            in sorted(languages.values()))\n \n     def get_context_data(self, *args, **kwargs):\n         return {\n", "issue": "Languages in languages drop down menu are messed\nHi,\r\n\r\nthe languages in the languages drop down menu are in a pretty mess now. It seems that they are not sorted anymore now, neither by language name nor by locale.\r\n\r\nRegards,\r\nMichael\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\nfrom django.urls import reverse\nfrom django.utils.decorators import method_decorator\nfrom django.utils.functional import cached_property\nfrom django.utils.translation import get_language\nfrom django.views.decorators.cache import never_cache\nfrom django.views.generic import DetailView\n\nfrom pootle.core.delegate import site_languages\nfrom pootle.core.url_helpers import get_path_parts\nfrom pootle.i18n.gettext import ugettext as _\nfrom pootle_app.models.permissions import check_permission\nfrom pootle_misc.util import ajax_required\n\nfrom .decorators import requires_permission, set_permissions\nfrom .mixins import GatherContextMixin, PootleJSONMixin\n\n\nclass PootleDetailView(GatherContextMixin, DetailView):\n    translate_url_path = \"\"\n    browse_url_path = \"\"\n    resource_path = \"\"\n    view_name = \"\"\n    sw_version = 0\n    ns = \"pootle.core\"\n\n    @property\n    def browse_url(self):\n        return reverse(\n            self.browse_url_path,\n            kwargs=self.url_kwargs)\n\n    @property\n    def cache_key(self):\n        return (\n            \"%s.%s.%s.%s\"\n            % (self.page_name,\n               self.view_name,\n               self.object.data_tool.cache_key,\n               self.request_lang))\n\n    @property\n    def request_lang(self):\n        return get_language()\n\n    @cached_property\n    def has_admin_access(self):\n        return check_permission('administrate', self.request)\n\n    @property\n    def language(self):\n        if self.tp:\n            return self.tp.language\n\n    @property\n    def permission_context(self):\n        return self.get_object()\n\n    @property\n    def pootle_path(self):\n        return self.object.pootle_path\n\n    @property\n    def project(self):\n        if self.tp:\n            return self.tp.project\n\n    @property\n    def tp(self):\n        return None\n\n    @property\n    def translate_url(self):\n        return reverse(\n            self.translate_url_path,\n            kwargs=self.url_kwargs)\n\n    @set_permissions\n    @requires_permission(\"view\")\n    def dispatch(self, request, *args, **kwargs):\n        # get funky with the request 8/\n        return super(PootleDetailView, self).dispatch(request, *args, **kwargs)\n\n    @property\n    def languages(self):\n        languages = site_languages.get()\n        return (\n            languages.all_languages\n            if self.has_admin_access\n            else languages.languages)\n\n    def get_context_data(self, *args, **kwargs):\n        return {\n            'object': self.object,\n            'pootle_path': self.pootle_path,\n            'project': self.project,\n            'language': self.language,\n            \"all_languages\": self.languages,\n            'translation_project': self.tp,\n            'has_admin_access': self.has_admin_access,\n            'resource_path': self.resource_path,\n            'resource_path_parts': get_path_parts(self.resource_path),\n            'translate_url': self.translate_url,\n            'browse_url': self.browse_url,\n            'paths_placeholder': _(\"Entire Project\"),\n            'unit_api_root': \"/xhr/units/\"}\n\n\nclass PootleJSON(PootleJSONMixin, PootleDetailView):\n\n    @never_cache\n    @method_decorator(ajax_required)\n    @set_permissions\n    @requires_permission(\"view\")\n    def dispatch(self, request, *args, **kwargs):\n        return super(PootleJSON, self).dispatch(request, *args, **kwargs)\n\n\nclass PootleAdminView(DetailView):\n\n    @set_permissions\n    @requires_permission(\"administrate\")\n    def dispatch(self, request, *args, **kwargs):\n        return super(PootleAdminView, self).dispatch(request, *args, **kwargs)\n\n    @property\n    def permission_context(self):\n        return self.get_object().directory\n\n    def post(self, *args, **kwargs):\n        return self.get(*args, **kwargs)\n", "path": "pootle/core/views/base.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\nfrom collections import OrderedDict\n\nfrom django.urls import reverse\nfrom django.utils.decorators import method_decorator\nfrom django.utils.functional import cached_property\nfrom django.utils.translation import get_language\nfrom django.views.decorators.cache import never_cache\nfrom django.views.generic import DetailView\n\nfrom pootle.core.delegate import site_languages\nfrom pootle.core.url_helpers import get_path_parts\nfrom pootle.i18n.gettext import ugettext as _\nfrom pootle_app.models.permissions import check_permission\nfrom pootle_misc.util import ajax_required\n\nfrom .decorators import requires_permission, set_permissions\nfrom .mixins import GatherContextMixin, PootleJSONMixin\n\n\nclass PootleDetailView(GatherContextMixin, DetailView):\n    translate_url_path = \"\"\n    browse_url_path = \"\"\n    resource_path = \"\"\n    view_name = \"\"\n    sw_version = 0\n    ns = \"pootle.core\"\n\n    @property\n    def browse_url(self):\n        return reverse(\n            self.browse_url_path,\n            kwargs=self.url_kwargs)\n\n    @property\n    def cache_key(self):\n        return (\n            \"%s.%s.%s.%s\"\n            % (self.page_name,\n               self.view_name,\n               self.object.data_tool.cache_key,\n               self.request_lang))\n\n    @property\n    def request_lang(self):\n        return get_language()\n\n    @cached_property\n    def has_admin_access(self):\n        return check_permission('administrate', self.request)\n\n    @property\n    def language(self):\n        if self.tp:\n            return self.tp.language\n\n    @property\n    def permission_context(self):\n        return self.get_object()\n\n    @property\n    def pootle_path(self):\n        return self.object.pootle_path\n\n    @property\n    def project(self):\n        if self.tp:\n            return self.tp.project\n\n    @property\n    def tp(self):\n        return None\n\n    @property\n    def translate_url(self):\n        return reverse(\n            self.translate_url_path,\n            kwargs=self.url_kwargs)\n\n    @set_permissions\n    @requires_permission(\"view\")\n    def dispatch(self, request, *args, **kwargs):\n        # get funky with the request 8/\n        return super(PootleDetailView, self).dispatch(request, *args, **kwargs)\n\n    @property\n    def languages(self):\n        languages = site_languages.get()\n        languages = (\n            languages.all_languages\n            if self.has_admin_access\n            else languages.languages)\n        lang_map = {\n            v: k\n            for k, v\n            in languages.items()}\n        return OrderedDict(\n            (lang_map[v], v)\n            for v\n            in sorted(languages.values()))\n\n    def get_context_data(self, *args, **kwargs):\n        return {\n            'object': self.object,\n            'pootle_path': self.pootle_path,\n            'project': self.project,\n            'language': self.language,\n            \"all_languages\": self.languages,\n            'translation_project': self.tp,\n            'has_admin_access': self.has_admin_access,\n            'resource_path': self.resource_path,\n            'resource_path_parts': get_path_parts(self.resource_path),\n            'translate_url': self.translate_url,\n            'browse_url': self.browse_url,\n            'paths_placeholder': _(\"Entire Project\"),\n            'unit_api_root': \"/xhr/units/\"}\n\n\nclass PootleJSON(PootleJSONMixin, PootleDetailView):\n\n    @never_cache\n    @method_decorator(ajax_required)\n    @set_permissions\n    @requires_permission(\"view\")\n    def dispatch(self, request, *args, **kwargs):\n        return super(PootleJSON, self).dispatch(request, *args, **kwargs)\n\n\nclass PootleAdminView(DetailView):\n\n    @set_permissions\n    @requires_permission(\"administrate\")\n    def dispatch(self, request, *args, **kwargs):\n        return super(PootleAdminView, self).dispatch(request, *args, **kwargs)\n\n    @property\n    def permission_context(self):\n        return self.get_object().directory\n\n    def post(self, *args, **kwargs):\n        return self.get(*args, **kwargs)\n", "path": "pootle/core/views/base.py"}]}