Adnane Belmadiaf has proposed merging
lp:~adnane002/loco-directory/ld-languages-menu into lp:loco-directory.
Requested reviews:
loco-directory-dev (loco-directory-dev)
Related bugs:
#648293 Add Asturian language to language selector
https://bugs.launchpad.net/bugs/648293
#648296 Languages in language selector should be listed alphabetically
https://bugs.launchpad.net/bugs/648296
--
https://code.launchpad.net/~adnane002/loco-directory/ld-languages-menu/+merge/42760
Your team loco-directory-dev is requested to review the proposed merge of
lp:~adnane002/loco-directory/ld-languages-menu into lp:loco-directory.
=== modified file 'loco_directory/common/context_processors.py'
--- loco_directory/common/context_processors.py 2010-11-20 17:25:50 +0000
+++ loco_directory/common/context_processors.py 2010-12-04 22:22:51 +0000
@@ -3,6 +3,9 @@
# to use this processor, add "common.context_processors.loco_version" to your variable TEMPLATE_CONTEXT_PROCESSORS in your settings file
from django.conf import settings
+from teams.models import Language
+
+from utils import check_for_language
def loco_version(request):
"""
@@ -48,3 +51,15 @@
from common.forms import SiteSearchForm
search_form = SiteSearchForm(data=request.GET)
return {'search_form': search_form}
+
+def language_menu(request):
+ """
+ Return a language list.
+ """
+ languages = {}
+ Languages = Language.objects.order_by('name')
+ for language in Languages:
+ if check_for_language(language.code):
+ languages[language.code] = language.name
+ languages = sorted([(value,key) for (key,value) in languages.items()])
+ return {'languages': languages}
=== modified file 'loco_directory/common/utils.py'
--- loco_directory/common/utils.py 2010-10-21 16:27:24 +0000
+++ loco_directory/common/utils.py 2010-12-04 22:22:51 +0000
@@ -1,10 +1,14 @@
+from django.conf import settings
+from settings import PROJECT_PATH
import email
import os
-from copy import deepcopy
import subprocess
import datetime
-
-from django.conf import settings
+import sys
+import gettext
+from copy import deepcopy
+
+
def write_log(job_name, log):
stamp_dir = os.path.join(settings.PROJECT_PATH, 'data')
@@ -102,4 +106,16 @@
self.index = -1
return ''
-
+def check_for_language(lang_code):
+ """
+ Checks whether there is a global language file for the given language code.
+ """
+ globalpath = os.path.join(PROJECT_PATH, 'locale')
+ for dirnames in os.listdir(globalpath):
+ if dirnames == lang_code:
+ for dirpath_local, dirnames_local, filenames in os.walk(os.path.join(globalpath, dirnames, 'LC_MESSAGES')):
+ #print filenames
+ if 'django.mo' in filenames:
+ return True
+ else:
+ return False
=== modified file 'loco_directory/common/views.py'
--- loco_directory/common/views.py 2010-11-20 17:25:50 +0000
+++ loco_directory/common/views.py 2010-12-04 22:22:51 +0000
@@ -3,9 +3,10 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth import logout
-from django.utils.translation import check_for_language
from django.conf import settings
+from utils import check_for_language
+
def index(request):
from events.models import GlobalEvent, TeamEvent
team_event_count = TeamEvent.objects.next_events().count()
@@ -58,7 +59,8 @@
if check_for_language(lang):
if hasattr(request, 'session'):
request.session['django_language'] = lang
- response.set_cookie(settings.LANGUAGE_COOKIE_NAME,lang)
+ else:
+ response.set_cookie(settings.LANGUAGE_COOKIE_NAME,lang)
return response
def site_search(request):
=== modified file 'loco_directory/settings.py'
--- loco_directory/settings.py 2010-11-20 17:25:50 +0000
+++ loco_directory/settings.py 2010-12-04 22:22:51 +0000
@@ -88,6 +88,7 @@
"common.context_processors.login_redirect",
"common.context_processors.url_base",
"common.context_processors.site_search",
+ "common.context_processors.language_menu",
)
ROOT_URLCONF = 'loco_directory.urls'
=== modified file 'loco_directory/templates/base.html'
--- loco_directory/templates/base.html 2010-11-20 17:25:50 +0000
+++ loco_directory/templates/base.html 2010-12-04 22:22:51 +0000
@@ -54,8 +54,8 @@
<form name="lang-switcher" style="text-align:right;" action="/language/" method="get">
<input name="next" type="hidden" value="{{ request.path }}" />
<select name="lang" onchange="document.forms['lang-switcher'].submit()">
- {% for lang in LANGUAGES %}
- <option value="{{ lang.0 }}"{% ifequal LANGUAGE_CODE lang.0 %} selected="selected"{% endifequal %}>{{ lang.1 }}</option>
+ {% for lang in languages %}
+ <option value="{{ lang.1 }}"{% ifequal LANGUAGE_CODE lang.1 %} selected="selected"{% endifequal %}>{{ lang.0 }}</option>
{% endfor %}
</select>
</form>
_______________________________________________
Mailing list: https://launchpad.net/~loco-directory-dev
Post to : [email protected]
Unsubscribe : https://launchpad.net/~loco-directory-dev
More help : https://help.launchpad.net/ListHelp