We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Overview dropdown is using ISO639 names and not simplified toolkit names
E.g. nso is using "Pedi; Sepedi; Nothern Sotho" instead of simply 'Northern Sotho'


--- 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_language/models.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright (C) Pootle contributors.
5 #
6 # This file is a part of the Pootle project. It is distributed under the GPL3
7 # or later license. See the LICENSE file for a copy of the license and the
8 # AUTHORS file for copyright and authorship information.
9 
10 from collections import OrderedDict
11 
12 from django.conf import settings
13 from django.core.cache import cache
14 from django.core.urlresolvers import reverse
15 from django.db import models
16 from django.db.models.signals import post_delete, post_save
17 from django.dispatch import receiver
18 from django.utils.translation import ugettext_lazy as _
19 
20 from pootle.core.mixins import TreeItem
21 from pootle.core.url_helpers import get_editor_filter
22 from pootle.i18n.gettext import tr_lang, language_dir
23 
24 
25 # FIXME: Generate key dynamically
26 CACHE_KEY = 'pootle-languages'
27 
28 
29 class LanguageManager(models.Manager):
30 
31     def get_queryset(self):
32         """Mimics `select_related(depth=1)` behavior. Pending review."""
33         return (
34             super(LanguageManager, self).get_queryset().select_related(
35                 'directory',
36             )
37         )
38 
39 
40 class LiveLanguageManager(models.Manager):
41     """Manager that only considers `live` languages.
42 
43     A live language is any language other than the special `Templates`
44     language that have any project with translatable files and is not a
45     source language.
46     """
47     def get_queryset(self):
48         return super(LiveLanguageManager, self).get_queryset().filter(
49                 ~models.Q(code='templates'),
50                 translationproject__isnull=False,
51                 project__isnull=True,
52             ).distinct()
53 
54     def cached_dict(self):
55         languages = cache.get(CACHE_KEY)
56         if not languages:
57             languages = OrderedDict(
58                 self.order_by('fullname').values_list('code', 'fullname')
59             )
60             cache.set(CACHE_KEY, languages, settings.OBJECT_CACHE_TIMEOUT)
61 
62         return languages
63 
64 
65 class Language(models.Model, TreeItem):
66 
67     code_help_text = _('ISO 639 language code for the language, possibly '
68             'followed by an underscore (_) and an ISO 3166 country code. '
69             '<a href="http://www.w3.org/International/articles/language-tags/">'
70             'More information</a>')
71     code = models.CharField(max_length=50, null=False, unique=True,
72             db_index=True, verbose_name=_("Code"), help_text=code_help_text)
73     fullname = models.CharField(max_length=255, null=False,
74             verbose_name=_("Full Name"))
75 
76     specialchars_help_text = _('Enter any special characters that users '
77             'might find difficult to type')
78     specialchars = models.CharField(max_length=255, blank=True,
79             verbose_name=_("Special Characters"),
80             help_text=specialchars_help_text)
81 
82     plurals_help_text = _('For more information, visit '
83             '<a href="http://docs.translatehouse.org/projects/'
84             'localization-guide/en/latest/l10n/pluralforms.html">'
85             'our page</a> on plural forms.')
86     nplural_choices = (
87             (0, _('Unknown')), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)
88     )
89     nplurals = models.SmallIntegerField(default=0, choices=nplural_choices,
90             verbose_name=_("Number of Plurals"), help_text=plurals_help_text)
91     pluralequation = models.CharField(max_length=255, blank=True,
92             verbose_name=_("Plural Equation"), help_text=plurals_help_text)
93 
94     directory = models.OneToOneField('pootle_app.Directory', db_index=True,
95             editable=False)
96 
97     objects = LanguageManager()
98     live = LiveLanguageManager()
99 
100     class Meta:
101         ordering = ['code']
102         db_table = 'pootle_app_language'
103 
104     ############################ Properties ###################################
105 
106     @property
107     def pootle_path(self):
108         return '/%s/' % self.code
109 
110     @property
111     def name(self):
112         """Localized fullname for the language."""
113         return tr_lang(self.fullname)
114 
115     ############################ Methods ######################################
116 
117     @property
118     def direction(self):
119         """Return the language direction."""
120         return language_dir(self.code)
121 
122     def __unicode__(self):
123         return u"%s - %s" % (self.name, self.code)
124 
125     def __init__(self, *args, **kwargs):
126         super(Language, self).__init__(*args, **kwargs)
127 
128     def __repr__(self):
129         return u'<%s: %s>' % (self.__class__.__name__, self.fullname)
130 
131     def save(self, *args, **kwargs):
132         # create corresponding directory object
133         from pootle_app.models.directory import Directory
134         self.directory = Directory.objects.root.get_or_make_subdir(self.code)
135 
136         super(Language, self).save(*args, **kwargs)
137 
138     def delete(self, *args, **kwargs):
139         directory = self.directory
140         super(Language, self).delete(*args, **kwargs)
141         directory.delete()
142 
143     def get_absolute_url(self):
144         return reverse('pootle-language-overview', args=[self.code])
145 
146     def get_translate_url(self, **kwargs):
147         return u''.join([
148             reverse('pootle-language-translate', args=[self.code]),
149             get_editor_filter(**kwargs),
150         ])
151 
152     ### TreeItem
153 
154     def get_children(self):
155         return self.translationproject_set.live()
156 
157     def get_cachekey(self):
158         return self.directory.pootle_path
159 
160     ### /TreeItem
161 
162 
163 @receiver([post_delete, post_save])
164 def invalidate_language_list_cache(sender, instance, **kwargs):
165     # XXX: maybe use custom signals or simple function calls?
166     if instance.__class__.__name__ not in ['Language', 'TranslationProject']:
167         return
168 
169     cache.delete(CACHE_KEY)
170
```

Path: `pootle/apps/pootle_misc/context_processors.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright (C) Pootle contributors.
5 #
6 # This file is a part of the Pootle project. It is distributed under the GPL3
7 # or later license. See the LICENSE file for a copy of the license and the
8 # AUTHORS file for copyright and authorship information.
9 
10 from django.conf import settings
11 
12 from pootle.__version__ import sver
13 from pootle_language.models import Language
14 from pootle_project.models import Project
15 from staticpages.models import LegalPage
16 
17 
18 def _agreement_context(request):
19     """Returns whether the agreement box should be displayed or not."""
20     request_path = request.META['PATH_INFO']
21     nocheck = filter(lambda x: request_path.startswith(x),
22                      settings.LEGALPAGE_NOCHECK_PREFIXES)
23 
24     if (request.user.is_authenticated() and not nocheck and
25         LegalPage.objects.pending_user_agreement(request.user).exists()):
26         return True
27 
28     return False
29 
30 
31 def pootle_context(request):
32     """Exposes settings to templates."""
33     #FIXME: maybe we should expose relevant settings only?
34     return {
35         'settings': {
36             'TITLE': settings.TITLE,
37             'POOTLE_INSTANCE_ID': settings.POOTLE_INSTANCE_ID,
38             'CAN_CONTACT': settings.CAN_CONTACT and settings.CONTACT_EMAIL,
39             'SCRIPT_NAME': settings.SCRIPT_NAME,
40             'POOTLE_VERSION': sver,
41             'CACHE_TIMEOUT': settings.CACHE_MIDDLEWARE_SECONDS,
42             'POOTLE_CACHE_TIMEOUT': settings.POOTLE_CACHE_TIMEOUT,
43             'DEBUG': settings.DEBUG,
44         },
45         'custom': settings.CUSTOM_TEMPLATE_CONTEXT,
46         'ALL_LANGUAGES': Language.live.cached_dict(),
47         'ALL_PROJECTS': Project.objects.cached_dict(request.user),
48         'display_agreement': _agreement_context(request),
49     }
50
```
--- 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_language/models.py b/pootle/apps/pootle_language/models.py
--- a/pootle/apps/pootle_language/models.py
+++ b/pootle/apps/pootle_language/models.py
@@ -7,6 +7,7 @@
 # or later license. See the LICENSE file for a copy of the license and the
 # AUTHORS file for copyright and authorship information.
 
+import locale
 from collections import OrderedDict
 
 from django.conf import settings
@@ -17,15 +18,12 @@
 from django.dispatch import receiver
 from django.utils.translation import ugettext_lazy as _
 
+from pootle.core.cache import make_method_key
 from pootle.core.mixins import TreeItem
 from pootle.core.url_helpers import get_editor_filter
 from pootle.i18n.gettext import tr_lang, language_dir
 
 
-# FIXME: Generate key dynamically
-CACHE_KEY = 'pootle-languages'
-
-
 class LanguageManager(models.Manager):
 
     def get_queryset(self):
@@ -51,13 +49,23 @@
                 project__isnull=True,
             ).distinct()
 
-    def cached_dict(self):
-        languages = cache.get(CACHE_KEY)
-        if not languages:
+    def cached_dict(self, locale_code='en-us'):
+        """Retrieves a sorted list of live language codes and names.
+
+        :param locale_code: the UI locale for which language full names need to
+            be localized.
+        :return: an `OrderedDict`
+        """
+        key = make_method_key(self, 'cached_dict', locale_code)
+        languages = cache.get(key, None)
+        if languages is None:
             languages = OrderedDict(
-                self.order_by('fullname').values_list('code', 'fullname')
+                sorted([(lang[0], tr_lang(lang[1]))
+                        for lang in self.values_list('code', 'fullname')],
+                        cmp=locale.strcoll,
+                        key=lambda x: x[1])
             )
-            cache.set(CACHE_KEY, languages, settings.OBJECT_CACHE_TIMEOUT)
+            cache.set(key, languages, settings.OBJECT_CACHE_TIMEOUT)
 
         return languages
 
@@ -166,4 +174,5 @@
     if instance.__class__.__name__ not in ['Language', 'TranslationProject']:
         return
 
-    cache.delete(CACHE_KEY)
+    key = make_method_key('LiveLanguageManager', 'cached_dict', '*')
+    cache.delete_pattern(key)
diff --git a/pootle/apps/pootle_misc/context_processors.py b/pootle/apps/pootle_misc/context_processors.py
--- a/pootle/apps/pootle_misc/context_processors.py
+++ b/pootle/apps/pootle_misc/context_processors.py
@@ -8,6 +8,7 @@
 # AUTHORS file for copyright and authorship information.
 
 from django.conf import settings
+from django.utils import translation
 
 from pootle.__version__ import sver
 from pootle_language.models import Language
@@ -43,7 +44,7 @@
             'DEBUG': settings.DEBUG,
         },
         'custom': settings.CUSTOM_TEMPLATE_CONTEXT,
-        'ALL_LANGUAGES': Language.live.cached_dict(),
+        'ALL_LANGUAGES': Language.live.cached_dict(translation.get_language()),
         'ALL_PROJECTS': Project.objects.cached_dict(request.user),
         'display_agreement': _agreement_context(request),
     }

{"golden_diff": "diff --git a/pootle/apps/pootle_language/models.py b/pootle/apps/pootle_language/models.py\n--- a/pootle/apps/pootle_language/models.py\n+++ b/pootle/apps/pootle_language/models.py\n@@ -7,6 +7,7 @@\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+import locale\n from collections import OrderedDict\n \n from django.conf import settings\n@@ -17,15 +18,12 @@\n from django.dispatch import receiver\n from django.utils.translation import ugettext_lazy as _\n \n+from pootle.core.cache import make_method_key\n from pootle.core.mixins import TreeItem\n from pootle.core.url_helpers import get_editor_filter\n from pootle.i18n.gettext import tr_lang, language_dir\n \n \n-# FIXME: Generate key dynamically\n-CACHE_KEY = 'pootle-languages'\n-\n-\n class LanguageManager(models.Manager):\n \n     def get_queryset(self):\n@@ -51,13 +49,23 @@\n                 project__isnull=True,\n             ).distinct()\n \n-    def cached_dict(self):\n-        languages = cache.get(CACHE_KEY)\n-        if not languages:\n+    def cached_dict(self, locale_code='en-us'):\n+        \"\"\"Retrieves a sorted list of live language codes and names.\n+\n+        :param locale_code: the UI locale for which language full names need to\n+            be localized.\n+        :return: an `OrderedDict`\n+        \"\"\"\n+        key = make_method_key(self, 'cached_dict', locale_code)\n+        languages = cache.get(key, None)\n+        if languages is None:\n             languages = OrderedDict(\n-                self.order_by('fullname').values_list('code', 'fullname')\n+                sorted([(lang[0], tr_lang(lang[1]))\n+                        for lang in self.values_list('code', 'fullname')],\n+                        cmp=locale.strcoll,\n+                        key=lambda x: x[1])\n             )\n-            cache.set(CACHE_KEY, languages, settings.OBJECT_CACHE_TIMEOUT)\n+            cache.set(key, languages, settings.OBJECT_CACHE_TIMEOUT)\n \n         return languages\n \n@@ -166,4 +174,5 @@\n     if instance.__class__.__name__ not in ['Language', 'TranslationProject']:\n         return\n \n-    cache.delete(CACHE_KEY)\n+    key = make_method_key('LiveLanguageManager', 'cached_dict', '*')\n+    cache.delete_pattern(key)\ndiff --git a/pootle/apps/pootle_misc/context_processors.py b/pootle/apps/pootle_misc/context_processors.py\n--- a/pootle/apps/pootle_misc/context_processors.py\n+++ b/pootle/apps/pootle_misc/context_processors.py\n@@ -8,6 +8,7 @@\n # AUTHORS file for copyright and authorship information.\n \n from django.conf import settings\n+from django.utils import translation\n \n from pootle.__version__ import sver\n from pootle_language.models import Language\n@@ -43,7 +44,7 @@\n             'DEBUG': settings.DEBUG,\n         },\n         'custom': settings.CUSTOM_TEMPLATE_CONTEXT,\n-        'ALL_LANGUAGES': Language.live.cached_dict(),\n+        'ALL_LANGUAGES': Language.live.cached_dict(translation.get_language()),\n         'ALL_PROJECTS': Project.objects.cached_dict(request.user),\n         'display_agreement': _agreement_context(request),\n     }\n", "issue": "Overview dropdown is using ISO639 names and not simplified toolkit names\nE.g. nso is using \"Pedi; Sepedi; Nothern Sotho\" instead of simply 'Northern Sotho'\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- 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.conf import settings\nfrom django.core.cache import cache\nfrom django.core.urlresolvers import reverse\nfrom django.db import models\nfrom django.db.models.signals import post_delete, post_save\nfrom django.dispatch import receiver\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom pootle.core.mixins import TreeItem\nfrom pootle.core.url_helpers import get_editor_filter\nfrom pootle.i18n.gettext import tr_lang, language_dir\n\n\n# FIXME: Generate key dynamically\nCACHE_KEY = 'pootle-languages'\n\n\nclass LanguageManager(models.Manager):\n\n    def get_queryset(self):\n        \"\"\"Mimics `select_related(depth=1)` behavior. Pending review.\"\"\"\n        return (\n            super(LanguageManager, self).get_queryset().select_related(\n                'directory',\n            )\n        )\n\n\nclass LiveLanguageManager(models.Manager):\n    \"\"\"Manager that only considers `live` languages.\n\n    A live language is any language other than the special `Templates`\n    language that have any project with translatable files and is not a\n    source language.\n    \"\"\"\n    def get_queryset(self):\n        return super(LiveLanguageManager, self).get_queryset().filter(\n                ~models.Q(code='templates'),\n                translationproject__isnull=False,\n                project__isnull=True,\n            ).distinct()\n\n    def cached_dict(self):\n        languages = cache.get(CACHE_KEY)\n        if not languages:\n            languages = OrderedDict(\n                self.order_by('fullname').values_list('code', 'fullname')\n            )\n            cache.set(CACHE_KEY, languages, settings.OBJECT_CACHE_TIMEOUT)\n\n        return languages\n\n\nclass Language(models.Model, TreeItem):\n\n    code_help_text = _('ISO 639 language code for the language, possibly '\n            'followed by an underscore (_) and an ISO 3166 country code. '\n            '<a href=\"http://www.w3.org/International/articles/language-tags/\">'\n            'More information</a>')\n    code = models.CharField(max_length=50, null=False, unique=True,\n            db_index=True, verbose_name=_(\"Code\"), help_text=code_help_text)\n    fullname = models.CharField(max_length=255, null=False,\n            verbose_name=_(\"Full Name\"))\n\n    specialchars_help_text = _('Enter any special characters that users '\n            'might find difficult to type')\n    specialchars = models.CharField(max_length=255, blank=True,\n            verbose_name=_(\"Special Characters\"),\n            help_text=specialchars_help_text)\n\n    plurals_help_text = _('For more information, visit '\n            '<a href=\"http://docs.translatehouse.org/projects/'\n            'localization-guide/en/latest/l10n/pluralforms.html\">'\n            'our page</a> on plural forms.')\n    nplural_choices = (\n            (0, _('Unknown')), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)\n    )\n    nplurals = models.SmallIntegerField(default=0, choices=nplural_choices,\n            verbose_name=_(\"Number of Plurals\"), help_text=plurals_help_text)\n    pluralequation = models.CharField(max_length=255, blank=True,\n            verbose_name=_(\"Plural Equation\"), help_text=plurals_help_text)\n\n    directory = models.OneToOneField('pootle_app.Directory', db_index=True,\n            editable=False)\n\n    objects = LanguageManager()\n    live = LiveLanguageManager()\n\n    class Meta:\n        ordering = ['code']\n        db_table = 'pootle_app_language'\n\n    ############################ Properties ###################################\n\n    @property\n    def pootle_path(self):\n        return '/%s/' % self.code\n\n    @property\n    def name(self):\n        \"\"\"Localized fullname for the language.\"\"\"\n        return tr_lang(self.fullname)\n\n    ############################ Methods ######################################\n\n    @property\n    def direction(self):\n        \"\"\"Return the language direction.\"\"\"\n        return language_dir(self.code)\n\n    def __unicode__(self):\n        return u\"%s - %s\" % (self.name, self.code)\n\n    def __init__(self, *args, **kwargs):\n        super(Language, self).__init__(*args, **kwargs)\n\n    def __repr__(self):\n        return u'<%s: %s>' % (self.__class__.__name__, self.fullname)\n\n    def save(self, *args, **kwargs):\n        # create corresponding directory object\n        from pootle_app.models.directory import Directory\n        self.directory = Directory.objects.root.get_or_make_subdir(self.code)\n\n        super(Language, self).save(*args, **kwargs)\n\n    def delete(self, *args, **kwargs):\n        directory = self.directory\n        super(Language, self).delete(*args, **kwargs)\n        directory.delete()\n\n    def get_absolute_url(self):\n        return reverse('pootle-language-overview', args=[self.code])\n\n    def get_translate_url(self, **kwargs):\n        return u''.join([\n            reverse('pootle-language-translate', args=[self.code]),\n            get_editor_filter(**kwargs),\n        ])\n\n    ### TreeItem\n\n    def get_children(self):\n        return self.translationproject_set.live()\n\n    def get_cachekey(self):\n        return self.directory.pootle_path\n\n    ### /TreeItem\n\n\n@receiver([post_delete, post_save])\ndef invalidate_language_list_cache(sender, instance, **kwargs):\n    # XXX: maybe use custom signals or simple function calls?\n    if instance.__class__.__name__ not in ['Language', 'TranslationProject']:\n        return\n\n    cache.delete(CACHE_KEY)\n", "path": "pootle/apps/pootle_language/models.py"}, {"content": "#!/usr/bin/env python\n# -*- 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.conf import settings\n\nfrom pootle.__version__ import sver\nfrom pootle_language.models import Language\nfrom pootle_project.models import Project\nfrom staticpages.models import LegalPage\n\n\ndef _agreement_context(request):\n    \"\"\"Returns whether the agreement box should be displayed or not.\"\"\"\n    request_path = request.META['PATH_INFO']\n    nocheck = filter(lambda x: request_path.startswith(x),\n                     settings.LEGALPAGE_NOCHECK_PREFIXES)\n\n    if (request.user.is_authenticated() and not nocheck and\n        LegalPage.objects.pending_user_agreement(request.user).exists()):\n        return True\n\n    return False\n\n\ndef pootle_context(request):\n    \"\"\"Exposes settings to templates.\"\"\"\n    #FIXME: maybe we should expose relevant settings only?\n    return {\n        'settings': {\n            'TITLE': settings.TITLE,\n            'POOTLE_INSTANCE_ID': settings.POOTLE_INSTANCE_ID,\n            'CAN_CONTACT': settings.CAN_CONTACT and settings.CONTACT_EMAIL,\n            'SCRIPT_NAME': settings.SCRIPT_NAME,\n            'POOTLE_VERSION': sver,\n            'CACHE_TIMEOUT': settings.CACHE_MIDDLEWARE_SECONDS,\n            'POOTLE_CACHE_TIMEOUT': settings.POOTLE_CACHE_TIMEOUT,\n            'DEBUG': settings.DEBUG,\n        },\n        'custom': settings.CUSTOM_TEMPLATE_CONTEXT,\n        'ALL_LANGUAGES': Language.live.cached_dict(),\n        'ALL_PROJECTS': Project.objects.cached_dict(request.user),\n        'display_agreement': _agreement_context(request),\n    }\n", "path": "pootle/apps/pootle_misc/context_processors.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- 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\nfrom collections import OrderedDict\n\nfrom django.conf import settings\nfrom django.core.cache import cache\nfrom django.core.urlresolvers import reverse\nfrom django.db import models\nfrom django.db.models.signals import post_delete, post_save\nfrom django.dispatch import receiver\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom pootle.core.cache import make_method_key\nfrom pootle.core.mixins import TreeItem\nfrom pootle.core.url_helpers import get_editor_filter\nfrom pootle.i18n.gettext import tr_lang, language_dir\n\n\nclass LanguageManager(models.Manager):\n\n    def get_queryset(self):\n        \"\"\"Mimics `select_related(depth=1)` behavior. Pending review.\"\"\"\n        return (\n            super(LanguageManager, self).get_queryset().select_related(\n                'directory',\n            )\n        )\n\n\nclass LiveLanguageManager(models.Manager):\n    \"\"\"Manager that only considers `live` languages.\n\n    A live language is any language other than the special `Templates`\n    language that have any project with translatable files and is not a\n    source language.\n    \"\"\"\n    def get_queryset(self):\n        return super(LiveLanguageManager, self).get_queryset().filter(\n                ~models.Q(code='templates'),\n                translationproject__isnull=False,\n                project__isnull=True,\n            ).distinct()\n\n    def cached_dict(self, locale_code='en-us'):\n        \"\"\"Retrieves a sorted list of live language codes and names.\n\n        :param locale_code: the UI locale for which language full names need to\n            be localized.\n        :return: an `OrderedDict`\n        \"\"\"\n        key = make_method_key(self, 'cached_dict', locale_code)\n        languages = cache.get(key, None)\n        if languages is None:\n            languages = OrderedDict(\n                sorted([(lang[0], tr_lang(lang[1]))\n                        for lang in self.values_list('code', 'fullname')],\n                        cmp=locale.strcoll,\n                        key=lambda x: x[1])\n            )\n            cache.set(key, languages, settings.OBJECT_CACHE_TIMEOUT)\n\n        return languages\n\n\nclass Language(models.Model, TreeItem):\n\n    code_help_text = _('ISO 639 language code for the language, possibly '\n            'followed by an underscore (_) and an ISO 3166 country code. '\n            '<a href=\"http://www.w3.org/International/articles/language-tags/\">'\n            'More information</a>')\n    code = models.CharField(max_length=50, null=False, unique=True,\n            db_index=True, verbose_name=_(\"Code\"), help_text=code_help_text)\n    fullname = models.CharField(max_length=255, null=False,\n            verbose_name=_(\"Full Name\"))\n\n    specialchars_help_text = _('Enter any special characters that users '\n            'might find difficult to type')\n    specialchars = models.CharField(max_length=255, blank=True,\n            verbose_name=_(\"Special Characters\"),\n            help_text=specialchars_help_text)\n\n    plurals_help_text = _('For more information, visit '\n            '<a href=\"http://docs.translatehouse.org/projects/'\n            'localization-guide/en/latest/l10n/pluralforms.html\">'\n            'our page</a> on plural forms.')\n    nplural_choices = (\n            (0, _('Unknown')), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6)\n    )\n    nplurals = models.SmallIntegerField(default=0, choices=nplural_choices,\n            verbose_name=_(\"Number of Plurals\"), help_text=plurals_help_text)\n    pluralequation = models.CharField(max_length=255, blank=True,\n            verbose_name=_(\"Plural Equation\"), help_text=plurals_help_text)\n\n    directory = models.OneToOneField('pootle_app.Directory', db_index=True,\n            editable=False)\n\n    objects = LanguageManager()\n    live = LiveLanguageManager()\n\n    class Meta:\n        ordering = ['code']\n        db_table = 'pootle_app_language'\n\n    ############################ Properties ###################################\n\n    @property\n    def pootle_path(self):\n        return '/%s/' % self.code\n\n    @property\n    def name(self):\n        \"\"\"Localized fullname for the language.\"\"\"\n        return tr_lang(self.fullname)\n\n    ############################ Methods ######################################\n\n    @property\n    def direction(self):\n        \"\"\"Return the language direction.\"\"\"\n        return language_dir(self.code)\n\n    def __unicode__(self):\n        return u\"%s - %s\" % (self.name, self.code)\n\n    def __init__(self, *args, **kwargs):\n        super(Language, self).__init__(*args, **kwargs)\n\n    def __repr__(self):\n        return u'<%s: %s>' % (self.__class__.__name__, self.fullname)\n\n    def save(self, *args, **kwargs):\n        # create corresponding directory object\n        from pootle_app.models.directory import Directory\n        self.directory = Directory.objects.root.get_or_make_subdir(self.code)\n\n        super(Language, self).save(*args, **kwargs)\n\n    def delete(self, *args, **kwargs):\n        directory = self.directory\n        super(Language, self).delete(*args, **kwargs)\n        directory.delete()\n\n    def get_absolute_url(self):\n        return reverse('pootle-language-overview', args=[self.code])\n\n    def get_translate_url(self, **kwargs):\n        return u''.join([\n            reverse('pootle-language-translate', args=[self.code]),\n            get_editor_filter(**kwargs),\n        ])\n\n    ### TreeItem\n\n    def get_children(self):\n        return self.translationproject_set.live()\n\n    def get_cachekey(self):\n        return self.directory.pootle_path\n\n    ### /TreeItem\n\n\n@receiver([post_delete, post_save])\ndef invalidate_language_list_cache(sender, instance, **kwargs):\n    # XXX: maybe use custom signals or simple function calls?\n    if instance.__class__.__name__ not in ['Language', 'TranslationProject']:\n        return\n\n    key = make_method_key('LiveLanguageManager', 'cached_dict', '*')\n    cache.delete_pattern(key)\n", "path": "pootle/apps/pootle_language/models.py"}, {"content": "#!/usr/bin/env python\n# -*- 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.conf import settings\nfrom django.utils import translation\n\nfrom pootle.__version__ import sver\nfrom pootle_language.models import Language\nfrom pootle_project.models import Project\nfrom staticpages.models import LegalPage\n\n\ndef _agreement_context(request):\n    \"\"\"Returns whether the agreement box should be displayed or not.\"\"\"\n    request_path = request.META['PATH_INFO']\n    nocheck = filter(lambda x: request_path.startswith(x),\n                     settings.LEGALPAGE_NOCHECK_PREFIXES)\n\n    if (request.user.is_authenticated() and not nocheck and\n        LegalPage.objects.pending_user_agreement(request.user).exists()):\n        return True\n\n    return False\n\n\ndef pootle_context(request):\n    \"\"\"Exposes settings to templates.\"\"\"\n    #FIXME: maybe we should expose relevant settings only?\n    return {\n        'settings': {\n            'TITLE': settings.TITLE,\n            'POOTLE_INSTANCE_ID': settings.POOTLE_INSTANCE_ID,\n            'CAN_CONTACT': settings.CAN_CONTACT and settings.CONTACT_EMAIL,\n            'SCRIPT_NAME': settings.SCRIPT_NAME,\n            'POOTLE_VERSION': sver,\n            'CACHE_TIMEOUT': settings.CACHE_MIDDLEWARE_SECONDS,\n            'POOTLE_CACHE_TIMEOUT': settings.POOTLE_CACHE_TIMEOUT,\n            'DEBUG': settings.DEBUG,\n        },\n        'custom': settings.CUSTOM_TEMPLATE_CONTEXT,\n        'ALL_LANGUAGES': Language.live.cached_dict(translation.get_language()),\n        'ALL_PROJECTS': Project.objects.cached_dict(request.user),\n        'display_agreement': _agreement_context(request),\n    }\n", "path": "pootle/apps/pootle_misc/context_processors.py"}]}