We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Support for properly displaying the site translated to RTL languages
**What's the problem this feature will solve?**
Display PyPI.org propely when translated to RTL languages such as Arabic, Farsi and Hebrew.

**Describe the solution you'd like**
I can't suggest a specific technical solution, since I'm not familiar with the website's design and implementation.

**Additional context**
The context is the recent work on translation into additional languages.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `warehouse/i18n/__init__.py`
Content:
```
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 # See the License for the specific language governing permissions and
11 # limitations under the License.
12 
13 import functools
14 
15 from babel.core import Locale
16 from pyramid import viewderivers
17 from pyramid.i18n import TranslationStringFactory, default_locale_negotiator
18 from pyramid.threadlocal import get_current_request
19 
20 from warehouse.cache.http import add_vary
21 
22 # Taken from:
23 # https://github.com/django/django/blob/master/django/conf/locale/__init__.py
24 KNOWN_LOCALES = {
25     "en": "English",  # English
26     "es": "español",  # Spanish
27     "fr": "français",  # French
28     "ja": "日本語",  # Japanese
29     "pt_BR": "Português Brasileiro",  # Brazilian Portugeuse
30     "uk": "Українська",  # Ukrainian
31     "el": "Ελληνικά",  # Greek
32     "de": "Deutsch",  # German
33     "zh_Hans": "简体中文",  # Simplified Chinese
34     "ru": "Русский",  # Russian
35 }
36 
37 LOCALE_ATTR = "_LOCALE_"
38 
39 _translation_factory = TranslationStringFactory("messages")
40 
41 
42 class LazyString:
43     def __init__(self, fn, *args, **kwargs):
44         self.fn = fn
45         self.args = args
46         self.mapping = kwargs.get("mapping", {})
47         self.kwargs = kwargs
48 
49     def __json__(self, request):
50         return str(self)
51 
52     def __mod__(self, new_mapping):
53         mapping = self.mapping.copy()
54         mapping.update(new_mapping)
55         return LazyString(self.fn, *self.args, mapping=new_mapping, **self.kwargs)
56 
57     def __str__(self):
58         return self.fn(*self.args, **self.kwargs)
59 
60 
61 def _locale(request):
62     """
63     Computes a babel.core:Locale() object for this request.
64     """
65     return Locale.parse(request.locale_name, sep="_")
66 
67 
68 def _negotiate_locale(request):
69     locale_name = getattr(request, LOCALE_ATTR, None)
70     if locale_name is not None:
71         return locale_name
72 
73     locale_name = request.params.get(LOCALE_ATTR)
74     if locale_name is not None:
75         return locale_name
76 
77     locale_name = request.cookies.get(LOCALE_ATTR)
78     if locale_name is not None:
79         return locale_name
80 
81     if not request.accept_language:
82         return default_locale_negotiator(request)
83 
84     return request.accept_language.best_match(
85         tuple(KNOWN_LOCALES.keys()), default_match=default_locale_negotiator(request)
86     )
87 
88 
89 def _localize(request, message, **kwargs):
90     """
91     To be used on the request directly, e.g. `request._(message)`
92     """
93     return request.localizer.translate(_translation_factory(message, **kwargs))
94 
95 
96 def localize(message, **kwargs):
97     """
98     To be used when we don't have the request context, e.g.
99     `from warehouse.i18n import localize as _`
100     """
101 
102     def _lazy_localize(message, **kwargs):
103         request = get_current_request()
104         return _localize(request, message, **kwargs)
105 
106     return LazyString(_lazy_localize, message, **kwargs)
107 
108 
109 class InvalidLocalizer:
110     def _fail(self):
111         raise RuntimeError("Cannot use localizer without has_translations=True")
112 
113     @property
114     def locale_name(self):
115         self._fail()
116 
117     def pluralize(self, *args, **kwargs):
118         self._fail()
119 
120     def translate(self, *args, **kwargs):
121         self._fail()
122 
123 
124 def translated_view(view, info):
125     if info.options.get("has_translations"):
126         # If this page can be translated, then we'll add a Vary: PyPI-Locale
127         #   Vary header.
128         # Note: This will give weird results if hitting PyPI directly instead of through
129         #       the Fastly VCL which sets PyPI-Locale.
130         return add_vary("PyPI-Locale")(view)
131     elif info.exception_only:
132         return view
133     else:
134         # If we're not using translations on this view, then we'll wrap the view
135         # with a wrapper that just ensures that the localizer cannot be used.
136         @functools.wraps(view)
137         def wrapped(context, request):
138             # This whole method is a little bit of an odd duck, we want to make
139             # sure that we don't actually *access* request.localizer, because
140             # doing so triggers the machinery to create a new localizer. So
141             # instead we will dig into the request object __dict__ to
142             # effectively do the same thing, just without triggering an access
143             # on request.localizer.
144 
145             # Save the original session so that we can restore it once the
146             # inner views have been called.
147             nothing = object()
148             original_localizer = request.__dict__.get("localizer", nothing)
149 
150             # This particular view hasn't been set to allow access to the
151             # translations, so we'll just assign an InvalidLocalizer to
152             # request.localizer
153             request.__dict__["localizer"] = InvalidLocalizer()
154 
155             try:
156                 # Invoke the real view
157                 return view(context, request)
158             finally:
159                 # Restore the original session so that things like
160                 # pyramid_debugtoolbar can access it.
161                 if original_localizer is nothing:
162                     del request.__dict__["localizer"]
163                 else:
164                     request.__dict__["localizer"] = original_localizer
165 
166         return wrapped
167 
168 
169 translated_view.options = {"has_translations"}
170 
171 
172 def includeme(config):
173     # Add the request attributes
174     config.add_request_method(_locale, name="locale", reify=True)
175     config.add_request_method(_localize, name="_")
176 
177     # Register our translation directory.
178     config.add_translation_dirs("warehouse:locale/")
179 
180     config.set_locale_negotiator(_negotiate_locale)
181 
182     # Register our i18n/l10n filters for Jinja2
183     filters = config.get_settings().setdefault("jinja2.filters", {})
184     filters.setdefault("format_date", "warehouse.i18n.filters:format_date")
185     filters.setdefault("format_datetime", "warehouse.i18n.filters:format_datetime")
186     filters.setdefault(
187         "format_rfc822_datetime", "warehouse.i18n.filters:format_rfc822_datetime"
188     )
189     filters.setdefault("format_number", "warehouse.i18n.filters:format_number")
190 
191     jglobals = config.get_settings().setdefault("jinja2.globals", {})
192     jglobals.setdefault("KNOWN_LOCALES", "warehouse.i18n:KNOWN_LOCALES")
193 
194     config.add_view_deriver(
195         translated_view, over="rendered_view", under=viewderivers.INGRESS
196     )
197
```
--- 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/warehouse/i18n/__init__.py b/warehouse/i18n/__init__.py
--- a/warehouse/i18n/__init__.py
+++ b/warehouse/i18n/__init__.py
@@ -19,19 +19,21 @@
 
 from warehouse.cache.http import add_vary
 
