From 3ba3839ecd7924dc2f25295754d7a257c2542b23 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 21 May 2020 17:54:59 -0700 Subject: better translation marking; add some basic de and zh Current translations are just from Google Translate --- fatcat_scholar/search.py | 42 ++--- fatcat_scholar/templates/base.html | 20 +-- fatcat_scholar/templates/home.html | 6 +- fatcat_scholar/templates/search.html | 10 +- fatcat_scholar/templates/search_macros.html | 10 +- .../translations/de/LC_MESSAGES/messages.mo | Bin 635 -> 2512 bytes .../translations/de/LC_MESSAGES/messages.po | 173 ++++++++++++++++++++- .../translations/zh/LC_MESSAGES/messages.mo | Bin 621 -> 2298 bytes .../translations/zh/LC_MESSAGES/messages.po | 165 +++++++++++++++++++- 9 files changed, 371 insertions(+), 55 deletions(-) (limited to 'fatcat_scholar') 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 diff --git a/fatcat_scholar/templates/base.html b/fatcat_scholar/templates/base.html index 9c7aba8..b530c26 100644 --- a/fatcat_scholar/templates/base.html +++ b/fatcat_scholar/templates/base.html @@ -167,7 +167,7 @@
- User Guide + {{ _("User Guide") }}
@@ -192,12 +192,14 @@

Internet Archive

-

We are a 501(c)(3) non-profit, building a digital library of Internet sites and other cultural artifacts in digital form. Other projects include the Wayback Machine, archive.org openlibrary.org and archive-it.org +

+ {% trans trimmed %}We are a 501(c)(3) non-profit, building a digital library of Internet sites and other cultural artifacts in digital form.{% endtrans %} + Other projects include The Wayback Machine, archive.org openlibrary.org and archive-it.org

@@ -210,7 +212,7 @@ Text and Data Mining Discussion Forum Statistics - Help + {{ _("Help") }}
@@ -219,8 +221,8 @@ Editable Catalog (Fatcat) Contribute Search API - Service Status - Source Code + {{ _("Service Status") }} + {{ _("Source Code") }}
diff --git a/fatcat_scholar/templates/home.html b/fatcat_scholar/templates/home.html index c6d9119..875c055 100644 --- a/fatcat_scholar/templates/home.html +++ b/fatcat_scholar/templates/home.html @@ -7,7 +7,7 @@
-

Search Inside Millions of Research Papers

+

{% trans %}Search Inside Millions of Research Papers{% endtrans %}




-

This fulltext search index includes over 25 million research articles and other documents preserved in the Internet Archive. -

The collection spans from digitized copies of eighteenth century journals though the latest Open Access conference proceedings and pre-prints crawled from the World Wide Web. +

{% trans %}This fulltext search index includes over 25 million research articles and other documents preserved in the Internet Archive.{% endtrans %} +

{% trans %}The collection spans from digitized copies of eighteenth century journals though the latest Open Access conference proceedings and pre-prints crawled from the World Wide Web.{% endtrans %}

diff --git a/fatcat_scholar/templates/search.html b/fatcat_scholar/templates/search.html index 8d9fb7d..02e169b 100644 --- a/fatcat_scholar/templates/search.html +++ b/fatcat_scholar/templates/search.html @@ -5,7 +5,7 @@
- Filters + {{ _("Filters") }}

{{ search_macros.query_option(query.time_options, query.filter_time) }} {{ search_macros.query_option(query.type_options, query.filter_type) }} @@ -55,9 +55,9 @@

{% if search_error.type == "backend" %} - Backend Search Engine Error + {% trans %}Backend Search Engine Error{% endtrans %} {% elif search_error.type == "query" %} - Query Error + {% trans %}Search Query Error{% endtrans %} {% endif %}

Computer said: {{ search_error.message }} @@ -75,7 +75,7 @@

- We didn't find any documents matching your query + {% trans %}We didn't find any documents matching your query{% endtrans %}
Try archive.org @@ -88,7 +88,7 @@
- Enter a query in the box above to get started + {% trans %}Enter a query in the box above to get started{% endtrans %}
{% endif %} diff --git a/fatcat_scholar/templates/search_macros.html b/fatcat_scholar/templates/search_macros.html index b1ccc69..ec5a73c 100644 --- a/fatcat_scholar/templates/search_macros.html +++ b/fatcat_scholar/templates/search_macros.html @@ -33,7 +33,7 @@ {% elif paper.biblio.release_type in ("book", "chapter", "dataset") %} [{{ _(paper.biblio.release_type) }}] {% elif not paper.biblio.release_type %} - [media?] + [{{ _("media?") }}] {% else %} [{{ _(paper.biblio.release_type) }}] {% endif %} @@ -89,7 +89,7 @@ {% elif paper.biblio.release_stage and paper.biblio.release_stage != "published" %} [{{ paper.biblio.release_stage }}] {% elif not paper.biblio.release_stage %} - [unpublished?] + [{{ _("unpublished?") }}] {% endif %} {# ### ABSTRACT / QUERY HIGHLIGHT #} @@ -132,7 +132,7 @@
{# colors to use: olive, brown, grey, pink, red, etc #} {% for tag in paper.tags %} - {{ tag }} + {{ _(tag) }} {% endfor %} {# TODO: remove doc for ES 7.x-style lack of type #} @@ -176,7 +176,7 @@ {% endmacro %} {% macro query_option(options, selected) -%} -{{ options.label }} +{{ _(options.label) }}