Skip to content
This repository has been archived by the owner on Mar 19, 2020. It is now read-only.

Commit

Permalink
bug 772108 - Verbatim links on the locale pages, r=Pike
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Oct 8, 2012
1 parent 5f7985f commit baa0b24
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 1 deletion.
85 changes: 85 additions & 0 deletions apps/homepage/management/commands/verbatim-codes-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

"""Checks the list of languages on https://localize.mozilla.org and compares
them against settings.VERBATIM_CONVERSIONS and suggests things that might
need to change.
Requires `pyquery` to be installed. See requirements/dev.txt
"""

import re
from django.conf import settings
from django.core.management.base import BaseCommand
from life.models import Locale


class Command(BaseCommand): # pragma: no cover

help = __doc__

def handle(self, **options):
# delay this import till run-time
from pyquery import PyQuery as pq

d = pq(url='https://localize.mozilla.org/')
VERBATIM = {}
for each in d('td.language a'):
lang = each.text
code = each.attrib['href'].split('/')[1]
assert lang and code
VERBATIM[code] = lang

ELMO = {}
for l in Locale.objects.all():
ELMO[l.code] = l.name

ending = re.compile('-[A-Z]{2}')

not_matched = set()
conversions = {}
for code, name in ELMO.items():
if code in VERBATIM:
pass
elif code.replace('-', '_') in VERBATIM:
pass
elif ending.findall(code) and code.split('-')[0] in VERBATIM:
conversions[code] = code.split('-')[0]
continue
else:
not_matched.add(code)

combined = {}
for code in not_matched:
combined[code] = None
for key, value in conversions.items():
combined[key] = value

if combined == settings.VERBATIM_CONVERSIONS:
return

print "SUGGESTED NEW SETTING..."
print
print "VERBATIM_CONVERSIONS = {"
for key in sorted(combined):
key = str(key)
value = combined[key]
if value:
value = str(value)
print " " * 4 + "%r: %r," % (key, value)
print "}"
print "\n"

print "POTENTIAL PROBLEMS..."
print
for each in combined:
if each not in settings.VERBATIM_CONVERSIONS:
print "\tMissing".ljust(20), each
elif combined[each] != settings.VERBATIM_CONVERSIONS[each]:
print "\tMismatch".ljust(20), each.ljust(10),
print repr(settings.VERBATIM_CONVERSIONS[each]), '-->',
print repr(combined[each])
for each in settings.VERBATIM_CONVERSIONS:
if each not in combined:
print "\tExcessive".ljust(20), each
7 changes: 6 additions & 1 deletion apps/homepage/templates/homepage/locale-team.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@
<li>
<a href="#webdashboard">Web Dashboard</a>
</li>
<li class="last">
<li {% if not verbatim_url %}class="last"{% endif %}>
<a href="https://wiki.mozilla.org/L10n:Teams:{{locale.code}}" class="external-link">Contact</a>
</li>
{% if verbatim_url %}
<li class="last">
<a href="{{ verbatim_url }}" class="external-link">Verbatim</a>
</li>
{% endif %}
</ul>
</div>

Expand Down
10 changes: 10 additions & 0 deletions apps/homepage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,22 @@ def locale_team(request, code):

name = loc.name or loc.code

gliblocale = settings.VERBATIM_CONVERSIONS.get(
loc.code,
loc.code.replace('-', '_')
)
if gliblocale:
verbatim_url = 'https://localize.mozilla.org/%s/' % gliblocale
else:
verbatim_url = None

return render(request, 'homepage/locale-team.html', {
'locale': loc,
'locale_name': name,
'shipping': ship_div,
'bugs': bug_div,
'webdashboard_url': settings.WEBDASHBOARD_URL,
'verbatim_url': verbatim_url,
})

# redirects for moves within pushes app, and moving the diff view
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage
mock
pyquery
22 changes: 22 additions & 0 deletions settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,25 @@
AUTHENTICATION_BACKENDS = ('lib.auth.backends.MozLdapBackend',)

WEBDASHBOARD_URL = 'https://l10n.mozilla-community.org/webdashboard/'

## Verbatim bridging
# codes that map to `None` deliberately don't exist on Verbatim
VERBATIM_CONVERSIONS = {
'en-US': None,
'es-ES': 'es',
'fy-NL': 'fy',
'ga-IE': 'ga',
'ja-JP-mac': 'ja',
'nr': None,
'pa-IN': 'pa',
'pt-PT': 'pt',
'rw': None,
'ss': None,
'sv-SE': 'sv',
'tn': None,
'ts': None,
've': None,
'x-testing': None,
'xh': None,
'zu': None,
}

0 comments on commit baa0b24

Please sign in to comment.