Beispiel #1
0
def test_unique_ids():
    # Check all locale IDs are uniques.
    all_ids = localedata.locale_identifiers()
    assert len(all_ids) == len(set(all_ids))
    # Check locale IDs don't collide after lower-case normalization.
    lower_case_ids = list(map(methodcaller('lower'), all_ids))
    assert len(lower_case_ids) == len(set(lower_case_ids))
Beispiel #2
0
def get_available_languages(domain):
    """Lists the available languages for the given translation domain.

    :param domain: the domain to get languages for
    """
    if domain in _AVAILABLE_LANGUAGES:
        return copy.copy(_AVAILABLE_LANGUAGES[domain])

    localedir = os.environ.get(_locale.get_locale_dir_variable_name(domain))
    find = lambda x: gettext.find(domain, localedir=localedir, languages=[x])

    # NOTE(mrodden): en_US should always be available (and first in case
    # order matters) since our in-line message strings are en_US
    language_list = ['en_US']
    locale_identifiers = localedata.locale_identifiers()
    language_list.extend(language for language in locale_identifiers
                         if find(language))

    # In Babel 1.3, locale_identifiers() doesn't list some OpenStack supported
    # locales (e.g. 'zh_CN', and 'zh_TW') so we add the locales explicitly if
    # necessary so that they are listed as supported.
    aliases = {
        'zh': 'zh_CN',
        'zh_Hant_HK': 'zh_HK',
        'zh_Hant': 'zh_TW',
        'fil': 'tl_PH'
    }

    language_list.extend(
        alias for locale, alias in six.iteritems(aliases)
        if (locale in language_list and alias not in language_list))

    _AVAILABLE_LANGUAGES[domain] = language_list
    return copy.copy(language_list)
def test_unique_ids():
    # Check all locale IDs are uniques.
    all_ids = localedata.locale_identifiers()
    assert len(all_ids) == len(set(all_ids))
    # Check locale IDs don't collide after lower-case normalization.
    lower_case_ids = list(map(methodcaller('lower'), all_ids))
    assert len(lower_case_ids) == len(set(lower_case_ids))
Beispiel #4
0
def pytest_generate_tests(metafunc):
    if hasattr(metafunc.function, "pytestmark"):
        for mark in metafunc.function.pytestmark:
            if mark.name == "all_locales":
                from babel.localedata import locale_identifiers
                metafunc.parametrize("locale", list(locale_identifiers()))
                break
Beispiel #5
0
    def run():
        identifiers = localedata.locale_identifiers()
        padding = len(max(identifiers, key=len))

        for identifier in sorted(identifiers):
            print(identifier.ljust(padding),
                  Locale.parse(identifier).english_name)
Beispiel #6
0
def get_available_languages(domain):
    """Lists the available languages for the given translation domain.

    :param domain: the domain to get languages for
    """
    if domain in _AVAILABLE_LANGUAGES:
        return copy.copy(_AVAILABLE_LANGUAGES[domain])

    localedir = os.environ.get(_locale.get_locale_dir_variable_name(domain))
    find = lambda x: gettext.find(domain,
                                  localedir=localedir,
                                  languages=[x])

    # NOTE(mrodden): en_US should always be available (and first in case
    # order matters) since our in-line message strings are en_US
    language_list = ['en_US']
    locale_identifiers = localedata.locale_identifiers()
    language_list.extend(language for language in locale_identifiers
                         if find(language))

    # In Babel 1.3, locale_identifiers() doesn't list some OpenStack supported
    # locales (e.g. 'zh_CN', and 'zh_TW') so we add the locales explicitly if
    # necessary so that they are listed as supported.
    aliases = {'zh': 'zh_CN',
               'zh_Hant_HK': 'zh_HK',
               'zh_Hant': 'zh_TW',
               'fil': 'tl_PH'}

    language_list.extend(alias for locale, alias in six.iteritems(aliases)
                         if (locale in language_list and
                             alias not in language_list))

    _AVAILABLE_LANGUAGES[domain] = language_list
    return copy.copy(language_list)
