diff options
author | Bryan Newbold <bnewbold@archive.org> | 2020-05-21 17:54:59 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2020-05-21 17:55:21 -0700 |
commit | 3ba3839ecd7924dc2f25295754d7a257c2542b23 (patch) | |
tree | d7246c44d8cf192da65eb9a14a2006bbed66feee /fatcat_scholar/search.py | |
parent | d12d03bd241d93ffc624747f9f60fdf7fbe18f14 (diff) | |
download | fatcat-scholar-3ba3839ecd7924dc2f25295754d7a257c2542b23.tar.gz fatcat-scholar-3ba3839ecd7924dc2f25295754d7a257c2542b23.zip |
better translation marking; add some basic de and zh
Current translations are just from Google Translate
Diffstat (limited to 'fatcat_scholar/search.py')
-rw-r--r-- | fatcat_scholar/search.py | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py index 080266a..6842e65 100644 --- a/fatcat_scholar/search.py +++ b/fatcat_scholar/search.py @@ -5,6 +5,7 @@ Helpers to make elasticsearch queries. import sys import json +from gettext import gettext import datetime import elasticsearch from pydantic import BaseModel @@ -13,6 +14,8 @@ from dataclasses import dataclass from elasticsearch_dsl import Search, Q from typing import List, Dict, Tuple, Optional, Any, Sequence +# i18n note: the use of gettext below doesn't actually do the translation here, +# it just ensures that the strings are caught by babel for translation later class FulltextQuery(BaseModel): q: Optional[str] = None @@ -23,49 +26,50 @@ class FulltextQuery(BaseModel): filter_availability: Optional[str] = None sort_order: Optional[str] = None time_options: Any = { - "label": "Release Date", + "label": gettext("Release Date"), "slug": "filter_time", "default": "all_time", "list": [ - {"label": "All Time", "slug": "all_time"}, - {"label": "Past Week", "slug": "past_week"}, - {"label": "Past Year", "slug": "past_year"}, - {"label": "Since 2000", "slug": "since_2000"}, - {"label": "Before 1925", "slug": "before_1925"}, + {"label": gettext("All Time"), "slug": "all_time"}, + {"label": gettext("Past Week"), "slug": "past_week"}, + {"label": gettext("Past Year"), "slug": "past_year"}, + {"label": gettext("Since 2000"), "slug": "since_2000"}, + {"label": gettext("Before 1925"), "slug": "before_1925"}, ], } type_options: Any = { - "label": "Resource Type", + "label": gettext("Resource Type"), "slug": "filter_type", "default": "papers", "list": [ - {"label": "Papers", "slug": "papers"}, - {"label": "Reports", "slug": "reports"}, - {"label": "Datasets", "slug": "datasets"}, - {"label": "Everything", "slug": "everything"}, + {"label": gettext("Papers"), "slug": "papers"}, + {"label": gettext("Reports"), "slug": "reports"}, + {"label": gettext("Datasets"), "slug": "datasets"}, + {"label": gettext("Everything"), "slug": "everything"}, ], } availability_options: Any = { - "label": "Availability", + "label": gettext("Availability"), "slug": "filter_availability", "default": "everything", "list": [ - {"label": "Everything", "slug": "everything"}, - {"label": "Fulltext", "slug": "fulltext"}, - {"label": "Open Access", "slug": "oa"}, + {"label": gettext("Everything"), "slug": "everything"}, + {"label": gettext("Fulltext"), "slug": "fulltext"}, + {"label": gettext("Open Access"), "slug": "oa"}, ], } sort_options: Any = { - "label": "Sort Order", + "label": gettext("Sort Order"), "slug": "sort_order", "default": "relevancy", "list": [ - {"label": "All Time", "slug": "relevancy"}, - {"label": "Recent First", "slug": "time_desc"}, - {"label": "Oldest First", "slug": "time_asc"}, + {"label": gettext("All Time"), "slug": "relevancy"}, + {"label": gettext("Recent First"), "slug": "time_desc"}, + {"label": gettext("Oldest First"), "slug": "time_asc"}, ], } + class FulltextHits(BaseModel): count_returned: int count_found: int |