Example #1
0
    def plurr_format(self, str1, str2, **kwargs):
        """For plurr-formatted strings, checks the syntax is correct."""
        # Ignore check for empty target strings or non Plurr-formatted
        # source strings
        if str2 == u"" or not plurr_format_regex.search(str1):
            return True

        # Ignore check if library is missing
        try:
            from plurr import Plurr
        except ImportError:
            return True

        plurr = Plurr()

        try:
            plurr.format(
                str2,
                {},
                {
                    "locale": kwargs["language_code"],
                    "strict": False,
                    "callback": lambda x: "",
                },
            )
        except SyntaxError as e:
            raise checks.FilterFailure(str(e))

        return True
Example #2
0
    def plurr_format(self, str1, str2, **kwargs):
        """For plurr-formatted strings, checks the syntax is correct."""
        # Ignore check for empty target strings or non Plurr-formatted
        # source strings
        if str2 == u'' or not plurr_format_regex.search(str1):
            return True

        # Ignore check if library is missing
        try:
            from plurr import Plurr
        except ImportError:
            return True

        plurr = Plurr()

        try:
            plurr.format(str2, {}, {
                'locale': kwargs['language_code'],
                'strict': False,
                'callback': lambda x: '',
            })
        except SyntaxError as e:
            raise checks.FilterFailure(e.message)

        return True
Example #3
0
    def plurr_format(self, str1, str2, **kwargs):
        """For plurr-formatted strings, checks the syntax is correct."""
        # Ignore check for empty target strings or non Plurr-formatted
        # source strings
        if str2 == u'' or not plurr_format_regex.search(str1):
            return True

        # Ignore check if library is missing
        try:
            from plurr import Plurr
        except ImportError:
            return True

        plurr = Plurr()

        try:
            plurr.format(str2, {}, {
                'locale': kwargs['language_code'],
                'strict': False,
                'callback': lambda x: '',
            })
        except SyntaxError as e:
            raise checks.FilterFailure(e.message)

        return True
Example #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.path.append("..")

import time

from plurr import Plurr

p = Plurr()
s = 'Do you want to delete {N_PLURAL:this {N} file|these {N} files} permanently?'
params = {
    'N': 5
}
x = 100000

start = time.clock()

for i in xrange(x):
    dummy = p.format(s, params)

end = time.clock()
time = end - start
print('Execution time ({0} calls): {1} sec ({2} ms per call)'.format(
    x, time, time * 1000 / x))
Example #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.path.append("..")

import time

from plurr import Plurr


p = Plurr()
s = 'Do you want to delete {N_PLURAL:this {N} file|these {N} files} permanently?';
params = {'N': 5};
x = 100000

start = time.clock()

for i in xrange(x):
    dummy = p.format(s, params)

end = time.clock()
time = end - start
print('Execution time ({0} calls): {1} sec ({2} ms per call)'.format(x, time, time * 1000 / x))