Beispiel #7
0
    def run(self, argv=None):
        """Main entry point of the command-line interface.

        :param argv: list of arguments passed on the command-line
        """

        if argv is None:
            argv = sys.argv

        self.parser = optparse.OptionParser(usage=self.usage %
                                            ('command', '[args]'),
                                            version=self.version)
        self.parser.disable_interspersed_args()
        self.parser.print_help = self._help
        self.parser.add_option('--list-locales',
                               dest='list_locales',
                               action='store_true',
                               help="print all known locales and exit")
        self.parser.add_option('-v',
                               '--verbose',
                               action='store_const',
                               dest='loglevel',
                               const=logging.DEBUG,
                               help='print as much as possible')
        self.parser.add_option('-q',
                               '--quiet',
                               action='store_const',
                               dest='loglevel',
                               const=logging.ERROR,
                               help='print as little as possible')
        self.parser.set_defaults(list_locales=False, loglevel=logging.INFO)

        options, args = self.parser.parse_args(argv[1:])

        self._configure_logging(options.loglevel)
        if options.list_locales:
            identifiers = localedata.locale_identifiers()
            longest = max([len(identifier) for identifier in identifiers])
            identifiers.sort()
            format = u'%%-%ds %%s' % (longest + 1)
            for identifier in identifiers:
                locale = Locale.parse(identifier)
                output = format % (identifier, locale.english_name)
                print(
                    output.encode(
                        sys.stdout.encoding or getpreferredencoding()
                        or 'ascii', 'replace'))
            return 0

        if not args:
            self.parser.error('no valid command or option passed. '
                              'Try the -h/--help option for more information.')

        cmdname = args[0]
        if cmdname not in self.commands:
            self.parser.error('unknown command "%s"' % cmdname)

        cmdinst = self._configure_command(cmdname, args[1:])
        return cmdinst.run()
Beispiel #8
0
def test_format_currency_quantization():
    # Test all locales.
    for locale_code in localedata.locale_identifiers():
        assert numbers.format_currency(
            '0.9999999999',
            'USD',
            locale=locale_code,
            decimal_quantization=False).find('9999999999') > -1
Beispiel #9
0
 def test_activate_unavailable_locale(self):
     unavailables = sorted(set(locale_identifiers()) -
                           set(translation.get_available_locales())) or \
                    ('en_US',)
     locale_dir = self._get_locale_dir()
     translation.add_domain('catalog1', self.env.path, locale_dir)
     translation.add_domain('catalog2', self.env.path, locale_dir)
     translation.activate(unavailables[0], self.env.path)
Beispiel #10
0
def set_available_locales():
    """Set available locales for which we have translations"""
    global AVAILABLE_LOCALES
    locales=['en', 'en_US'] # these are available without translations
    for locale in localedata.locale_identifiers():
        if gettext.find('mediagoblin', TRANSLATIONS_PATH, [locale]):
            locales.append(locale)
    AVAILABLE_LOCALES = locales
Beispiel #11
0
def set_available_locales():
    """Set available locales for which we have translations"""
    global AVAILABLE_LOCALES
    locales=['en', 'en_US'] # these are available without translations
    for locale in localedata.locale_identifiers():
        if gettext.find('mediagoblin', TRANSLATIONS_PATH, [locale]):
            locales.append(locale)
    AVAILABLE_LOCALES = locales
Beispiel #12
0
 def test_activate_unavailable_locale(self):
     unavailables = sorted(set(locale_identifiers()) -
                           set(translation.get_available_locales())) or \
                    ('en_US',)
     locale_dir = self._get_locale_dir()
     translation.add_domain('catalog1', self.env.path, locale_dir)
     translation.add_domain('catalog2', self.env.path, locale_dir)
     translation.activate(unavailables[0], self.env.path)
    def __init__(self, queryIndexer):
        '''
        Construct the query criteria service.
        '''
        assert isinstance(queryIndexer, QueryIndexer), 'Invalid QueryIndexer %s' % queryIndexer

        self.queryIndexer = queryIndexer
        self._locales = {code:Locale.parse(code) for code in locale_identifiers()}
