mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Use translation on package view page
This commit is contained in:
parent
ab57b6aa2c
commit
d252d687fc
@ -19,8 +19,9 @@ import datetime
|
||||
import enum
|
||||
import os
|
||||
|
||||
import typing
|
||||
from flask import url_for
|
||||
from flask_babel import lazy_gettext
|
||||
from flask_babel import lazy_gettext, get_locale
|
||||
from flask_sqlalchemy import BaseQuery
|
||||
from sqlalchemy import or_, func
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
@ -493,6 +494,28 @@ class Package(db.Model):
|
||||
def get_id(self):
|
||||
return "{}/{}".format(self.author.username, self.name)
|
||||
|
||||
def get_translated(self, lang=None):
|
||||
if lang is None:
|
||||
locale = get_locale()
|
||||
if locale:
|
||||
lang = locale.language
|
||||
else:
|
||||
lang = "en"
|
||||
|
||||
translation: typing.Optional[PackageTranslation] = self.translations.filter_by(language_id=lang).first()
|
||||
if translation is None:
|
||||
return {
|
||||
"title": self.title,
|
||||
"short_desc": self.short_desc,
|
||||
"desc": self.desc,
|
||||
}
|
||||
|
||||
return {
|
||||
"title": translation.title or self.title,
|
||||
"short_desc": translation.short_desc or self.short_desc,
|
||||
"desc": translation.desc or self.desc,
|
||||
}
|
||||
|
||||
def get_sorted_dependencies(self, is_hard=None):
|
||||
query = self.dependencies
|
||||
if is_hard is not None:
|
||||
|
@ -1,14 +1,15 @@
|
||||
{% set query=package.name %}
|
||||
{% set release = package.get_download_release() %}
|
||||
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% set query=package.name %}
|
||||
{% set release = package.get_download_release() %}
|
||||
{% set meta = package.get_translated() %}
|
||||
|
||||
{% block title %}
|
||||
{{ package.title }}
|
||||
{{ meta.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block description -%}
|
||||
{{ package.short_desc }}
|
||||
{{ meta.short_desc }}
|
||||
{% endblock %}
|
||||
|
||||
{% block headextra %}
|
||||
@ -130,11 +131,11 @@
|
||||
</div>
|
||||
|
||||
<h1 class="display-3">
|
||||
{{ package.title }}
|
||||
{{ meta.title }}
|
||||
</h1>
|
||||
|
||||
<p class="lead">
|
||||
{{ package.short_desc }}
|
||||
{{ meta.short_desc }}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@ -322,9 +323,9 @@
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% if package.desc %}
|
||||
{% if meta.desc %}
|
||||
<article class="markdown panel mb-5">
|
||||
{{ package.desc | markdown }}
|
||||
{{ meta.desc | markdown }}
|
||||
</article>
|
||||
{% endif %}
|
||||
|
||||
@ -454,7 +455,7 @@
|
||||
<a class="badge bg-primary"
|
||||
href="{{ dep.package.get_url('packages.view') }}">
|
||||
{{ _("%(title)s by %(display_name)s",
|
||||
title=dep.package.title, display_name=dep.package.author.display_name) }}
|
||||
title=dep.package.get_translated().title, display_name=dep.package.author.display_name) }}
|
||||
</a>
|
||||
{% elif dep.meta_package %}
|
||||
<a class="badge bg-primary"
|
||||
@ -478,7 +479,7 @@
|
||||
<a class="badge bg-secondary"
|
||||
href="{{ dep.package.get_url('packages.view') }}">
|
||||
{{ _("%(title)s by %(display_name)s",
|
||||
title=dep.package.title, display_name=dep.package.author.display_name) }}
|
||||
title=dep.package.get_translated().title, display_name=dep.package.author.display_name) }}
|
||||
{% elif dep.meta_package %}
|
||||
<a class="badge bg-secondary"
|
||||
href="{{ url_for('modnames.view', name=dep.meta_package.name) }}">
|
||||
|
Loading…
Reference in New Issue
Block a user