-# Taken from:
-# https://github.com/django/django/blob/master/django/conf/locale/__init__.py
 KNOWN_LOCALES = {
-    "en": "English",  # English
-    "es": "español",  # Spanish
-    "fr": "français",  # French
-    "ja": "日本語",  # Japanese
-    "pt_BR": "Português Brasileiro",  # Brazilian Portugeuse
-    "uk": "Українська",  # Ukrainian
-    "el": "Ελληνικά",  # Greek
-    "de": "Deutsch",  # German
-    "zh_Hans": "简体中文",  # Simplified Chinese
-    "ru": "Русский",  # Russian
+    identifier: Locale.parse(identifier, sep="_")
+    for identifier in [
+        "en",  # English
+        "es",  # Spanish
+        "fr",  # French
+        "ja",  # Japanese
+        "pt_BR",  # Brazilian Portugeuse
+        "uk",  # Ukranian
+        "el",  # Greek
+        "de",  # German
+        "zh_Hans",  # Simplified Chinese
+        "ru",  # Russian
+        "he",  # Hebrew
+    ]
 }
 
 LOCALE_ATTR = "_LOCALE_"
@@ -60,9 +62,9 @@
 
 def _locale(request):
     """
-    Computes a babel.core:Locale() object for this request.
+    Gets a babel.core:Locale() object for this request.
     """