Beispiel #14
0
def _fetch_supported_languages(resp):
    # startpage's language selector is a mess
    # each option has a displayed name and a value, either of which may represent the language name
    # in the native script, the language name in English, an English transliteration of the native name,
    # the English name of the writing script used by the language, or occasionally something else entirely.

    # this cases are so special they need to be hardcoded, a couple of them are mispellings
    language_names = {
        'english_uk': 'en-GB',
        'fantizhengwen': ['zh-TW', 'zh-HK'],
        'hangul': 'ko',
        'malayam': 'ml',
        'norsk': 'nb',
        'sinhalese': 'si',
        'sudanese': 'su'
    }

    # get the English name of every language known by babel
    language_names.update({
        name.lower(): lang_code
        for lang_code, name in Locale('en')._data['languages'].items()
    })

    # get the native name of every language known by babel
    for lang_code in filter(lambda lang_code: lang_code.find('_') == -1,
                            locale_identifiers()):
        native_name = Locale(lang_code).get_language_name().lower()
        # add native name exactly as it is
        language_names[native_name] = lang_code

        # add "normalized" language name (i.e. français becomes francais and español becomes espanol)
        unaccented_name = ''.join(
            filter(lambda c: not combining(c), normalize('NFKD', native_name)))
        if len(unaccented_name) == len(unaccented_name.encode()):
            # add only if result is ascii (otherwise "normalization" didn't work)
            language_names[unaccented_name] = lang_code

    dom = html.fromstring(resp.text)
    sp_lang_names = []
    for option in dom.xpath(
            '//form[@id="settings-form"]//select[@name="language"]/option'):
        sp_lang_names.append(
            (option.get('value'), extract_text(option).lower()))

    supported_languages = {}
    for sp_option_value, sp_option_text in sp_lang_names:
        lang_code = language_names.get(sp_option_value) or language_names.get(
            sp_option_text)
        if isinstance(lang_code, str):
            supported_languages[lang_code] = {'alias': sp_option_value}
        elif isinstance(lang_code, list):
            for lc in lang_code:
                supported_languages[lc] = {'alias': sp_option_value}
        else:
            print('Unknown language option in Startpage: {} ({})'.format(
                sp_option_value, sp_option_text))

    return supported_languages
Beispiel #15
0
 def __init__(self):
     '''
     Construct the language service.
     '''
     EntityNQServiceAlchemy.__init__(self, LanguageEntity)
     locales = [(code, Locale.parse(code)) for code in locale_identifiers()]
     locales.sort(key=lambda pack: pack[0])
     self._locales = OrderedDict(locales)
     validateProperty(LanguageEntity.Code, self._validateCode)
Beispiel #16
0
 def __init__(self):
     '''
     Construct the language service.
     '''
     EntityNQServiceAlchemy.__init__(self, LanguageEntity)
     locales = [(code, Locale.parse(code)) for code in locale_identifiers()]
     locales.sort(key=lambda pack: pack[0])
     self._locales = OrderedDict(locales)
     validateProperty(LanguageEntity.Code, self._validateCode)
Beispiel #17
0
 def get_locale_list(self):
     django_locales = set([i[0].replace('_', '-').lower()
                          for i in settings.LANGUAGES])
     babel_locales = set([j.replace('_', '-').lower()
                         for j in locale_identifiers()])
     sphinx_locales = set([k.replace('_', '-').lower()
                          for k in chm_locales.keys()])
     locales = [str(Locale.parse(identifier=l, sep='-'))
                for l in django_locales & babel_locales & sphinx_locales]
     return filter(None, locales)
Beispiel #18
0
 def __init__(self):
     '''
     Construct the country service.
     '''
     assert isinstance(self.countries,
                       Countries), 'Invalid countries %s' % self.countries
     self._locales = {
         code: Locale.parse(code)
         for code in locale_identifiers()
     }
