← Back to team overview

team4alfanous team mailing list archive

[Branch ~team4alfanous/alfanous/alfanous-git] Rev 524: Prepare django wui to manage multi-languages

 

------------------------------------------------------------
revno: 524
committer: Assem Chelli <assem.ch@xxxxxxxxx>
timestamp: Mon 2013-01-07 20:27:14 +0100
message:
  Prepare django wui to manage multi-languages
modified:
  src/alfanous-django/settings.py
  src/alfanous-django/templates/base.html
  src/alfanous-django/urls.py
  src/alfanous-django/wui/views.py


--
lp:alfanous
https://code.launchpad.net/~team4alfanous/alfanous/alfanous-git

Your team Alfanous team is subscribed to branch lp:alfanous.
To unsubscribe from this branch go to https://code.launchpad.net/~team4alfanous/alfanous/alfanous-git/+edit-subscription
=== modified file 'src/alfanous-django/settings.py'
--- src/alfanous-django/settings.py	2013-01-07 16:40:08 +0000
+++ src/alfanous-django/settings.py	2013-01-07 19:27:14 +0000
@@ -78,9 +78,16 @@
 
 # Language code for this installation. All choices can be found here:
 # http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-us'
-
-
+LANGUAGE_CODE = 'en'
+
+LANGUAGES = ( 
+    ( 'ar', "Arabic" ),
+    ( 'en', "English" ),
+    #( 'fr', "French" ),
+    ( 'id', "Indonesian" ),
+    #( 'ms', "Malay" ),
+    #( 'sv', "swedish" )
+ )
 
 
 SITE_ID = 1

=== modified file 'src/alfanous-django/templates/base.html'
--- src/alfanous-django/templates/base.html	2013-01-06 18:31:20 +0000
+++ src/alfanous-django/templates/base.html	2013-01-07 19:27:14 +0000
@@ -209,12 +209,21 @@
 <ul class="headermenu">
 <li class="menuitem"><span>{{ _("Ayahs") }}</span></li>
 {# <li class="menuitem"><a href="/sura/">{{ _("Surahs") }}</a></li> #}
-<li class="menuitem"><a href="/word/">{{ _("Words") }}</a></li>
-<li class="menuitem"><a href="/translation/">{{ _("Translations") }}</a></li>
+<li class="menuitem"><a href="{{ current_path }}word/">{{ _("Words") }}</a></li>
+<li class="menuitem"><a href="{{ current_path }}translation/">{{ _("Translations") }}</a></li>
 {# <li class="menuitem"><a href="/taffsir/">{{ _("Taffsirs") }}</a></li> #}
 {# <li class="menuitem"><a href="/hadith/">{{ _("Hadiths") }}</a></li> #}
 {# <li class="menuitem"><a href="/dream/">{{ _("Dreams") }}</a></li> #}
 {# <li class="menuitem"><a href="/poem/">{{ _("Poems") }}</a></li> #}
+
+</ul>
+<ul class="right">
+{% for language in available_languages %}
+<li class="menuitem" >
+{% ifequal language.0 language_code %}<span >{{ language.1 }}</span> 
+{% else %} <a href="/{{ language.0 }}/">{{ language.1 }}</a></span></li>
+{% endifequal %} 
+{% endfor %}
 </ul>
 <div style="clear: left"></div>
 </div>

=== modified file 'src/alfanous-django/urls.py'
--- src/alfanous-django/urls.py	2013-01-06 18:31:20 +0000
+++ src/alfanous-django/urls.py	2013-01-07 19:27:14 +0000
@@ -14,6 +14,9 @@
 
     # Uncomment the next line to enable the admin:
     url( r'^admin/', include( admin.site.urls ) ),
-    url( r'^(?P<unit>\w+)/', 'alfanous-django.wui.views.results' ),
+    url( r'^(?P<language>\w{2})/(?P<unit>\w{3,15})/', 'alfanous-django.wui.views.results' ),
+    url( r'^(?P<language>\w{2})/', 'alfanous-django.wui.views.results' ),
+    url( r'^(?P<unit>\w{3,15})/(?P<language>\w{2})/', 'alfanous-django.wui.views.results' ),
+    url( r'^(?P<unit>\w{3,15})/', 'alfanous-django.wui.views.results' ),
     url( r'^', 'alfanous-django.wui.views.results' ),
  )

=== modified file 'src/alfanous-django/wui/views.py'
--- src/alfanous-django/wui/views.py	2013-01-07 09:54:04 +0000
+++ src/alfanous-django/wui/views.py	2013-01-07 19:27:14 +0000
@@ -13,6 +13,8 @@
 from django.http import HttpResponse
 from django.shortcuts import render_to_response
 
+from django.conf import settings
+
 from django.utils import translation
 from django.utils.translation import ugettext as _
 from django.utils.translation import ungettext
@@ -48,7 +50,7 @@
     return response
 
 
-def results( request, unit = "aya" ):
+def results( request, unit = "aya", language = None ):
     """     """
     if unit not in ["aya", "word", "translation"]: # authorized units
     	unit = "aya"
@@ -86,13 +88,22 @@
     raw_show = RAWoutput.do( show_params )   if show_params else None
 
     # language information
-    language = translation.get_language_from_request( request )
-    language_info = get_language_info( language )
-
-    #print  language ,language_info['name'], language_info['name_local'], language_info['bidi']
-
-
-    translation.activate( language )
+    current_language = translation.get_language()
+    request_language = translation.get_language_from_request( request )
+    available_languages = settings.LANGUAGES
+    try:
+        translation.activate( language )
+        language_info = get_language_info( language )
+    except:
+    	try:
+	        translation.activate( request_language )
+	        language_info = get_language_info( request_language )
+	        language = request_language
+    	except:
+    		translation.activate( current_language )
+	        language_info = get_language_info( current_language )
+	        language = current_language
+
     request.LANGUAGE_CODE = translation.get_language()
 
     mytemplate = unit + '_search.html'
@@ -103,6 +114,8 @@
                                 "bidi": "rtl" if language_info['bidi']
                                               else "ltr",
                                 "language_local_name": language_info['name_local'],
+                                "language_code": language_info['code'],
+                                "available_languages": available_languages,
                                 "align": "right" if language_info['bidi']
                                               else "left",
                                 "align_inverse": "left" if language_info['bidi']