Skip to content

Commit

Permalink
Refactor KNOWN_LANGUAGES into {DEV,PROD}_LANGUAGES
Browse files Browse the repository at this point in the history
Remove KNOWN_LANGUAGES in favor of DEV_LANGUAGES and PROD_LANGUAGES
which are lazily used in LANGUAGES_URL_MAP and LANGUAGES depending on
the value of DEV.

DEV_LANGUAGES are autogenerated from the contents of the locale/
directory in the root of the project.

PROD_LANGUAGES should be maintained manually.

In addition, the commit removes the RTL_LANGUAGES setting which wasn't
used anywhere.  Django's default value for LANGUAGES_BIDI is sufficient
and used by django.utils.translation.get_language_bidi.
  • Loading branch information
stasm committed May 25, 2011
1 parent 8d584fe commit 2d27585
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
10 changes: 9 additions & 1 deletion apps/examples/templates/examples/home.html
@@ -1,7 +1,9 @@
{% extends "example_base.html" %}

{% block content %}
<h1>{{ _('Hello world') }}</h1>
<h1>
<a href="/">{{ _('Hello world') }}</a>
</h1>

{# L10n: This is a localizer comment #}
<p>{{ _('This is a <em>test view</em>.') }}</p>
Expand All @@ -11,4 +13,10 @@ <h1>{{ _('Hello world') }}</h1>
something <strong>awesome</strong>.
{% endtrans %}
</p>
<p>
{% trans langs=LANGUAGES.items() %}
Current locale: {{ LANG }}.<br>
Available locales: {{ langs }}.
{% endtrans %}
</p>
{% endblock %}
40 changes: 29 additions & 11 deletions settings.py
Expand Up @@ -10,6 +10,8 @@

ROOT_PACKAGE = os.path.basename(ROOT)

# Is this a dev instance?
DEV = False

DEBUG = False
TEMPLATE_DEBUG = DEBUG
Expand Down Expand Up @@ -51,25 +53,41 @@
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-US'

# Accepted locales
KNOWN_LANGUAGES = ('en-US',)
## Accepted locales

# List of RTL locales known to this project. Subset of LANGUAGES.
RTL_LANGUAGES = () # ('ar', 'fa', 'fa-IR', 'he')
# On dev instances, the list of accepted locales defaults to the contents of
# the `locale` directory. A localizer can add their locale in the l10n
# repository (copy of which is checked out into `locale`) in order to start
# testing the localization on the dev server.
DEV_LANGUAGES = [loc.replace('_', '-') for loc in os.listdir(path('locale'))
if os.path.isdir(path('locale', loc)) and
loc != 'templates']

LANGUAGE_URL_MAP = dict([(i.lower(), i) for i in KNOWN_LANGUAGES])
# On stage/prod, the list of accepted locales is manually maintained. Only
# locales whose localizers have signed off on their work should be listed here.
PROD_LANGUAGES = (
'en-US',
)

def lazy_lang_url_map():
from django.conf import settings
langs = DEV_LANGUAGES if settings.DEV else PROD_LANGUAGES
return dict([(i.lower(), i) for i in langs])

LANGUAGE_URL_MAP = lazy(lazy_lang_url_map, dict)()

# Override Django's built-in with our native names
class LazyLangs(dict):
def __new__(self):
from product_details import product_details
return dict([(lang.lower(), product_details.languages[lang]['native'])
for lang in KNOWN_LANGUAGES])
def lazy_langs():
from django.conf import settings
from product_details import product_details
langs = DEV_LANGUAGES if settings.DEV else PROD_LANGUAGES
return dict([(lang.lower(), product_details.languages[lang]['native'])
for lang in langs])

# Where to store product details etc.
PROD_DETAILS_DIR = path('lib/product_details_json')

LANGUAGES = lazy(LazyLangs, dict)()
LANGUAGES = lazy(lazy_langs, dict)()

# Paths that don't require a locale code in the URL.
SUPPORTED_NONLOCALES = ['media']
Expand Down
2 changes: 2 additions & 0 deletions settings_local.py-dist
Expand Up @@ -30,3 +30,5 @@ MANAGERS = ADMINS


DEBUG = TEMPLATE_DEBUG = True

DEV = True

0 comments on commit 2d27585

Please sign in to comment.