Commit 43fe1274 authored by Claude Paroz's avatar Claude Paroz

Link to current language team on homepage (Fixes #569819)

parent 2e414fae
......@@ -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))
......
......@@ -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")
......
......@@ -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">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment