Skip to content
Snippets Groups Projects
Commit 7c1dd948 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Even more language handling logic fix!

parent 61b5e7f6
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@
# You should have received a copy of the Bioforsk Open Source License
# along with VIPSWeb. If not, see <http://www.bioforsk.no/licenses/>.
#
# @author: Tor-Einar Skog <tor-einar.skog@bioforsk.no>
from django.shortcuts import render
from django.conf import settings
from django.utils import translation
......@@ -27,7 +27,7 @@ def index(request):
message_tags = MessageTag.get_message_tags()
messages_by_tag = {}
for message_tag_id in settings.FRONTPAGE_MESSAGE_TAG_IDS:
messages = Message.get_messages_by_tag(message_tag_id)
messages = Message.get_messages_by_tag(message_tag_id, translation.get_language())
#print "MESSAGES: %s" % messages
messages_by_tag[message_tag_id] = messages
#for message in messages:
......
......@@ -93,15 +93,15 @@ class Message:
Currently this is a REST service
"""
@staticmethod
def get_message(message_id):
def get_message(message_id, current_language=settings.VIPSLOGIC_LANGUAGE_CODE):
message_json = Message.get_message_as_json(message_id)
return Message.get_instance_from_dict(message_json)
return Message.get_instance_from_dict(message_json, current_language)
@staticmethod
def get_messages_by_tag(tag_id):
def get_messages_by_tag(tag_id, current_language=settings.VIPSLOGIC_LANGUAGE_CODE):
messages = []
for item in Message.get_messages_by_tag_as_json(tag_id):
message = Message.get_instance_from_dict(item)
message = Message.get_instance_from_dict(item, current_language)
messages.append(message)
return messages
......@@ -158,7 +158,12 @@ class Message:
for message_locale in message_locale_set:
if message_locale["messageLocalePK"]["locale"] == language:
return message_locale
# Fallback: Return the first locale in the set
# Fallback: Find message in web site's default language
for message_locale in message_locale_set:
if message_locale["messageLocalePK"]["locale"] == settings.LANGUAGE_CODE:
return message_locale
# If none of this works, try to return the first locale found
# If no locale, return empty set
if len(message_locale_set) > 0:
return message_locale_set[0]
else:
......
......@@ -30,6 +30,6 @@ def index(request):
def detail(request, message_id):
context = {
#'message' : get_object_or_404(Message, pk=message_id)
'message': Message.get_message(message_id)
'message': Message.get_message(message_id, translation.get_language())
}
return render(request, 'messages/detail.html', context)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment