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 --- Makefile | 5 + extra/i18n/babel.cfg | 3 +- extra/i18n/web_interface.pot | 161 ++++++++++++++++++- 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 +++++++++++++++++++- 12 files changed, 534 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 5fb6a73..c269576 100644 --- a/Makefile +++ b/Makefile @@ -28,3 +28,8 @@ dev-index: ## Delete/Create DEV elasticsearch fulltext index locally http put ":9200/dev_scholar_fulltext_v01/_alias/dev_scholar_fulltext" cat data/sim_intermediate.json data/work_intermediate.json | pipenv run python -m fatcat_scholar.transform run_transform | esbulk -verbose -size 200 -id key -w 4 -index dev_scholar_fulltext_v01 -type _doc +.PHONY: update-i18n +update-i18n: ## Re-extract and compile translation files + pipenv run pybabel extract -F extra/i18n/babel.cfg -o extra/i18n/web_interface.pot fatcat_scholar/ + pipenv run pybabel update -i extra/i18n/web_interface.pot -d fatcat_scholar/translations + pipenv run pybabel compile -d fatcat_scholar/translations diff --git a/extra/i18n/babel.cfg b/extra/i18n/babel.cfg index ff50c82..c120f5a 100644 --- a/extra/i18n/babel.cfg +++ b/extra/i18n/babel.cfg @@ -1,4 +1,5 @@ -[python 1="**.py" language=":"][/python] +[python: **.py] + [jinja2: **/templates/**.html] encoding = utf-8 extensions = jinja2.ext.autoescape,jinja2.ext.with_ diff --git a/extra/i18n/web_interface.pot b/extra/i18n/web_interface.pot index b9b0b7f..7862b59 100644 --- a/extra/i18n/web_interface.pot +++ b/extra/i18n/web_interface.pot @@ -8,20 +8,171 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2020-05-12 14:16-0700\n" +"POT-Creation-Date: 2020-05-21 17:53-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.6.0\n" +"Generated-By: Babel 2.8.0\n" -#: fatcat_scholar/templates/home.html:8 -msgid "This is a longer paragraph, all of which should be translated." +#: fatcat_scholar/search.py:29 +msgid "Release Date" +msgstr "" + +#: fatcat_scholar/search.py:33 fatcat_scholar/search.py:66 +msgid "All Time" +msgstr "" + +#: fatcat_scholar/search.py:34 +msgid "Past Week" +msgstr "" + +#: fatcat_scholar/search.py:35 +msgid "Past Year" +msgstr "" + +#: fatcat_scholar/search.py:36 +msgid "Since 2000" +msgstr "" + +#: fatcat_scholar/search.py:37 +msgid "Before 1925" +msgstr "" + +#: fatcat_scholar/search.py:41 +msgid "Resource Type" +msgstr "" + +#: fatcat_scholar/search.py:45 +msgid "Papers" +msgstr "" + +#: fatcat_scholar/search.py:46 +msgid "Reports" +msgstr "" + +#: fatcat_scholar/search.py:47 +msgid "Datasets" +msgstr "" + +#: fatcat_scholar/search.py:48 fatcat_scholar/search.py:56 +msgid "Everything" +msgstr "" + +#: fatcat_scholar/search.py:52 +msgid "Availability" +msgstr "" + +#: fatcat_scholar/search.py:57 +msgid "Fulltext" +msgstr "" + +#: fatcat_scholar/search.py:58 +msgid "Open Access" +msgstr "" + +#: fatcat_scholar/search.py:62 +msgid "Sort Order" +msgstr "" + +#: fatcat_scholar/search.py:67 +msgid "Recent First" +msgstr "" + +#: fatcat_scholar/search.py:68 +msgid "Oldest First" +msgstr "" + +#: fatcat_scholar/templates/base.html:160 fatcat_scholar/templates/home.html:16 +msgid "by title, authors, identifiers..." +msgstr "" + +#: fatcat_scholar/templates/base.html:161 fatcat_scholar/templates/home.html:17 +msgid "Search" +msgstr "" + +#: fatcat_scholar/templates/base.html:170 +msgid "User Guide" +msgstr "" + +#: fatcat_scholar/templates/base.html:196 +msgid "" +"We are a 501(c)(3) non-profit, building a digital library of Internet " +"sites and other cultural artifacts in digital form." +msgstr "" + +#: fatcat_scholar/templates/base.html:199 +msgid "About Us" +msgstr "" + +#: fatcat_scholar/templates/base.html:200 +msgid "Contact Us" +msgstr "" + +#: fatcat_scholar/templates/base.html:201 +msgid "Policies" +msgstr "" + +#: fatcat_scholar/templates/base.html:202 +msgid "Donate" +msgstr "" + +#: fatcat_scholar/templates/base.html:215 +msgid "Help" +msgstr "" + +#: fatcat_scholar/templates/base.html:224 +msgid "Service Status" +msgstr "" + +#: fatcat_scholar/templates/base.html:225 +msgid "Source Code" msgstr "" #: fatcat_scholar/templates/home.html:10 -msgid "this is a quick" +msgid "Search Inside Millions of Research Papers" +msgstr "" + +#: fatcat_scholar/templates/home.html:24 +msgid "" +"This fulltext search index includes over 25 million research articles and" +" other documents preserved in the Internet Archive." +msgstr "" + +#: fatcat_scholar/templates/home.html:25 +msgid "" +"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." +msgstr "" + +#: fatcat_scholar/templates/search.html:8 +msgid "Filters" +msgstr "" + +#: fatcat_scholar/templates/search.html:58 +msgid "Backend Search Engine Error" +msgstr "" + +#: fatcat_scholar/templates/search.html:60 +msgid "Search Query Error" +msgstr "" + +#: fatcat_scholar/templates/search.html:78 +msgid "We didn't find any documents matching your query" +msgstr "" + +#: fatcat_scholar/templates/search.html:91 +msgid "Enter a query in the box above to get started" +msgstr "" + +#: fatcat_scholar/templates/search_macros.html:36 +msgid "media?" +msgstr "" + +#: fatcat_scholar/templates/search_macros.html:92 +msgid "unpublished?" msgstr "" 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") }} 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) }}