Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 4e2ec9b8 authored by Alexandre Flament's avatar Alexandre Flament Committed by GitHub
Browse files

Merge pull request #247 from dalf/remote_settings_locales

settings.yml: remove locales section.
parents 34ffd081 0d20e5df
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
.. _searx.locales:

=======
Locales
=======

.. automodule:: searx.locales
  :members:

searx/locales.py

0 → 100644
+75 −0
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
"""Initialize :py:obj:`LOCALE_NAMES`, :py:obj:`UI_LOCALE_CODES` and
:py:obj:`RTL_LOCALES`."""

from typing import List, Set
import os
import pathlib

from babel import Locale

LOCALE_NAMES = {
    "oc": "Occitan",
    "nl_BE": "Vlaams (Dutch, Belgium)",
}
"""Mapping of locales and their description.  Locales e.g. 'fr' or 'pt_BR'
(delimiter is *underline* '_')"""

UI_LOCALE_CODES: List[str] = []
"""List of locales e.g. 'fr' or 'pt-BR' (delimiter is '-')"""

RTL_LOCALES: Set[str] = set()
"""List of *Right-To-Left* locales e.g. 'he' or 'fa_IR' (delimiter is
*underline* '_')"""


def _get_name(locale, language_code):
    language_name = locale.get_language_name(language_code).capitalize()
    if language_name and ('a' <= language_name[0] <= 'z'):
        language_name = language_name.capitalize()
    terrirtory_name = locale.get_territory_name(language_code)
    return language_name, terrirtory_name


def _get_locale_name(locale, locale_name):
    """Get locale name e.g. 'Français - fr' or 'Português (Brasil) - pt-BR'

    :param locale: instance of :py:class:`Locale`
    :param locale_name: name e.g. 'fr'  or 'pt_BR'
    """
    native_language, native_territory = _get_name(locale, locale_name)
    english_language, english_territory = _get_name(locale, 'en')
    if native_territory == english_territory:
        english_territory = None
    if not native_territory and not english_territory:
        if native_language == english_language:
            return native_language
        return native_language + ' (' + english_language + ')'
    result = native_language + ', ' + native_territory + ' (' + english_language
    if english_territory:
        return result + ', ' + english_territory + ')'
    return result + ')'


def initialize_locales(directory):
    """Initialize global names :py:obj:`LOCALE_NAMES`, :py:obj:`UI_LOCALE_CODES` and
    :py:obj:`RTL_LOCALES`.
    """
    global LOCALE_NAMES, UI_LOCALE_CODES, RTL_LOCALES  # pylint: disable=global-statement
    for dirname in sorted(os.listdir(directory)):
        # Based on https://flask-babel.tkte.ch/_modules/flask_babel.html#Babel.list_translations
        if not os.path.isdir( os.path.join(directory, dirname, 'LC_MESSAGES') ):
            continue
        info = LOCALE_NAMES.get(dirname)
        if not info:
            locale = Locale.parse(dirname)
            LOCALE_NAMES[dirname] = _get_locale_name(locale, dirname)
            if locale.text_direction == 'rtl':
                RTL_LOCALES.add(dirname)

    UI_LOCALE_CODES = [l.replace('_', '-') for l in LOCALE_NAMES]


initialize_locales(pathlib.Path(__file__).parent / 'translations')
+2 −1
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ from urllib.parse import parse_qs, urlencode

from searx import settings, autocomplete
from searx.languages import language_codes as languages
from searx.locales import LOCALE_NAMES
from searx.webutils import VALID_LANGUAGE_CODE


@@ -340,7 +341,7 @@ class Preferences:
            'locale': EnumStringSetting(
                settings['ui']['default_locale'],
                is_locked('locale'),
                choices=list(settings['locales'].keys()) + ['']
                choices=list(LOCALE_NAMES.keys()) + ['']
            ),
            'autocomplete': EnumStringSetting(
                settings['search']['autocomplete'],
+0 −47
Original line number Diff line number Diff line
@@ -1651,53 +1651,6 @@ engines:
#        chars: ' '
#        keys: ['line']

locales:
  en: English
  ar: العَرَبِيَّة (Arabic)
  bg: Български (Bulgarian)
  bo: བོད་སྐད་ (Tibetian)
  ca: Català (Catalan)
  cs: Čeština (Czech)
  cy: Cymraeg (Welsh)
  da: Dansk (Danish)
  de: Deutsch (German)
  el_GR: Ελληνικά (Greek_Greece)
  eo: Esperanto (Esperanto)
  es: Español (Spanish)
  et: Eesti (Estonian)
  eu: Euskara (Basque)
  fa_IR: (fārsī) فارسى (Persian)
  fi: Suomi (Finnish)
  fil: Wikang Filipino (Filipino)
  fr: Français (French)
  gl: Galego (Galician)
  he: עברית (Hebrew)
  hr: Hrvatski (Croatian)
  hu: Magyar (Hungarian)
  ia: Interlingua (Interlingua)
  it: Italiano (Italian)
  ja: 日本語 (Japanese)
  lt: Lietuvių (Lithuanian)
  nl: Nederlands (Dutch)
  nl_BE: Vlaams (Dutch_Belgium)
  oc: Lenga D'òc (Occitan)
  pl: Polski (Polish)
  pt: Português (Portuguese)
  pt_BR: Português (Portuguese_Brazil)
  ro: Română (Romanian)
  ru: Русский (Russian)
  sk: Slovenčina (Slovak)
  sl: Slovenski (Slovene)
  sr: српски (Serbian)
  sv: Svenska (Swedish)
  te: తెలుగు (telugu)
  ta: தமிழ் (Tamil)
  tr: Türkçe (Turkish)
  uk: українська мова (Ukrainian)
  vi: tiếng việt (Vietnamese)
  zh: 中文 (Chinese)
  zh_TW: 國語 (Taiwanese Mandarin)

doi_resolvers:
  oadoi.org: 'https://oadoi.org/'
  doi.org: 'https://doi.org/'
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ class SearxRobotLayer():
def run_robot_tests(tests):
    print('Running {0} tests'.format(len(tests)))
    for test in tests:
        with Browser('firefox', headless=True) as browser:
        with Browser('firefox', headless=True, profile_preferences={'intl.accept_languages': 'en'}) as browser:
            test(browser)


Loading