@@ -0,0 +1,1237 @@
+from __future__ import absolute_import, unicode_literals%0A%0Afrom django.core.management.base import BaseCommand%0Afrom molo.core.models import (%0A    Languages, Main, SiteLanguage, SiteLanguageRelation, LanguageRelation)%0A%0A# This is currently made to work for single sites%0A%0A%0Aclass Command(BaseCommand):%0A    def add_arguments(self, parser):%0A        parser.add_argument('new_language_locale', type=str)%0A%0A    def handle(self, *args, **options):%0A        new_language_locale = options.get('new_language_locale', None)%0A        main_language = SiteLanguage.objects.get(is_main_language=True)%0A        main = Main.objects.first()%0A%0A        # add the new language%0A        new_language = SiteLanguageRelation.objects.create(%0A            language_setting=Languages.for_site(main.get_site()),%0A            locale=new_language_locale,%0A            is_active=True)%0A%0A        # switch the language in the language relation to the new language%0A        for relation in LanguageRelation.objects.filter(%0A                language__is_main_language=True):%0A            relation.language = new_language%0A            relation.save()%0A%0A        # delete the old language%0A        main_language.delete()%0A%0A        new_language.is_main_language = True%0A        new_language.save()%0A

add command for switching main language