Beispiel #19
0
    def run(self, argv=None):
        """Main entry point of the command-line interface.

        :param argv: list of arguments passed on the command-line
        """

        if argv is None:
            argv = sys.argv

        self.parser = optparse.OptionParser(usage=self.usage % ("command", "[args]"), version=self.version)
        self.parser.disable_interspersed_args()
        self.parser.print_help = self._help
        self.parser.add_option(
            "--list-locales", dest="list_locales", action="store_true", help="print all known locales and exit"
        )
        self.parser.add_option(
            "-v",
            "--verbose",
            action="store_const",
            dest="loglevel",
            const=logging.DEBUG,
            help="print as much as possible",
        )
        self.parser.add_option(
            "-q",
            "--quiet",
            action="store_const",
            dest="loglevel",
            const=logging.ERROR,
            help="print as little as possible",
        )
        self.parser.set_defaults(list_locales=False, loglevel=logging.INFO)

        options, args = self.parser.parse_args(argv[1:])

        self._configure_logging(options.loglevel)
        if options.list_locales:
            identifiers = localedata.locale_identifiers()
            longest = max([len(identifier) for identifier in identifiers])
            identifiers.sort()
            format = u"%%-%ds %%s" % (longest + 1)
            for identifier in identifiers:
                locale = Locale.parse(identifier)
                output = format % (identifier, locale.english_name)
                print(output.encode(sys.stdout.encoding or getpreferredencoding() or "ascii", "replace"))
            return 0

        if not args:
            self.parser.error("no valid command or option passed. " "Try the -h/--help option for more information.")

        cmdname = args[0]
        if cmdname not in self.commands:
            self.parser.error('unknown command "%s"' % cmdname)

        return self._dispatch(cmdname, args[1:])
 def __init__(self):
     '''
     Construct the query criteria service.
     '''
     assert isinstance(
         self.queryIndexer,
         IQueryIndexer), 'Invalid IQueryIndexer %s' % self.queryIndexer
     self._locales = {
         code: Locale.parse(code)
         for code in locale_identifiers()
     }
Beispiel #21
0
 def parse_lang(self, s):
     try:
         locale = Locale.parse(s)
     except UnknownLocaleError:
         pattern = re.compile(r'\b%s\b' % re.escape(s), re.I)
         for locale_id in locale_identifiers():
             locale = Locale.parse(locale_id)
             if pattern.search(locale.english_name):
                 return locale.language
         return s
     else:
         return locale.language
Beispiel #22
0
    def search_currency_symbol(symbol_or_sign):
        """Search currency name by currency sign

        Returns:
            str -- currency 3 letters code
        """
        for name in locale_identifiers():
            locale_setlocale(locale_LC_ALL, name)
            d = locale_localeconv()
            if d['currency_symbol'].lower() == symbol_or_sign.lower():
                return d['int_curr_symbol']
        return None
Beispiel #23
0
def test_locale_identifiers_cache(monkeypatch):
    original_listdir = localedata.os.listdir
    listdir_calls = []
    def listdir_spy(*args):
        rv = original_listdir(*args)
        listdir_calls.append((args, rv))
        return rv
    monkeypatch.setattr(localedata.os, 'listdir', listdir_spy)

    # In case we've already run some tests...
    if hasattr(localedata.locale_identifiers, 'cache'):
        del localedata.locale_identifiers.cache

    assert not listdir_calls
    assert localedata.locale_identifiers()
    assert len(listdir_calls) == 1
    assert localedata.locale_identifiers() is localedata.locale_identifiers.cache
    assert len(listdir_calls) == 1
    localedata.locale_identifiers.cache = None
    assert localedata.locale_identifiers()
    assert len(listdir_calls) == 2
Beispiel #24
0
    def run(self, argv=None):
        """Main entry point of the command-line interface.

        :param argv: list of arguments passed on the command-line
        """

        if argv is None:
            argv = sys.argv

        self.parser = optparse.OptionParser(usage=self.usage % ('command', '[args]'),
                                            version=self.version)
        self.parser.disable_interspersed_args()
        self.parser.print_help = self._help
        self.parser.add_option('--list-locales', dest='list_locales',
                               action='store_true',
                               help="print all known locales and exit")
        self.parser.add_option('-v', '--verbose', action='store_const',
                               dest='loglevel', const=logging.DEBUG,
                               help='print as much as possible')
        self.parser.add_option('-q', '--quiet', action='store_const',
                               dest='loglevel', const=logging.ERROR,
                               help='print as little as possible')
        self.parser.set_defaults(list_locales=False, loglevel=logging.INFO)

        options, args = self.parser.parse_args(argv[1:])

        self._configure_logging(options.loglevel)
        if options.list_locales:
            identifiers = localedata.locale_identifiers()
            longest = max([len(identifier) for identifier in identifiers])
            identifiers.sort()
            format = u'%%-%ds %%s' % (longest + 1)
            for identifier in identifiers:
                locale = Locale.parse(identifier)
                output = format % (identifier, locale.english_name)
                print(output.encode(sys.stdout.encoding or
                                    getpreferredencoding() or
                                    'ascii', 'replace'))
            return 0

        if not args:
            self.parser.error('no valid command or option passed. '
                              'Try the -h/--help option for more information.')

        cmdname = args[0]
        if cmdname not in self.commands:
            self.parser.error('unknown command "%s"' % cmdname)

        cmdinst = self._configure_command(cmdname, args[1:])
        return cmdinst.run()
