From b1a9398ed1add11e8e6d40f8a304adb82d12d0a2 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 26 Feb 2024 01:50:15 +0000 Subject: [PATCH] Add `has_contentdb_translation` to Language, add API --- app/blueprints/api/endpoints.py | 6 ++++ app/flatpages/help/api.md | 42 ++++++++++++++++--------- app/models/packages.py | 11 +++++++ app/templates/admin/languages/list.html | 19 ++++++++--- 4 files changed, 59 insertions(+), 19 deletions(-) diff --git a/app/blueprints/api/endpoints.py b/app/blueprints/api/endpoints.py index f9db0dfd..8c0fc75b 100644 --- a/app/blueprints/api/endpoints.py +++ b/app/blueprints/api/endpoints.py @@ -648,6 +648,12 @@ def versions(): for rel in MinetestRelease.query.all() if rel.get_actual() is not None]) +@bp.route("/api/languages/") +@cors_allowed +def languages(): + return jsonify([x.as_dict() for x in Language.query.all()]) + + @bp.route("/api/dependencies/") @cors_allowed def all_deps(): diff --git a/app/flatpages/help/api.md b/app/flatpages/help/api.md index 7fef151f..d47b03c5 100644 --- a/app/flatpages/help/api.md +++ b/app/flatpages/help/api.md @@ -466,31 +466,43 @@ Supported query parameters: ### Tags -* GET `/api/tags/` ([View](/api/tags/)): List of: - * `name`: technical name. - * `title`: human-readable title. - * `description`: tag description or null. - * `views`: number of views of this tag. +* GET `/api/tags/` ([View](/api/tags/)) + * List of objects with: + * `name`: technical name. + * `title`: human-readable title. + * `description`: tag description or null. + * `views`: number of views of this tag. ### Content Warnings -* GET `/api/content_warnings/` ([View](/api/content_warnings/)): List of: - * `name`: technical name - * `title`: human-readable title - * `description`: tag description or null +* GET `/api/content_warnings/` ([View](/api/content_warnings/)) + * List of objects with + * `name`: technical name + * `title`: human-readable title + * `description`: tag description or null ### Licenses -* GET `/api/licenses/` ([View](/api/licenses/)): List of: - * `name` - * `is_foss`: whether the license is foss +* GET `/api/licenses/` ([View](/api/licenses/)) + * List of objects with: + * `name` + * `is_foss`: whether the license is foss ### Minetest Versions * GET `/api/minetest_versions/` ([View](/api/minetest_versions/)) - * `name`: Version name. - * `is_dev`: boolean, is dev version. - * `protocol_version`: protocol version umber. + * List of objects with: + * `name`: Version name. + * `is_dev`: boolean, is dev version. + * `protocol_version`: protocol version number. + +### Languages + +* GET `/api/languages/` ([View](/api/languages/)) + * List of objects with: + * `id`: language code. + * `title`: native language name. + * `has_contentdb_translation`: whether ContentDB has been translated into this language. ## Misc diff --git a/app/models/packages.py b/app/models/packages.py index f8847c34..85c3da04 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -847,6 +847,17 @@ class Language(db.Model): id = db.Column(db.String(10), primary_key=True) title = db.Column(db.String(100), unique=True, nullable=False) + @property + def has_contentdb_translation(self): + return self.id in app.config["LANGUAGES"].keys() + + def as_dict(self): + return { + "id": self.id, + "title": self.title, + "has_contentdb_translation": self.has_contentdb_translation, + } + class PackageTranslation(db.Model): package_id = db.Column(db.Integer, db.ForeignKey("package.id"), primary_key=True) diff --git a/app/templates/admin/languages/list.html b/app/templates/admin/languages/list.html index bd4ca9d5..580ad8dd 100644 --- a/app/templates/admin/languages/list.html +++ b/app/templates/admin/languages/list.html @@ -12,13 +12,17 @@
-
+
{{ _("Id") }}
-
+
{{ _("Title") }}
+ +
+ {{ _("Has ContentDB translation?") }} +
@@ -26,12 +30,19 @@