-    return Locale.parse(request.locale_name, sep="_")
+    return KNOWN_LOCALES.get(request.locale_name, "en")
 
 
 def _negotiate_locale(request):

{"golden_diff": "diff --git a/warehouse/i18n/__init__.py b/warehouse/i18n/__init__.py\n--- a/warehouse/i18n/__init__.py\n+++ b/warehouse/i18n/__init__.py\n@@ -19,19 +19,21 @@\n \n from warehouse.cache.http import add_vary\n \n-# Taken from:\n-# https://github.com/django/django/blob/master/django/conf/locale/__init__.py\n KNOWN_LOCALES = {\n-    \"en\": \"English\",  # English\n-    \"es\": \"espa\u00f1ol\",  # Spanish\n-    \"fr\": \"fran\u00e7ais\",  # French\n-    \"ja\": \"\u65e5\u672c\u8a9e\",  # Japanese\n-    \"pt_BR\": \"Portugu\u00eas Brasileiro\",  # Brazilian Portugeuse\n-    \"uk\": \"\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430\",  # Ukrainian\n-    \"el\": \"\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac\",  # Greek\n-    \"de\": \"Deutsch\",  # German\n-    \"zh_Hans\": \"\u7b80\u4f53\u4e2d\u6587\",  # Simplified Chinese\n-    \"ru\": \"\u0420\u0443\u0441\u0441\u043a\u0438\u0439\",  # Russian\n+    identifier: Locale.parse(identifier, sep=\"_\")\n+    for identifier in [\n+        \"en\",  # English\n+        \"es\",  # Spanish\n+        \"fr\",  # French\n+        \"ja\",  # Japanese\n+        \"pt_BR\",  # Brazilian Portugeuse\n+        \"uk\",  # Ukranian\n+        \"el\",  # Greek\n+        \"de\",  # German\n+        \"zh_Hans\",  # Simplified Chinese\n+        \"ru\",  # Russian\n+        \"he\",  # Hebrew\n+    ]\n }\n \n LOCALE_ATTR = \"_LOCALE_\"\n@@ -60,9 +62,9 @@\n \n def _locale(request):\n     \"\"\"\n-    Computes a babel.core:Locale() object for this request.\n+    Gets a babel.core:Locale() object for this request.\n     \"\"\"\n-    return Locale.parse(request.locale_name, sep=\"_\")\n+    return KNOWN_LOCALES.get(request.locale_name, \"en\")\n \n \n def _negotiate_locale(request):\n", "issue": "Support for properly displaying the site translated to RTL languages\n**What's the problem this feature will solve?**\r\nDisplay PyPI.org propely when translated to RTL languages such as Arabic, Farsi and Hebrew.\r\n\r\n**Describe the solution you'd like**\r\nI can't suggest a specific technical solution, since I'm not familiar with the website's design and implementation.\r\n\r\n**Additional context**\r\nThe context is the recent work on translation into additional languages.\n", "before_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport functools\n\nfrom babel.core import Locale\nfrom pyramid import viewderivers\nfrom pyramid.i18n import TranslationStringFactory, default_locale_negotiator\nfrom pyramid.threadlocal import get_current_request\n\nfrom warehouse.cache.http import add_vary\n\n# Taken from:\n# https://github.com/django/django/blob/master/django/conf/locale/__init__.py\nKNOWN_LOCALES = {\n    \"en\": \"English\",  # English\n    \"es\": \"espa\u00f1ol\",  # Spanish\n    \"fr\": \"fran\u00e7ais\",  # French\n    \"ja\": \"\u65e5\u672c\u8a9e\",  # Japanese\n    \"pt_BR\": \"Portugu\u00eas Brasileiro\",  # Brazilian Portugeuse\n    \"uk\": \"\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430\",  # Ukrainian\n    \"el\": \"\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac\",  # Greek\n    \"de\": \"Deutsch\",  # German\n    \"zh_Hans\": \"\u7b80\u4f53\u4e2d\u6587\",  # Simplified Chinese\n    \"ru\": \"\u0420\u0443\u0441\u0441\u043a\u0438\u0439\",  # Russian\n}\n\nLOCALE_ATTR = \"_LOCALE_\"\n\n_translation_factory = TranslationStringFactory(\"messages\")\n\n\nclass LazyString:\n    def __init__(self, fn, *args, **kwargs):\n        self.fn = fn\n        self.args = args\n        self.mapping = kwargs.get(\"mapping\", {})\n        self.kwargs = kwargs\n\n    def __json__(self, request):\n        return str(self)\n\n    def __mod__(self, new_mapping):\n        mapping = self.mapping.copy()\n        mapping.update(new_mapping)\n        return LazyString(self.fn, *self.args, mapping=new_mapping, **self.kwargs)\n\n    def __str__(self):\n        return self.fn(*self.args, **self.kwargs)\n\n\ndef _locale(request):\n    \"\"\"\n    Computes a babel.core:Locale() object for this request.\n    \"\"\"\n    return Locale.parse(request.locale_name, sep=\"_\")\n\n\ndef _negotiate_locale(request):\n    locale_name = getattr(request, LOCALE_ATTR, None)\n    if locale_name is not None:\n        return locale_name\n\n    locale_name = request.params.get(LOCALE_ATTR)\n    if locale_name is not None:\n        return locale_name\n\n    locale_name = request.cookies.get(LOCALE_ATTR)\n    if locale_name is not None:\n        return locale_name\n\n    if not request.accept_language:\n        return default_locale_negotiator(request)\n\n    return request.accept_language.best_match(\n        tuple(KNOWN_LOCALES.keys()), default_match=default_locale_negotiator(request)\n    )\n\n\ndef _localize(request, message, **kwargs):\n    \"\"\"\n    To be used on the request directly, e.g. `request._(message)`\n    \"\"\"\n    return request.localizer.translate(_translation_factory(message, **kwargs))\n\n\ndef localize(message, **kwargs):\n    \"\"\"\n    To be used when we don't have the request context, e.g.\n    `from warehouse.i18n import localize as _`\n    \"\"\"\n\n    def _lazy_localize(message, **kwargs):\n        request = get_current_request()\n        return _localize(request, message, **kwargs)\n\n    return LazyString(_lazy_localize, message, **kwargs)\n\n\nclass InvalidLocalizer:\n    def _fail(self):\n        raise RuntimeError(\"Cannot use localizer without has_translations=True\")\n\n    @property\n    def locale_name(self):\n        self._fail()\n\n    def pluralize(self, *args, **kwargs):\n        self._fail()\n\n    def translate(self, *args, **kwargs):\n        self._fail()\n\n\ndef translated_view(view, info):\n    if info.options.get(\"has_translations\"):\n        # If this page can be translated, then we'll add a Vary: PyPI-Locale\n        #   Vary header.\n        # Note: This will give weird results if hitting PyPI directly instead of through\n        #       the Fastly VCL which sets PyPI-Locale.\n        return add_vary(\"PyPI-Locale\")(view)\n    elif info.exception_only:\n        return view\n    else:\n        # If we're not using translations on this view, then we'll wrap the view\n        # with a wrapper that just ensures that the localizer cannot be used.\n        @functools.wraps(view)\n        def wrapped(context, request):\n            # This whole method is a little bit of an odd duck, we want to make\n            # sure that we don't actually *access* request.localizer, because\n            # doing so triggers the machinery to create a new localizer. So\n            # instead we will dig into the request object __dict__ to\n            # effectively do the same thing, just without triggering an access\n            # on request.localizer.\n\n            # Save the original session so that we can restore it once the\n            # inner views have been called.\n            nothing = object()\n            original_localizer = request.__dict__.get(\"localizer\", nothing)\n\n            # This particular view hasn't been set to allow access to the\n            # translations, so we'll just assign an InvalidLocalizer to\n            # request.localizer\n            request.__dict__[\"localizer\"] = InvalidLocalizer()\n\n            try:\n                # Invoke the real view\n                return view(context, request)\n            finally:\n                # Restore the original session so that things like\n                # pyramid_debugtoolbar can access it.\n                if original_localizer is nothing:\n                    del request.__dict__[\"localizer\"]\n                else:\n                    request.__dict__[\"localizer\"] = original_localizer\n\n        return wrapped\n\n\ntranslated_view.options = {\"has_translations\"}\n\n\ndef includeme(config):\n    # Add the request attributes\n    config.add_request_method(_locale, name=\"locale\", reify=True)\n    config.add_request_method(_localize, name=\"_\")\n\n    # Register our translation directory.\n    config.add_translation_dirs(\"warehouse:locale/\")\n\n    config.set_locale_negotiator(_negotiate_locale)\n\n    # Register our i18n/l10n filters for Jinja2\n    filters = config.get_settings().setdefault(\"jinja2.filters\", {})\n    filters.setdefault(\"format_date\", \"warehouse.i18n.filters:format_date\")\n    filters.setdefault(\"format_datetime\", \"warehouse.i18n.filters:format_datetime\")\n    filters.setdefault(\n        \"format_rfc822_datetime\", \"warehouse.i18n.filters:format_rfc822_datetime\"\n    )\n    filters.setdefault(\"format_number\", \"warehouse.i18n.filters:format_number\")\n\n    jglobals = config.get_settings().setdefault(\"jinja2.globals\", {})\n    jglobals.setdefault(\"KNOWN_LOCALES\", \"warehouse.i18n:KNOWN_LOCALES\")\n\n    config.add_view_deriver(\n        translated_view, over=\"rendered_view\", under=viewderivers.INGRESS\n    )\n", "path": "warehouse/i18n/__init__.py"}], "after_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport functools\n\nfrom babel.core import Locale\nfrom pyramid import viewderivers\nfrom pyramid.i18n import TranslationStringFactory, default_locale_negotiator\nfrom pyramid.threadlocal import get_current_request\n\nfrom warehouse.cache.http import add_vary\n\nKNOWN_LOCALES = {\n    identifier: Locale.parse(identifier, sep=\"_\")\n    for identifier in [\n        \"en\",  # English\n        \"es\",  # Spanish\n        \"fr\",  # French\n        \"ja\",  # Japanese\n        \"pt_BR\",  # Brazilian Portugeuse\n        \"uk\",  # Ukranian\n        \"el\",  # Greek\n        \"de\",  # German\n        \"zh_Hans\",  # Simplified Chinese\n        \"ru\",  # Russian\n        \"he\",  # Hebrew\n    ]\n}\n\nLOCALE_ATTR = \"_LOCALE_\"\n\n_translation_factory = TranslationStringFactory(\"messages\")\n\n\nclass LazyString:\n    def __init__(self, fn, *args, **kwargs):\n        self.fn = fn\n        self.args = args\n        self.mapping = kwargs.get(\"mapping\", {})\n        self.kwargs = kwargs\n\n    def __json__(self, request):\n        return str(self)\n\n    def __mod__(self, new_mapping):\n        mapping = self.mapping.copy()\n        mapping.update(new_mapping)\n        return LazyString(self.fn, *self.args, mapping=new_mapping, **self.kwargs)\n\n    def __str__(self):\n        return self.fn(*self.args, **self.kwargs)\n\n\ndef _locale(request):\n    \"\"\"\n    Gets a babel.core:Locale() object for this request.\n    \"\"\"\n    return KNOWN_LOCALES.get(request.locale_name, \"en\")\n\n\ndef _negotiate_locale(request):\n    locale_name = getattr(request, LOCALE_ATTR, None)\n    if locale_name is not None:\n        return locale_name\n\n    locale_name = request.params.get(LOCALE_ATTR)\n    if locale_name is not None:\n        return locale_name\n\n    locale_name = request.cookies.get(LOCALE_ATTR)\n    if locale_name is not None:\n        return locale_name\n\n    if not request.accept_language:\n        return default_locale_negotiator(request)\n\n    return request.accept_language.best_match(\n        tuple(KNOWN_LOCALES.keys()), default_match=default_locale_negotiator(request)\n    )\n\n\ndef _localize(request, message, **kwargs):\n    \"\"\"\n    To be used on the request directly, e.g. `request._(message)`\n    \"\"\"\n    return request.localizer.translate(_translation_factory(message, **kwargs))\n\n\ndef localize(message, **kwargs):\n    \"\"\"\n    To be used when we don't have the request context, e.g.\n    `from warehouse.i18n import localize as _`\n    \"\"\"\n\n    def _lazy_localize(message, **kwargs):\n        request = get_current_request()\n        return _localize(request, message, **kwargs)\n\n    return LazyString(_lazy_localize, message, **kwargs)\n\n\nclass InvalidLocalizer:\n    def _fail(self):\n        raise RuntimeError(\"Cannot use localizer without has_translations=True\")\n\n    @property\n    def locale_name(self):\n        self._fail()\n\n    def pluralize(self, *args, **kwargs):\n        self._fail()\n\n    def translate(self, *args, **kwargs):\n        self._fail()\n\n\ndef translated_view(view, info):\n    if info.options.get(\"has_translations\"):\n        # If this page can be translated, then we'll add a Vary: PyPI-Locale\n        #   Vary header.\n        # Note: This will give weird results if hitting PyPI directly instead of through\n        #       the Fastly VCL which sets PyPI-Locale.\n        return add_vary(\"PyPI-Locale\")(view)\n    elif info.exception_only:\n        return view\n    else:\n        # If we're not using translations on this view, then we'll wrap the view\n        # with a wrapper that just ensures that the localizer cannot be used.\n        @functools.wraps(view)\n        def wrapped(context, request):\n            # This whole method is a little bit of an odd duck, we want to make\n            # sure that we don't actually *access* request.localizer, because\n            # doing so triggers the machinery to create a new localizer. So\n            # instead we will dig into the request object __dict__ to\n            # effectively do the same thing, just without triggering an access\n            # on request.localizer.\n\n            # Save the original session so that we can restore it once the\n            # inner views have been called.\n            nothing = object()\n            original_localizer = request.__dict__.get(\"localizer\", nothing)\n\n            # This particular view hasn't been set to allow access to the\n            # translations, so we'll just assign an InvalidLocalizer to\n            # request.localizer\n            request.__dict__[\"localizer\"] = InvalidLocalizer()\n\n            try:\n                # Invoke the real view\n                return view(context, request)\n            finally:\n                # Restore the original session so that things like\n                # pyramid_debugtoolbar can access it.\n                if original_localizer is nothing:\n                    del request.__dict__[\"localizer\"]\n                else:\n                    request.__dict__[\"localizer\"] = original_localizer\n\n        return wrapped\n\n\ntranslated_view.options = {\"has_translations\"}\n\n\ndef includeme(config):\n    # Add the request attributes\n    config.add_request_method(_locale, name=\"locale\", reify=True)\n    config.add_request_method(_localize, name=\"_\")\n\n    # Register our translation directory.\n    config.add_translation_dirs(\"warehouse:locale/\")\n\n    config.set_locale_negotiator(_negotiate_locale)\n\n    # Register our i18n/l10n filters for Jinja2\n    filters = config.get_settings().setdefault(\"jinja2.filters\", {})\n    filters.setdefault(\"format_date\", \"warehouse.i18n.filters:format_date\")\n    filters.setdefault(\"format_datetime\", \"warehouse.i18n.filters:format_datetime\")\n    filters.setdefault(\n        \"format_rfc822_datetime\", \"warehouse.i18n.filters:format_rfc822_datetime\"\n    )\n    filters.setdefault(\"format_number\", \"warehouse.i18n.filters:format_number\")\n\n    jglobals = config.get_settings().setdefault(\"jinja2.globals\", {})\n    jglobals.setdefault(\"KNOWN_LOCALES\", \"warehouse.i18n:KNOWN_LOCALES\")\n\n    config.add_view_deriver(\n        translated_view, over=\"rendered_view\", under=viewderivers.INGRESS\n    )\n", "path": "warehouse/i18n/__init__.py"}]}