Beispiel #25
0
def test_locale_identifiers_cache(monkeypatch):
    original_listdir = localedata.os.listdir
    listdir_calls = []

    def listdir_spy(*args):
        rv = original_listdir(*args)
        listdir_calls.append((args, rv))
        return rv

    monkeypatch.setattr(localedata.os, 'listdir', listdir_spy)

    # In case we've already run some tests...
    if hasattr(localedata.locale_identifiers, 'cache'):
        del localedata.locale_identifiers.cache

    assert not listdir_calls
    assert localedata.locale_identifiers()
    assert len(listdir_calls) == 1
    assert localedata.locale_identifiers(
    ) is localedata.locale_identifiers.cache
    assert len(listdir_calls) == 1
    localedata.locale_identifiers.cache = None
    assert localedata.locale_identifiers()
    assert len(listdir_calls) == 2
Beispiel #26
0
def get_available_languages(domain):
    """Lists the available languages for the given translation domain.

    :param domain: the domain to get languages for
    """
    if domain in _AVAILABLE_LANGUAGES:
        return copy.copy(_AVAILABLE_LANGUAGES[domain])

    localedir = os.environ.get(_locale.get_locale_dir_variable_name(domain))
    find = lambda x: gettext.find(domain,
                                  localedir=localedir,
                                  languages=[x])

    # NOTE(mrodden): en_US should always be available (and first in case
    # order matters) since our in-line message strings are en_US
    language_list = ['en_US']
    locale_identifiers = localedata.locale_identifiers()
    language_list.extend(language for language in locale_identifiers
                         if find(language))

    # In Babel 1.3, locale_identifiers() doesn't list some OpenStack supported
    # locales (e.g. 'zh_CN', and 'zh_TW') so we add the locales explicitly if
    # necessary so that they are listed as supported.
    aliases = {'zh': 'zh_CN',
               'zh_Hant_HK': 'zh_HK',
               'zh_Hant': 'zh_TW',
               'fil': 'tl_PH'}
    language_list.extend(alias for locale, alias in aliases.items()
                         if (locale in language_list and
                             alias not in language_list))

    language_list.extend(alias for locale, alias in aliases.items()
                         if (locale not in language_list and
                             find(alias)))

    # In webob.acceptparse, the best_match is just match the first element in
    # the language_list, so make the precise element in front
    result = ['en_US']
    for i in language_list[1:]:
        if '_' in i:
            result.insert(1, i)
        else:
            result.append(i)

    _AVAILABLE_LANGUAGES[domain] = result
    return copy.copy(result)
Beispiel #27
0
def get_available_languages(domain):
    """Lists the available languages for the given translation domain.

    :param domain: the domain to get languages for
    """
    if domain in _AVAILABLE_LANGUAGES:
        return copy.copy(_AVAILABLE_LANGUAGES[domain])

    localedir = os.environ.get(_locale.get_locale_dir_variable_name(domain))
    find = lambda x: gettext.find(domain, localedir=localedir, languages=[x])

    # NOTE(mrodden): en_US should always be available (and first in case
    # order matters) since our in-line message strings are en_US
    language_list = ['en_US']
    locale_identifiers = localedata.locale_identifiers()
    language_list.extend(language for language in locale_identifiers
                         if find(language))

    # In Babel 1.3, locale_identifiers() doesn't list some OpenStack supported
    # locales (e.g. 'zh_CN', and 'zh_TW') so we add the locales explicitly if
    # necessary so that they are listed as supported.
    aliases = {
        'zh': 'zh_CN',
        'zh_Hant_HK': 'zh_HK',
        'zh_Hant': 'zh_TW',
        'fil': 'tl_PH'
    }
    language_list.extend(
        alias for locale, alias in aliases.items()
        if (locale in language_list and alias not in language_list))

    language_list.extend(alias for locale, alias in aliases.items()
                         if (locale not in language_list and find(alias)))

    # In webob.acceptparse, the best_match is just match the first element in
    # the language_list, so make the precise element in front
    result = ['en_US']
    for i in language_list[1:]:
        if '_' in i:
            result.insert(1, i)
        else:
            result.append(i)

    _AVAILABLE_LANGUAGES[domain] = result
    return copy.copy(result)
