def handle_noargs(self, **options): codes = open(os.path.join(os.path.dirname(__file__), 'all-locales')).read().split() codes.extend([ "en-US", # US English, not included because it is default "hsb", # Upper Sorbian "ms", # Malay - see bug 286080 ]) for l in Language.objects.all(): # already there if l.code in codes: print "Found %s" % l continue # Mozilla uses dashes, not underscores if l.code.replace("_", "-") in codes: print "Tweaking code for %s" % l l.code = l.code.replace("_", "-") l.save() continue # probably some unneeded double, like af_ZA - af is enough print "Deleting %s" % l l.delete() # Transifex at the moment does not have Luganda language in fixture if not Language.objects.filter(code="lg").exists(): print "Adding Luganda (lg)" Language(name="Luganda", code="lg").save()
def test_printf_formats(self): class Language(object): pass sl = Language() sl.nplurals = 2 tl = Language() tl.nplurals = 2 v = PrintfFormatNumberValidator(sl, tl) old = "%s %d" new = "%s %d" v(old, new) new = "%f" self.assertRaises(ValidationError, v, old, new) tl.nplurals = 3 new = "%f %s %x" v(old, new)
def test_singular_printf_number(self): class Language(object): pass sl = Language() sl.nplurals = 2 tl = Language() tl.nplurals = 2 v = PrintfFormatPluralizedNumberValidator(sl, tl, rule=5) old = "%s apples" new = "apples" self.assertRaises(ValidationError, v, old, new) v.rule = 1 new = "apple" v(old, new) v.rule = 5 tl.nplurals = 5 v(old, new)
def as_aggregated_rlstats(cursor): """ Yield each row from a cursor as a AggregatedRLStats object. """ total = Resource.objects.by_project(project).aggregate( total=Sum('total_entities'))['total'] # Create a kwargs var to be passed to AggregatedRLStats init method kwargs = {'total': total} for row in queryset: # Create a fake language object and associate it to the object key kwargs.update({ 'object': Language(code=row['language__code'], name=row['language__name']), 'last_update': row['last_update'], 'translated': row['translated'] }) yield AggregatedRLStats(**kwargs)