[damned-lies] Link to current language team on homepage (Fixes #569819)
- From: Claude Paroz <claudep src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [damned-lies] Link to current language team on homepage (Fixes #569819)
- Date: Sat, 5 Dec 2009 21:17:30 +0000 (UTC)
commit 43fe12748e2c9ab78a967dd4b358f7824d6239fa
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Dec 5 22:15:37 2009 +0100
Link to current language team on homepage (Fixes #569819)
common/views.py | 11 ++++++++---
languages/models.py | 28 ++++++++++++++++++++++++++++
templates/index.html | 7 +++++++
3 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/common/views.py b/common/views.py
index 8ef0c1f..71baaaf 100644
--- a/common/views.py
+++ b/common/views.py
@@ -28,18 +28,23 @@ from django.conf import settings
from people.models import Person
from teams.models import Role
from people.forms import RegistrationForm
-
+from languages.models import Language
def index(request):
+ """ Homepage view """
translator_credits = _("translator-credits")
- # FIXME Not sure the LANGUAGE_CODE test is useful
- if request.LANGUAGE_CODE == 'en' or translator_credits == "translator-credits":
+ if translator_credits == "translator-credits":
translator_credits = ''
else:
translator_credits = translator_credits.split('\n')
+ curlang = Language.get_language_from_ianacode(request.LANGUAGE_CODE)
+ if curlang.locale == 'en':
+ curlang = None
+
context = {
'pageSection': 'home',
+ 'user_language': curlang,
'translator_credits': translator_credits
}
return render_to_response('index.html', context, context_instance=RequestContext(request))
diff --git a/languages/models.py b/languages/models.py
index ecf60ed..1096802 100644
--- a/languages/models.py
+++ b/languages/models.py
@@ -15,12 +15,40 @@ class Language(models.Model):
def __unicode__(self):
return "%s (%s)" % (self.name, self.locale)
+ @classmethod
+ def get_language_from_ianacode(cls, ianacode):
+ """ Return a matching Language object corresponding to LANGUAGE_CODE (BCP47-formatted)
+ This is a sort of BCP47 to ISO639 conversion function """
+ iana_splitted = ianacode.split("-", 1)
+ iana_suffix = len(iana_splitted) > 1 and iana_splitted[1] or ""
+ iana_suffix = iana_suffix.replace('Latn','latin').replace('Cyrl','cyrillic')
+ lang_list = cls.objects.filter(locale__startswith=iana_splitted[0])
+ if len(lang_list) == 0:
+ return None
+ elif len(lang_list) > 1:
+ # Find the best language to return
+ best_lang = lang_list[0]
+ for lang in lang_list:
+ if lang.get_suffix():
+ if iana_suffix.lower() == lang.get_suffix().lower():
+ return lang
+ else:
+ best_lang = lang
+ return best_lang
+ return lang_list[0]
+
def get_name(self):
if self.name != self.locale:
return _(self.name)
else:
return self.locale
+ def get_suffix(self):
+ splitted = self.locale.replace('@','_').split('_')
+ if len(splitted) > 1:
+ return splitted[-1]
+ return None
+
def get_plurals(self):
# Translators: this concerns an unknown plural form
return self.plurals or _("Unknown")
diff --git a/templates/index.html b/templates/index.html
index 61599db..f625323 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -13,6 +13,13 @@
<h2><a href="{% url teams %}">{% trans "Teams" %}</a></h2>
<p>{% trans "List of all GNOME Translation Teams, with full information such as primary contact (coordinator), web pages and mailing list information." %}
{% trans "If there is no team for your language, you can easily <a href='http://live.gnome.org/TranslationProject/StartingATeam/'>start your own team</a>." %}
+{% if user_language %}
+ {% with user_language.get_team_url as team_url %}
+ {% with user_language.name as language_name %}
+ <br /><strong>{% blocktrans %}Go to the <a href="{{ team_url }}">{{ language_name }} team page</a> and help us to translate GNOME!{% endblocktrans %}</strong>
+ {% endwith %}
+ {% endwith %}
+{% endif %}
</p>
</td><td valign="top">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]