From f24c03365f780c3d08a90b4ddbe0a9bc3b63d18d Mon Sep 17 00:00:00 2001 From: db0 Date: Thu, 28 Sep 2023 19:50:31 +0200 Subject: [PATCH] feat: translations --- TRANSLATIONS.md | 33 ++++++++++++++++++++++ fediseer/apis/models/v1.py | 1 + fediseer/faq/__init__.py | 19 +++++++++++-- fediseer/faq/ell.py | 24 ++++++++++++++++ fediseer/faq/eng.py | 25 ++++++++++++++++ fediseer/routes.py | 58 +++++++++++++++++++++++++++++--------- fediseer/templates/faq.md | 6 ---- 7 files changed, 145 insertions(+), 21 deletions(-) create mode 100644 TRANSLATIONS.md delete mode 100644 fediseer/templates/faq.md diff --git a/TRANSLATIONS.md b/TRANSLATIONS.md new file mode 100644 index 0000000..54c8f26 --- /dev/null +++ b/TRANSLATIONS.md @@ -0,0 +1,33 @@ +# Help us translate the fediseer FAQ + +We wish to allow the Fediseer [FAQ](/faq) to be available to multiple languages and for that we need your help. + +If you want to translate, you can do it two ways: + + +## Pull Request + +Use this approach if you're good with github and/or git. If not, see the `Simple` approach below + +Go to our github repository (https://github.com/Fediseer/fediseer) and create a pull request for the language you would like to contribute. + +All you need to do is make a copy [of the english version](https://github.com/Fediseer/fediseer/blob/main/fediseer/faq/eng.py) into the [3-letter ISO 639-3 code](https://iso639-3.sil.org/code_tables/639/data) of the language you wish to translate to. + +For example if you would like to translate into arabic, you would create a file `fediseer/faq/ara.py`. + +Then rename all variables of "ENG" to your language code. To follow our example, you would rename `ENG_HEADER` to `ARA_HEADER` before translating its contents. + +**Note:** Do not translate the `category` key. Only the `category_translated` key. + +Once you're done with a field, change its `translated` key to `True` + +Finally in https://github.com/Fediseer/fediseer/blob/main/fediseer/faq/__init__.py, follow the other existing language as examples, and import and add the entries for your new language code. + +## Simple + +Use this approach if you don't understand github or git well. + +Simply [download the english version](https://github.com/Fediseer/fediseer/blob/main/fediseer/faq/eng.py) + +Edit it as best as you can with your text editor, then [open a new issue with your results](https://github.com/Fediseer/fediseer/issues) and post it there. We'll handle the rest. You can send us partial translations if you want and work on them slowly. + diff --git a/fediseer/apis/models/v1.py b/fediseer/apis/models/v1.py index 716bce3..7660b0c 100644 --- a/fediseer/apis/models/v1.py +++ b/fediseer/apis/models/v1.py @@ -143,6 +143,7 @@ class Models: self.response_model_faq_entry = api.model('FAQEntry', { 'category': fields.String(description="The overarching category for this entry", example="terminology"), 'category_translated': fields.String(description="The overarching category for this entry, translated to the target language.", example="terminology"), + 'translated': fields.Boolean(description="If false, this entry has not yet been translated to the target language."), 'added': fields.DateTime(description="The date this entry was added"), 'question': fields.String(description="The entry in question form", example="What is an FAQ?"), 'stub': fields.String(description="The entry in a short form", example="faq"), diff --git a/fediseer/faq/__init__.py b/fediseer/faq/__init__.py index 8d0730e..c3d5061 100644 --- a/fediseer/faq/__init__.py +++ b/fediseer/faq/__init__.py @@ -1,7 +1,22 @@ -from .eng import ENG_FAQ -from .ell import ELL_FAQ +from .eng import ENG_FAQ, ENG_HEADER, ENG_TRANSLATION_MESSAGE +from .ell import ELL_FAQ, ELL_HEADER, ELL_TRANSLATION_MESSAGE + +LANGUAGE_NAMES = { + "eng": "English", + "ell": "Ελληνικά", +} FAQ_LANGUAGES = { "eng": ENG_FAQ, "ell": ELL_FAQ, +} + +HEADER_LANGUAGES = { + "eng": ENG_HEADER, + "ell": ELL_HEADER, +} + +TRANSLATION_MESSAGE_LANGUAGES = { + "eng": ENG_TRANSLATION_MESSAGE, + "ell": ELL_TRANSLATION_MESSAGE, } \ No newline at end of file diff --git a/fediseer/faq/ell.py b/fediseer/faq/ell.py index 594f9d5..a42e0f2 100644 --- a/fediseer/faq/ell.py +++ b/fediseer/faq/ell.py @@ -1,9 +1,19 @@ from fediseer.consts import MAX_TAGS +ELL_HEADER = """#Συχνές Ερωτήσεις για το Fediseer + +Αυτό το έγγραφο θα προσπαθήσει να παρέχει ορισμούς και απαντήσεις σε συνήθεις ερωτήσεις σχετικά με το Fediseer. + +[TOC] +""" + +ELL_TRANSLATION_MESSAGE = "**Προσοχή**: Αυτή η μετάφραση δεν έχει υλοποιηθεί ακόμα." + ELL_FAQ = [ { "category": "terminology", "category_translated": "τερμινολογία", + "translated": True, "added": "2023-09-25", "question": "Τι είναι το Fediseer?", "stub": "fediseer", @@ -21,6 +31,7 @@ To παρέχει ένα αναγνώσιμο από μηχανή API για τ { "category": "terminology", "category_translated": "τερμινολογία", + "translated": True, "added": "2023-09-25", "question": "Τι είναι η εγγυήση?", "stub": "guarantee", @@ -39,6 +50,7 @@ To παρέχει ένα αναγνώσιμο από μηχανή API για τ { "category": "terminology", "category_translated": "τερμινολογία", + "translated": False, "added": "2023-09-25", "question": "What is the chain of trust?", "stub": "chain of trust", @@ -53,6 +65,7 @@ This allows the fediseer to quickly deal with spam instances that sneaked into t { "category": "terminology", "category_translated": "τερμινολογία", + "translated": False, "added": "2023-09-25", "question": "What is an endorsement?", "stub": "endorsement", @@ -67,6 +80,7 @@ When looking at the instance whitelist, one can also filter by amount of endorse { "category": "terminology", "category_translated": "τερμινολογία", + "translated": False, "added": "2023-09-25", "question": "What is a censure?", "stub": "censure", @@ -81,6 +95,7 @@ One can export the list of instances censured by a subset of instances. { "category": "terminology", "category_translated": "τερμινολογία", + "translated": False, "added": "2023-09-25", "question": "What is a hesitation?", "stub": "hesitation", @@ -95,6 +110,7 @@ One can export the list of instances hesitate by a subset of instances. { "category": "terminology", "category_translated": "τερμινολογία", + "translated": False, "added": "2023-09-25", "question": "What is an instance claim?", "stub": "claim", @@ -107,6 +123,7 @@ Fediseer has no users. Instead it's driven by instance admins only. Instance adm { "category": "terminology", "category_translated": "τερμινολογία", + "translated": False, "added": "2023-09-25", "question": "What are instance visibilities?", "stub": "visibilities", @@ -123,6 +140,7 @@ Note that guarantees are always public as this is necessary for the good functio { "category": "terminology", "category_translated": "τερμινολογία", + "translated": False, "added": "2023-09-25", "question": "What is an instance flag?", "stub": "flag", @@ -136,6 +154,7 @@ Note that guarantees are always public as this is necessary for the good functio { "category": "terminology", "category_translated": "τερμινολογία", + "translated": False, "added": "2023-09-27", "question": "What is an instance tag?", "stub": "tag", @@ -152,6 +171,7 @@ Like always, no hate speech is allowed. { "category": "functionality", "category_translated": "λειτουργικότητα", + "translated": False, "added": "2023-09-25", "question": "How can I claim my instance?", "stub": "instance claim", @@ -164,6 +184,7 @@ You will then receive an API key in PMs, which you can afterwards use to represe { "category": "functionality", "category_translated": "λειτουργικότητα", + "translated": False, "added": "2023-09-25", "question": "What can I write in my reasons for endorsements, hesitations and censures?", "stub": "reasons", @@ -176,6 +197,7 @@ You are not allowed to use hate speech in your reasons. { "category": "functionality", "category_translated": "λειτουργικότητα", + "translated": False, "added": "2023-09-25", "question": "What can I write in my evidence for censures and hesitations?", "stub": "evidence", @@ -188,6 +210,7 @@ You are not allowed to use hate speech in your evidence. { "category": "philosophy", "category_translated": "φιλοσοφία", + "translated": False, "added": "2023-09-25", "question": "Doesn't this all cause fediverse centralization?", "stub": "centralization", @@ -200,6 +223,7 @@ Not only that, but the fediseer is free and open source software, allowing anyon { "category": "philosophy", "category_translated": "φιλοσοφία", + "translated": False, "added": "2023-09-25", "question": "Doesn't this make the fediseer an authority on the fediverse?", "stub": "authority", diff --git a/fediseer/faq/eng.py b/fediseer/faq/eng.py index 02ba4e3..daf1397 100644 --- a/fediseer/faq/eng.py +++ b/fediseer/faq/eng.py @@ -1,9 +1,20 @@ from fediseer.consts import MAX_TAGS +ENG_HEADER = """#Fediseer FAQ + +This document will attempt to provide some definitions and answers to common questions around the fediseer. + +[TOC] +""" + +ENG_TRANSLATION_MESSAGE = "**Attention**: This translation is not completed yet." + + ENG_FAQ = [ { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-25", "question": "What is the Fediseer?", "stub": "fediseer", @@ -20,6 +31,7 @@ The fediseer provides a machine readable API to consume the data contained withi { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-25", "question": "What is a guarantee?", "stub": "guarantee", @@ -34,6 +46,7 @@ Guarantees are community driven. While the fediseer can guarantee at the top lev { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-25", "question": "What is the chain of trust?", "stub": "chain of trust", @@ -48,6 +61,7 @@ This allows the fediseer to quickly deal with spam instances that sneaked into t { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-25", "question": "What is an endorsement?", "stub": "endorsement", @@ -62,6 +76,7 @@ When looking at the instance whitelist, one can also filter by amount of endorse { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-25", "question": "What is a censure?", "stub": "censure", @@ -76,6 +91,7 @@ One can export the list of instances censured by a subset of instances. { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-25", "question": "What is a hesitation?", "stub": "hesitation", @@ -90,6 +106,7 @@ One can export the list of instances hesitate by a subset of instances. { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-25", "question": "What is an instance claim?", "stub": "claim", @@ -102,6 +119,7 @@ Fediseer has no users. Instead it's driven by instance admins only. Instance adm { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-25", "question": "What are instance visibilities?", "stub": "visibilities", @@ -118,6 +136,7 @@ Note that guarantees are always public as this is necessary for the good functio { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-25", "question": "What is an instance flag?", "stub": "flag", @@ -131,6 +150,7 @@ Note that guarantees are always public as this is necessary for the good functio { "category": "terminology", "category_translated": "terminology", + "translated": True, "added": "2023-09-27", "question": "What is an instance tag?", "stub": "tag", @@ -147,6 +167,7 @@ Like always, no hate speech is allowed. { "category": "functionality", "category_translated": "functionality", + "translated": True, "added": "2023-09-25", "question": "How can I claim my instance?", "stub": "instance claim", @@ -159,6 +180,7 @@ You will then receive an API key in PMs, which you can afterwards use to represe { "category": "functionality", "category_translated": "functionality", + "translated": True, "added": "2023-09-25", "question": "What can I write in my reasons for endorsements, hesitations and censures?", "stub": "reasons", @@ -171,6 +193,7 @@ You are not allowed to use hate speech in your reasons. { "category": "functionality", "category_translated": "functionality", + "translated": True, "added": "2023-09-25", "question": "What can I write in my evidence for censures and hesitations?", "stub": "evidence", @@ -183,6 +206,7 @@ You are not allowed to use hate speech in your evidence. { "category": "philosophy", "category_translated": "philosophy", + "translated": True, "added": "2023-09-25", "question": "Doesn't this all cause fediverse centralization?", "stub": "centralization", @@ -195,6 +219,7 @@ Not only that, but the fediseer is free and open source software, allowing anyon { "category": "philosophy", "category_translated": "philosophy", + "translated": True, "added": "2023-09-25", "question": "Doesn't this make the fediseer an authority on the fediverse?", "stub": "authority", diff --git a/fediseer/routes.py b/fediseer/routes.py index 8f3c95e..7ffc5aa 100644 --- a/fediseer/routes.py +++ b/fediseer/routes.py @@ -2,7 +2,7 @@ from flask import render_template, redirect, url_for, request from markdown import markdown from loguru import logger from fediseer.flask import OVERSEER -from fediseer.faq import FAQ_LANGUAGES +from fediseer.faq import FAQ_LANGUAGES, HEADER_LANGUAGES, TRANSLATION_MESSAGE_LANGUAGES, LANGUAGE_NAMES import fediseer.exceptions as e @logger.catch(reraise=True) @@ -34,12 +34,12 @@ def index(): return(head + markdown(findex)) @logger.catch(reraise=True) -@OVERSEER.route('/faq') +@OVERSEER.route('/faq/') # @cache.cached(timeout=300) -def faq(): - with open(f'fediseer/templates/faq.md') as md_file: - md = md_file.read() - +def faq(lang): + if lang not in FAQ_LANGUAGES: + return redirect(url_for('faq_default')) + md = HEADER_LANGUAGES[lang] style = """ + """ + + head = f""" + Fediseer + + {style} + + """ + md = "#Fediseer FAQ\n\n" +\ + "We provide the fediseer FAQ in multiple languages. Please select one of the options below.\n\n" + + for lang in LANGUAGE_NAMES: + md += f" * [{LANGUAGE_NAMES[lang]}](/faq/{lang})\n" + md += "\nPlease [help us add more language support](https://github.com/Fediseer/fediseer/blob/main/TRANSLATIONS.md)" + return(head + markdown(md)) @logger.catch(reraise=True) @OVERSEER.route('/.well-known/webfinger') diff --git a/fediseer/templates/faq.md b/fediseer/templates/faq.md deleted file mode 100644 index 78e0661..0000000 --- a/fediseer/templates/faq.md +++ /dev/null @@ -1,6 +0,0 @@ -# Fediseer FAQ - -This document will attempt to provide some definitions and answers to common questions around the fediseer. - -[TOC] -