How to use weblate - 10 common examples

To help you get started, we’ve selected a few weblate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WeblateOrg / weblate / weblate / permissions / tests.py View on Github external
def test_affects_unrelated(self):
        """Unrelated objects test.

        If I set an ACL on an object, it should not affect objects
        that it doesn't match. (in this case, a different language)
        """
        lang_cs = Language.objects.get(code='cs')
        lang_de = Language.objects.get(code='de')
        trans_cs = Translation.objects.create(
            component=self.component, language=lang_cs,
            plural=lang_cs.plural,
            filename="this/is/not/a.template"
        )
        trans_de = Translation.objects.create(
            component=self.component, language=lang_de,
            plural=lang_de.plural,
            filename="this/is/not/a.template"
        )

        acl = GroupACL.objects.create(language=lang_cs)
        acl.groups.add(self.group)

        self.assertTrue(can_edit(self.privileged, trans_cs, self.PERMISSION))
github WeblateOrg / weblate / weblate / lang / tests.py View on Github external
def run_create(self, original, expected, direction, plural, name, create):
        """Test that auto create correctly handles languages"""
        # Lookup language
        lang = Language.objects.auto_get_or_create(original, create=False)
        self.assertEqual(
            create,
            not bool(lang.pk),
            'Failed to assert creation for {}: {}'.format(original, create),
        )
        # Create language
        lang = Language.objects.auto_get_or_create(original)
        # Check language code
        self.assertEqual(
            lang.code, expected, 'Invalid code for {0}: {1}'.format(original, lang.code)
        )
        # Check direction
        self.assertEqual(
            lang.direction, direction, 'Invalid direction for {0}'.format(original)
        )
        # Check plurals
github WeblateOrg / weblate / weblate / accounts / tests.py View on Github external
def test_profile(self):
        # Get profile page
        response = self.client.get(reverse('profile'))
        self.assertContains(response, 'action="/accounts/profile/"')

        # Save profile
        response = self.client.post(
            reverse('profile'),
            {
                'language': 'cs',
                'languages': Language.objects.get(code='cs').id,
                'secondary_languages': Language.objects.get(code='cs').id,
                'first_name': 'First Last',
                'email': 'noreply@weblate.org',
                'username': 'testik',
            }
        )
        self.assertRedirects(response, reverse('profile'))
github WeblateOrg / weblate / weblate / lang / tests.py View on Github external
def test_edit_plural(self):
        language = Language.objects.get(code='cs')
        self.user.is_superuser = True
        self.user.save()
        response = self.client.post(
            reverse('edit-plural', kwargs={'pk': language.plural.pk}),
            {'number': '2', 'equation': 'n != 1'},
        )
        self.assertRedirects(
            response, reverse('show_language', kwargs={'lang': 'cs'}) + '#information'
        )
github WeblateOrg / weblate / weblate / billing / tests.py View on Github external
def add_project(self):
        name = 'test{0}'.format(self.projectnum)
        self.projectnum += 1
        project = Project.objects.create(
            name=name, slug=name, access_control=Project.ACCESS_PROTECTED
        )
        self.billing.projects.add(project)
        project.add_user(self.user, '@Billing')
github WeblateOrg / weblate / weblate / addons / tests.py View on Github external
def test_creation(self):
        link = self.component.get_repo_link_url()
        self.assertEqual(Component.objects.filter(repo=link).count(), 0)
        addon = DiscoveryAddon.create(
            self.component,
            configuration={
                'file_format': 'po',
                'match': r'(?P[^/]*)/(?P[^/]*)\.po',
                'name_template': '{{ component|title }}',
                'language_regex': '^(?!xx).*$',
                'base_file_template': '',
                'remove': True,
            },
        )
        self.assertEqual(Component.objects.filter(repo=link).count(), 3)
        addon.post_update(self.component, '')
        self.assertEqual(Component.objects.filter(repo=link).count(), 3)
github WeblateOrg / weblate / weblate / billing / tests.py View on Github external
def setUp(self):
        self.user = User.objects.create_user(
            username='bill',
            password='kill',
            email='noreply@example.net'
        )
        self.plan = Plan.objects.create(
            name='test', limit_projects=1, price=1.0
        )
        self.billing = Billing.objects.create(plan=self.plan)
        self.billing.owners.add(self.user)
        self.invoice = Invoice.objects.create(
            billing=self.billing,
            start=timezone.now().date() - timedelta(days=2),
            end=timezone.now().date() + timedelta(days=2),
            amount=10,
            ref='00000',
        )
github WeblateOrg / weblate / weblate / addons / tests.py View on Github external
def test_creation(self):
        link = self.component.get_repo_link_url()
        self.assertEqual(Component.objects.filter(repo=link).count(), 0)
        addon = DiscoveryAddon.create(
            self.component,
            configuration={
                'file_format': 'po',
                'match': r'(?P[^/]*)/(?P[^/]*)\.po',
                'name_template': '{{ component|title }}',
                'language_regex': '^(?!xx).*$',
                'base_file_template': '',
                'remove': True,
            },
        )
        self.assertEqual(Component.objects.filter(repo=link).count(), 3)
        addon.post_update(self.component, '')
        self.assertEqual(Component.objects.filter(repo=link).count(), 3)
github WeblateOrg / weblate / weblate / utils / ratelimit.py View on Github external
def rate_wrap(request, *args, **kwargs):
            if request.method == 'POST' and not check_rate_limit(scope, request):
                # Rotate session token
                rotate_token(request)
                # Logout user
                do_logout = request.user.is_authenticated
                if do_logout:
                    logout(request)
                messages.error(
                    request,
                    render_to_string(
                        'ratelimit.html', {'do_logout': do_logout}
                    )
                )
                return redirect('login')
            return function(request, *args, **kwargs)
        return rate_wrap
github WeblateOrg / weblate / weblate / lang / models.py View on Github external
def auto_create(self, code, create=True):
        """Automatically create new language based on code and best guess
        of parameters.
        """
        # Create standard language
        name = '{0} (generated)'.format(code)
        if create:
            lang = self.get_or_create(code=code, defaults={'name': name})[0]
        else:
            lang = Language(code=code, name=name)

        baselang = None

        # Check for different variant
        if baselang is None and '@' in code:
            parts = code.split('@')
            baselang = self.fuzzy_get(code=parts[0], strict=True)

        # Check for different country
        if baselang is None and '_' in code or '-' in code:
            parts = code.replace('-', '_').split('_')
            baselang = self.fuzzy_get(code=parts[0], strict=True)

        if baselang is not None:
            lang.name = baselang.name
            lang.direction = baselang.direction