@@ -0,0 +1,2307 @@
+from django.core.management.base import BaseCommand, CommandError%0Afrom optparse import make_option%0Aimport json%0Aimport csv%0A%0A%0Aclass Command(BaseCommand):%0A    option_list = BaseCommand.option_list + (%0A        make_option(%0A            '--output',%0A            dest='output',%0A            type=str,%0A            default='new-flashcards.json'),%0A    )%0A%0A    def handle(self, *args, **options):%0A        if len(args) %3C 3:%0A            raise CommandError(%0A                %22Not enough arguments. Three arguments required: %22 +%0A                %22 %3Cflashcards-file%3E %3Clang-code%3E %3Ctranslations-file%3E%22)%0A        translations = self.get_translations(args%5B2%5D)%0A        lang = args%5B1%5D%0A        with open(args%5B0%5D, 'r') as json_file:%0A            data = json.load(json_file, 'utf-8')%0A            for c in data%5B'contexts'%5D:%0A                if c%5B'id'%5D in translations:%0A                    c%5B'name-' + lang%5D = translations%5Bc%5B'id'%5D%5D%0A                    c%5B'content-' + lang%5D = c%5B'content-en'%5D%0A                else:%0A                    print ('Warning: missing translation for context %25s' %25%0A                           c%5B'name-en'%5D)%0A            for t in data%5B'terms'%5D:%0A                if t%5B'id'%5D in translations:%0A                    t%5B'name-' + lang%5D = translations%5Bt%5B'id'%5D%5D%0A                else:%0A                    t%5B'name-' + lang%5D = t%5B'name-en'%5D%0A                    print ('Warning: missing translation for term ' +%0A                           '%5C'%25s%5C', id: %5C'%25s%5C'' %25 (t%5B'name-en'%5D, t%5B'id'%5D))%0A            for c in data%5B'categories'%5D:%0A                if c%5B'id'%5D in translations:%0A                    c%5B'name-' + lang%5D = translations%5Bc%5B'id'%5D%5D%0A                else:%0A                    print ('Warning: missing translation for category ' +%0A                           '%5C'%25s%5C', id: %5C'%25s%5C'' %25 (c%5B'name-en'%5D, c%5B'id'%5D))%0A        with open(options%5B'output'%5D, 'w') as f:%0A            json.dump(data, f, indent=2)%0A            print ('Updated flashcards written to file: %5C'%25s%5C'' %25%0A                   options%5B'output'%5D)%0A%0A    def get_translations(self, filename):%0A        translations = %7B%7D%0A        with open(filename, 'r') as csvfile:%0A            translations_reader = csv.reader(csvfile, delimiter='%5Ct')%0A            for row in translations_reader:%0A                if len(row) == 2:%0A                    translations%5Brow%5B0%5D%5D = row%5B1%5D%0A        return translations%0A

Create add_language command