Beispiel #28
0
    def __init__(self, locales_configuration: LocalesConfiguration, *args,
                 **kwargs):
        super().__init__(*args, **kwargs)
        self._locales_configuration = locales_configuration

        self._layout = QFormLayout()
        self._widget = QWidget()
        self._widget.setLayout(self._layout)
        self.setCentralWidget(self._widget)

        self._locales = OrderedDict(
            sorted({
                babel_locale.replace('_', '-'):
                Locale.parse(babel_locale).get_display_name()
                for babel_locale in locale_identifiers()
            }.items(),
                   key=lambda x: x[1]))

        self._locale = QComboBox()
        for locale, locale_name in self._locales.items():
            self._locale.addItem(locale_name, locale)
        self._layout.addRow(self._locale)

        self._alias = QLineEdit()
        self._layout.addRow('Alias', self._alias)
        self._layout.addRow(
            Caption(
                'An optional alias is used instead of the locale code to identify this locale, such as in URLs. If US English is the only English language variant on your site, you may want to alias its language code from <code>en-US</code> to <code>en</code>, for instance.'
            ))

        buttons_layout = QHBoxLayout()
        self._layout.addRow(buttons_layout)

        self._save_and_close = QPushButton('Save and close')
        self._save_and_close.released.connect(self._save_and_close_locale)
        buttons_layout.addWidget(self._save_and_close)

        self._cancel = QPushButton('Cancel')
        self._cancel.released.connect(self.close)
        buttons_layout.addWidget(self._cancel)
Beispiel #29
0
    def get_cldr_languages(self):
        """
        Helper function to extract CLDR information. Heavily relied on babel functionality
        """
        from babel import Locale, localedata, plural

        for lang in localedata.locale_identifiers():
            locale = Locale(lang)
            if not locale.english_name:
                continue

            plurals_str = plural.to_gettext(locale.plural_form)
            nplurals, pluralequation = re_plurals.match(plurals_str).groups()
            lang_aliases = set(CLDR_FALLBACK_ALIASES.get(lang, []))
            lang_aliases.add(lang)
            for alias in lang_aliases:
                yield {
                    'code': alias,
                    'fullname': locale.english_name,
                    'nplurals': int(nplurals),
                    'pluralequation': pluralequation,
                }
Beispiel #30
0
import hashlib
import io
from collections import defaultdict

from babel import Locale
from babel.localedata import locale_identifiers
from babel.numbers import format_decimal, format_number, format_percent


def md5(s: str):
    b = s.encode('utf-8')
    return hashlib.md5(b).hexdigest()


ids = [x for x in locale_identifiers() if "_" in x]
locales = sorted(ids)

mlines = {}
mids = defaultdict(list)
mlos = {}
storage = io.StringIO()

for lo in locales:
    storage.seek(0)
    storage.truncate()

    n1 = format_decimal(3.1415, locale=lo, decimal_quantization=False)
    n2 = format_number(199_000, locale=lo)
    n3 = format_percent(0.7777, locale=lo)

    print('\t', n1, file=storage)  # 12,345
Beispiel #31
0
    '_n',
    'timezoneselector',
    'VALID_LANGUAGES_CODE',
    'render_template_i18n',
]

#: gettext alias
_ = gettext

#: lazy_gettext alias
_l = lazy_gettext
#: ngettext alias
_n = ngettext

#: accepted languages codes
VALID_LANGUAGES_CODE = frozenset(lang for lang in locale_identifiers()
                                 if len(lang) == 2)


def get_default_locale():
    return current_app.extensions['babel'].default_locale


def _get_locale():
    locale = flask_babel.get_locale()
    if locale is None:
        locale = get_default_locale()
    return locale


