def get_translation(strings, lang=None): """Return the translation of all the given strings for the current locale.""" if lang is not None: gramps_locale = GrampsLocale(lang=lang) else: gramps_locale = GRAMPS_LOCALE return {s: gramps_locale.translation.sgettext(s) for s in strings}
def get(self, args: Union[Dict, None] = None) -> Response: """Get available translations.""" default_locale = GrampsLocale(lang="en") current_locale = get_locale_for_language(args["locale"], default=True) catalog = default_locale.get_language_dict() translations = [] for entry in catalog: native_locale = GrampsLocale(lang=catalog[entry]) translations.append({ "default": entry, "current": current_locale.translation.sgettext(entry), "language": catalog[entry], "native": native_locale.translation.sgettext(entry), }) sort = Sort(default_locale=default_locale, current_locale=current_locale) lookup = { "current": sort.get_current_key, "default": sort.get_default_key, "language": sort.get_language_key, "native": sort.get_native_key, } if "sort" not in args: args["sort"] = ["language"] for sort_key in args["sort"]: sort_key = sort_key.strip() reverse = False if sort_key[:1] == "-": reverse = True sort_key = sort_key[1:] if sort_key not in lookup: abort(422) translations.sort(key=lambda x: lookup[sort_key](x), reverse=reverse) return self.response(200, translations)
def get_locale_for_language(language: str, default: bool = False) -> GrampsLocale: """Get GrampsLocale set to specified language.""" if language is not None: catalog = GRAMPS_LOCALE.get_language_dict() for entry in catalog: if catalog[entry] == language: return GrampsLocale(lang=language) if default: return GRAMPS_LOCALE return None
def get(self, args: Dict, code: str) -> Response: """Get translation.""" try: strings = json.loads(args["strings"]) except json.JSONDecodeError: abort(400) gramps_locale = GrampsLocale(lang=code) return self.response( 200, [{ "original": s, "translation": gramps_locale.translation.sgettext(s) } for s in strings], )
def set_locale(self, language): """ Set the translator to one selected with stdoptions.add_localization_option(). """ if language == GrampsLocale.DEFAULT_TRANSLATION_STR: language = None locale = GrampsLocale(lang=language) self._ = locale.translation.gettext self._get_date = locale.get_date self._get_type = locale.get_type self._ldd = locale.date_displayer self._name_display = NameDisplay(locale) # a legacy/historical name self._name_display.set_name_format(self.database.name_formats) fmt_default = config.get('preferences.name-format') self._name_display.set_default_format(fmt_default) return locale
def get(self, args: Dict, language: str) -> Response: """Get translation.""" try: strings = json.loads(args["strings"]) except json.JSONDecodeError: abort(400) catalog = GRAMPS_LOCALE.get_language_dict() for entry in catalog: if catalog[entry] == language: gramps_locale = GrampsLocale(lang=language) return self.response( 200, [{ "original": s, "translation": gramps_locale.translation.sgettext(s), } for s in strings], ) abort(404)
def register_datehandler(locales,parse_class,display_class): """ Registers the passed date parser class and date displayer classes with the specified language locales. Set the parser_class and display_class ._locale attribute to the corresponding :class:`.GrampsLocale` object. :param locales: tuple of strings containing language codes. The character encoding is not included, so the language should be in the form of fr_FR, not fr_FR.utf8 :type locales: tuple :param parse_class: Class to be associated with parsing :type parse_class: :class:`.DateParser` :param display_class: Class to be associated with displaying :type display_class: :class:`.DateDisplay` """ for lang_str in locales: LANG_TO_PARSER[lang_str] = parse_class LANG_TO_DISPLAY[lang_str] = display_class parse_class._locale = display_class._locale = GrampsLocale(lang=locales[0])
TIP_DATA = os.path.join(DATA_DIR, "tips.xml") PAPERSIZE = os.path.join(DATA_DIR, "papersize.xml") ICON = os.path.join(IMAGE_DIR, "gramps.png") LOGO = os.path.join(IMAGE_DIR, "logo.png") SPLASH = os.path.join(IMAGE_DIR, "splash.jpg") LICENSE_FILE = os.path.join(_resources.doc_dir, 'COPYING') #------------------------------------------------------------------------- # # Init Localization # #------------------------------------------------------------------------- from gramps.gen.utils.grampslocale import GrampsLocale GRAMPS_LOCALE = GrampsLocale(localedir=_resources.locale_dir) _ = GRAMPS_LOCALE.translation.sgettext GTK_GETTEXT_DOMAIN = 'gtk30' #------------------------------------------------------------------------- # # About box information # #------------------------------------------------------------------------- COPYRIGHT_MSG = "© 2001-2006 Donald N. Allingham\n" \ "© 2007-2015 The Gramps Developers" COMMENTS = _("Gramps\n (Genealogical Research and Analysis " "Management Programming System)\n" "is a personal genealogy program.") AUTHORS = [ "Alexander Roitman", "Benny Malengier", "Brian Matherly",
from gramps.gen.utils.grampslocale import GrampsLocale from webargs import fields, validate from ...types import Handle from ..util import get_db_handle, get_locale_for_language, use_args from . import ProtectedResource from .emit import GrampsJSONEncoder from .filters import apply_filter from .util import ( get_person_profile_for_object, get_place_profile_for_object, get_rating, ) pd = PlaceDisplay() default_locale = GrampsLocale(lang="en") event_type = EventType() DEATH_INDICATORS = [ event_type.DEATH, event_type.BURIAL, event_type.CREMATION, event_type.CAUSE_DEATH, event_type.PROBATE, ] RELATIVES = [ "father", "mother", "brother", "sister",
def get_native_key(self, data): """Return sort key for native locale.""" native_locale = GrampsLocale(lang=data["language"]) return native_locale.sort_key(data["native"])
def set_language(self, language): if language == GrampsLocale.DEFAULT_TRANSLATION_STR: language = None locale = GrampsLocale(lang=language) self._ = locale.translation.gettext