コード例 #1
0
def migrate_content(apps, schema_editor):
    Client = apps.get_model('clients', 'Client')
    tenant = Client.objects.get(schema_name=connection.tenant.schema_name)
    languages = get_languages()

    Category = apps.get_model('categories', 'Category')
    CategoryTranslation = apps.get_model('categories', 'CategoryTranslation')

    for block in Category.objects.all():
        for (language, _long_language) in languages:
            activate(language)
            _trans._active.value = tenant_translation(language, tenant.client_name)
            CategoryTranslation.objects.create(
                master_id=block.pk,
                language_code=language,
                title=block.title_old,
                description=block.description_old
            )

    CategoryContent = apps.get_model('categories', 'CategoryContent')
    CategoryContentTranslation = apps.get_model('categories', 'CategoryContentTranslation')

    for block in CategoryContent.objects.all():
        for (language, _long_language) in languages:
            activate(language)
            _trans._active.value = tenant_translation(language, tenant.client_name)
            CategoryContentTranslation.objects.create(
                master_id=block.pk,
                language_code=language,
                title=block.title_old,
                description=block.description_old,
                link_url=block.link_url_old,
                link_text=block.link_text_old,
            )
コード例 #2
0
def create_refunded_phase(apps, schema_editor):
    ProjectPhase = apps.get_model('bb_projects', 'ProjectPhase')
    try:
        ProjectPhase.objects.get_or_create(
            id=13,
            slug='refunded',
            viewable=True,
            editable=False,
            sequence=11,
            description='The project was refunded')
    except FieldError:
        # If project phases are already translated then translate description
        object, created = ProjectPhase.objects.get_or_create(id=13,
                                                             slug='refunded',
                                                             viewable=True,
                                                             editable=False,
                                                             sequence=11)
        Client = apps.get_model('clients', 'Client')
        PhaseTranslation = apps.get_model('bb_projects',
                                          'ProjectPhaseTranslation')

        tenant = Client.objects.get(schema_name=connection.tenant.schema_name)

        with LocalTenant(tenant):
            languages = get_languages()
            for (language, _long_language) in languages:
                activate(language)
                _trans._active.value = tenant_translation(
                    language, tenant.client_name)
                PhaseTranslation.objects.create(
                    master_id=object.pk,
                    language_code=language,
                    name=_('Refunded'),
                    description=_('The project was refunded'),
                )
コード例 #3
0
    def process_request(self, request):
        if request.path.startswith('/api'):
            try:
                language = request.META['HTTP_X_APPLICATION_LANGUAGE']
                if language not in [lang[0] for lang in properties.LANGUAGES]:
                    language = properties.LANGUAGE_CODE
            except KeyError:
                language = properties.LANGUAGE_CODE

            translation.activate(language)

            translation._trans._active.value = tenant_translation(
                language, connection.tenant.client_name)
            request.LANGUAGE_CODE = translation.get_language()
コード例 #4
0
ファイル: retranslate_models.py プロジェクト: raux/bluebottle
def run():
    for tenant in Client.objects.all():
        with LocalTenant(tenant):
            activate('en')
            for model in [Country, ProjectTheme, ProjectPhase, Skill]:
                for obj in model.objects.all():
                    for translation in obj.translations.all():
                        activate(translation.language_code)
                        _trans._active.value = tenant_translation(
                            translation.language_code, connection.tenant.client_name
                        )
                        translation.name = _(translation.name)
                        print translation.name, translation.language_code
                        translation.save()
コード例 #5
0
def translate_skills(apps, schema_editor):
    Client = apps.get_model('clients', 'Client')
    Theme = apps.get_model('bb_projects', 'ProjectTheme')
    ThemeTranslation = apps.get_model('bb_projects', 'ProjectThemeTranslation')

    tenant = Client.objects.get(schema_name=connection.tenant.schema_name)

    with LocalTenant(tenant):
        languages = get_languages()
        for object in Theme.objects.all():
            for (language, _long_language) in languages:
                activate(language)
                _trans._active.value = tenant_translation(
                    language, tenant.client_name)
                ThemeTranslation.objects.create(
                    master_id=object.pk,
                    language_code=language,
                    name=_(object.name),
                    _description=_(object.description),
                )
コード例 #6
0
def translate_geo(apps, schema_editor):
    Client = apps.get_model('clients', 'Client')
    tenant = Client.objects.get(schema_name=connection.tenant.schema_name)

    with LocalTenant(tenant):
        languages = get_languages()
        for model in ['Region', 'SubRegion', 'Country']:
            Model = apps.get_model('geo', model)
            ModelTranslation = apps.get_model('geo',
                                              '{}Translation'.format(model))

            for object in Model.objects.all():
                for (language, _long_language) in languages:
                    activate(language)
                    _trans._active.value = tenant_translation(
                        language, tenant.client_name)
                    ModelTranslation.objects.create(
                        master_id=object.pk,
                        language_code=language,
                        _name=_(object.name),
                    )
コード例 #7
0
 def __exit__(self, exc_type, exc_value, traceback):
     translation.activate(self.old_language)
     translation._trans._active.value = tenant_translation(
         self.old_language, connection.tenant.client_name)
コード例 #8
0
 def __enter__(self):
     self.old_language = translation.get_language() or 'en'
     translation.activate(self.language)
     translation._trans._active.value = tenant_translation(
         self.language, connection.tenant.client_name)