def __gettext_territory(code):
def test_mixedcased_locale():
    for l in localedata.locale_identifiers():
        locale_id = ''.join(
            [methodcaller(random.choice(['lower', 'upper']))(c) for c in l])
        assert localedata.exists(locale_id)
Beispiel #33
0
from searx import settings
from searx import logger
from searx.utils import load_module, match_language


logger = logger.getChild('engines')

engine_dir = dirname(realpath(__file__))

engines = {}

categories = {'general': []}

languages = loads(open(engine_dir + '/../data/engines_languages.json', 'r', encoding='utf-8').read())
babel_langs = [lang_parts[0] + '-' + lang_parts[-1] if len(lang_parts) > 1 else lang_parts[0]
               for lang_parts in (lang_code.split('_') for lang_code in locale_identifiers())]

engine_shortcuts = {}
engine_default_args = {'paging': False,
                       'categories': ['general'],
                       'language_support': True,
                       'supported_languages': [],
                       'safesearch': False,
                       'timeout': settings['outgoing']['request_timeout'],
                       'shortcut': '-',
                       'disabled': False,
                       'suspend_end_time': 0,
                       'continuous_errors': 0,
                       'time_range_support': False}

def test_locale_identification():
    for l in localedata.locale_identifiers():
        assert localedata.exists(l)
Beispiel #35
0
def pytest_generate_tests(metafunc):
    if hasattr(metafunc.function, "all_locales"):
        from babel.localedata import locale_identifiers
        metafunc.parametrize("locale", list(locale_identifiers()))
Beispiel #36
0
def test_locale_identification():
    for l in localedata.locale_identifiers():
        assert localedata.exists(l)
Beispiel #37
0
  'set_locale',
  'timezoneselector',
  'VALID_LANGUAGES_CODE',
  'render_template_i18n'
]

#: gettext alias
_ = gettext

#: lazy_gettext alias
_l = lazy_gettext
#: ngettext alias
_n = ngettext

#: accepted languages codes
VALID_LANGUAGES_CODE = frozenset(lang for lang in locale_identifiers()
                                 if len(lang) == 2)

def get_default_locale():
  return current_app.extensions['babel'].default_locale


def _get_locale():
  locale = flask_babel.get_locale()
  if locale is None:
    locale = get_default_locale()
  return locale


def __gettext_territory(code):
  locale = _get_locale()
Beispiel #38
0
def test_format_scientific_quantization():
    # Test all locales.
    for locale_code in localedata.locale_identifiers():
        assert numbers.format_scientific(
            '0.9999999999', locale=locale_code, decimal_quantization=False).find('999999999') > -1
Beispiel #39
0
import sys
import os
from decimal import Decimal
from collections import defaultdict
from gettext import translation
from babel import Locale, UnknownLocaleError, localedata
from babel.numbers import parse_decimal, format_currency, format_decimal
from bottle import request
from functools import lru_cache
from os.path import join
from lib import root_directory


LOCALE_DIR = join(root_directory(), 'backend', 'locale')
DEFAULT_LANGUAGE = conf.ui.default_language
SUPPORTED_LOCALES = frozenset(localedata.locale_identifiers())
APPLICATION_NAME = "boss"


def _(message):
    return message


def acceptable_languages():
    languages = languages_set_from_headers()
    languages.intersection_update(available_languages())
    languages -= {DEFAULT_LANGUAGE}

    return list(languages) if languages else [DEFAULT_LANGUAGE]

                    default=True,
                    action='store_true',
                    help='generate source .po files')
parser.add_argument('-m',
                    '--mo',
                    action='store_true',
                    help='generate compiled .mo files')
parser.add_argument('-s',
                    '--stats',
                    default=True,
                    action='store_true',
                    help='print statistics')
parser.add_argument('locale',
                    nargs='*',
                    help='generate for selected locales only',
                    default=localedata.locale_identifiers())
args = parser.parse_args()
if not args.po and not args.mo:
    parser.error('Either -p or -m is required.')

header = '''\
# Translations template for %s
# Copyright (C) YEAR ORGANIZATION
# This file is distributed under the MIT license
#
''' % domain
C = Locale.parse('en_US_POSIX')
max_cur = len(C.currencies)
t = 0

for loc in sorted(args.locale):
Beispiel #41
0
 def __init__(self):
     '''
     Construct the country service.
     '''
     assert isinstance(self.countries, Countries), 'Invalid countries %s' % self.countries
     self._locales = {code:Locale.parse(code) for code in locale_identifiers()}
Beispiel #42
0
def test_mixedcased_locale():
    for l in localedata.locale_identifiers():
        locale_id = ''.join([
            methodcaller(random.choice(['lower', 'upper']))(c) for c in l])
        assert localedata.exists(locale_id)
Beispiel #43
0
from searx.data import ENGINES_LANGUAGES
from searx.exceptions import SearxEngineResponseException
from searx.network import get, initialize as initialize_network, set_context_network_name
from searx.utils import load_module, match_language, get_engine_from_settings, gen_useragent


logger = logger.getChild('engines')

engine_dir = dirname(realpath(__file__))

engines = {}

categories = {'general': []}

babel_langs = [lang_parts[0] + '-' + lang_parts[-1] if len(lang_parts) > 1 else lang_parts[0]
               for lang_parts in (lang_code.split('_') for lang_code in locale_identifiers())]

engine_shortcuts = {}
engine_default_args = {'paging': False,
                       'categories': ['general'],
                       'supported_languages': [],
                       'safesearch': False,
                       'timeout': settings['outgoing']['request_timeout'],
                       'shortcut': '-',
                       'disabled': False,
                       'enable_http': False,
                       'suspend_end_time': 0,
                       'continuous_errors': 0,
                       'time_range_support': False,
                       'engine_type': 'online',
                       'display_error_messages': True,
Beispiel #44
0
from searx.network import get, initialize as initialize_network, set_context_network_name
from searx.utils import load_module, match_language, get_engine_from_settings, gen_useragent

logger = logger.getChild('engines')

engine_dir = dirname(realpath(__file__))

engines = {}

categories = {'general': []}

babel_langs = [
    lang_parts[0] + '-' +
    lang_parts[-1] if len(lang_parts) > 1 else lang_parts[0]
    for lang_parts in (lang_code.split('_')
                       for lang_code in locale_identifiers())
]

engine_shortcuts = {}
engine_default_args = {
    'paging': False,
    'categories': ['general'],
    'supported_languages': [],
    'safesearch': False,
    'timeout': settings['outgoing']['request_timeout'],
    'shortcut': '-',
    'disabled': False,
    'enable_http': False,
    'time_range_support': False,
    'engine_type': 'online',
    'display_error_messages': True,
Beispiel #45
0
def test_format_decimal_quantization():
    # Test all locales.
    for locale_code in localedata.locale_identifiers():
        assert numbers.format_decimal(
            '0.9999999999', locale=locale_code, decimal_quantization=False).endswith('9999999999') is True
Beispiel #46
0
def test_format_decimal_quantization():
    # Test all locales.
    for locale_code in localedata.locale_identifiers():
        assert numbers.format_decimal(
            '0.9999999999', locale=locale_code,
            decimal_quantization=False).endswith('9999999999') is True
Beispiel #47
0
def test_format_currency_long_display_name_all():
    for locale_code in localedata.locale_identifiers():
        assert numbers.format_currency(
            1, 'USD', locale=locale_code, format_type='name').find('1') > -1
        assert numbers.format_currency(
            '1', 'USD', locale=locale_code, format_type='name').find('1') > -1
Beispiel #48
0
def test_format_currency_long_display_name_all():
    for locale_code in localedata.locale_identifiers():
        assert numbers.format_currency(
            1, 'USD', locale=locale_code, format_type='name').find('1') > -1
        assert numbers.format_currency(
            '1', 'USD', locale=locale_code, format_type='name').find('1') > -1
Beispiel #49
0
    "render_template_i18n",
    "timezoneselector",
    "VALID_LANGUAGES_CODE",
]

#: gettext alias
_ = gettext

#: lazy_gettext alias
_l = lazy_gettext
#: ngettext alias
_n = ngettext

#: accepted languages codes
VALID_LANGUAGES_CODE = frozenset(
    lang for lang in locale_identifiers() if len(lang) == 2
)


def get_default_locale():
    return current_app.extensions["babel"].default_locale


def _get_locale():
    locale = flask_babel.get_locale()
    if locale is None:
        locale = get_default_locale()
    return locale


def __gettext_territory(code):