Add translation support

This commit is contained in:
rubenwardy 2019-07-29 21:44:39 +01:00
parent 3c8a8b8988
commit 60483ef542
8 changed files with 55 additions and 39 deletions

1
.gitignore vendored

@ -1,6 +1,7 @@
config.cfg
*.env
*.sqlite
.vscode
custom.css
tmp
log.txt

@ -24,6 +24,7 @@ from flaskext.markdown import Markdown
from flask_github import GitHub
from flask_wtf.csrf import CsrfProtect
from flask_flatpages import FlatPages
from flask_babel import Babel
import os
app = Flask(__name__, static_folder="public/static")
@ -37,6 +38,7 @@ github = GitHub(app)
csrf = CsrfProtect(app)
mail = Mail(app)
pages = FlatPages(app)
babel = Babel(app)
gravatar = Gravatar(app,
size=58,
rating='g',
@ -50,5 +52,11 @@ if not app.debug:
from .maillogger import register_mail_error_handler
register_mail_error_handler(app, mail)
@babel.localeselector
def get_locale():
return request.accept_languages.best_match(app.config['LANGUAGES'].keys())
from . import models, tasks
from .views import *

@ -79,24 +79,24 @@
<a class="nav-link" href="{{ url_for('user_profile_page', username=current_user.username) }}#unadded-topics">Your unadded topics</a>
</li>
{% if current_user.canAccessTodoList() %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('todo_page') }}">Work Queue</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('user_list_page') }}">User list</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('todo_page') }}">{{ _("Work Queue") }}</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('user_list_page') }}">{{ _("User list") }}</a></li>
{% endif %}
<li class="nav-item">
<a class="nav-link" href="{{ url_for('todo_topics_page') }}">All unadded topics</a>
<a class="nav-link" href="{{ url_for('todo_topics_page') }}">{{ _("All unadded topics") }}</a>
</li>
{% if current_user.rank == current_user.rank.ADMIN %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin_page') }}">Admin</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('admin_page') }}">{{ _("Admin") }}</a></li>
{% endif %}
{% if current_user.rank == current_user.rank.MODERATOR %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('tag_list_page') }}">Tag Editor</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('license_list_page') }}">License Editor</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('tag_list_page') }}">{{ _("Tag Editor") }}</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('license_list_page') }}">{{ _("License Editor") }}</a></li>
{% endif %}
<li class="nav-item"><a class="nav-link" href="{{ url_for('user.logout') }}">Sign out</a></li>
<li class="nav-item"><a class="nav-link" href="{{ url_for('user.logout') }}">{{ _("Sign out") }}</a></li>
</ul>
</li>
{% else %}
<li><a class="nav-link" href="{{ url_for('user.login') }}">Sign in</a></li>
<li><a class="nav-link" href="{{ url_for('user.login') }}">{{ _("Sign in") }}</a></li>
{% endif %}
</ul>
</div>
@ -131,10 +131,10 @@
<footer class="container footer-copyright my-5 page-footer font-small text-center">
ContentDB &copy; 2018-9 to <a href="https://rubenwardy.com/">rubenwardy</a> |
<a href="https://github.com/minetest/contentdb">GitHub</a> |
<a href="{{ url_for('flatpage', path='help') }}">Help</a> |
<a href="{{ url_for('flatpage', path='policy_and_guidance') }}">Policy and Guidance</a> |
<a href="{{ url_for('flatpage', path='help/reporting') }}">Report / DMCA</a> |
<a href="{{ url_for('user_list_page') }}">User List</a>
<a href="{{ url_for('flatpage', path='help') }}">{{ _("Help") }}</a> |
<a href="{{ url_for('flatpage', path='policy_and_guidance') }}">{{ _("Policy and Guidance") }}</a> |
<a href="{{ url_for('flatpage', path='help/reporting') }}">{{ _("Report / DMCA") }}</a> |
<a href="{{ url_for('user_list_page') }}">{{ _("User List") }}</a>
</footer>
<script src="/static/jquery.min.js"></script>

@ -1,7 +1,7 @@
{% extends "base.html" %}
{% block title %}
Welcome
{{ _("Welcome") }}
{% endblock %}
{% block scriptextra %}
@ -38,35 +38,35 @@ Welcome
<a href="{{ url_for('packages_page', sort='created_at', order='desc') }}" class="btn btn-secondary float-right">
See more
{{ _("See more") }}
</a>
<h2 class="my-3">Recently Added</h2>
<h2 class="my-3">{{ _("Recently Added") }}</h2>
{{ render_pkggrid(new) }}
<a href="{{ url_for('packages_page', type='mod', sort='score', order='desc') }}" class="btn btn-secondary float-right">
See more
{{ _("See more") }}
</a>
<h2 class="my-3">Top Mods</h2>
<h2 class="my-3">{{ _("Top Mods") }}</h2>
{{ render_pkggrid(pop_mod) }}
<a href="{{ url_for('packages_page', type='game', sort='score', order='desc') }}" class="btn btn-secondary float-right">
See more
{{ _("See more") }}
</a>
<h2 class="my-3">Top Games</h2>
<h2 class="my-3">{{ _("Top Games") }}</h2>
{{ render_pkggrid(pop_gam) }}
<a href="{{ url_for('packages_page', type='txp', sort='score', order='desc') }}" class="btn btn-secondary float-right">
See more
{{ _("See more") }}
</a>
<h2 class="my-3">Top Texture Packs</h2>
<h2 class="my-3">{{ _("Top Texture Packs") }}</h2>
{{ render_pkggrid(pop_txp) }}
<div class="text-center">
<small>
CDB has {{ count }} packages, with a total of {{ downloads }} downloads.
{{ _("CDB has %(count)d packages, with a total of %(downloads)d downloads.", count=count, downloads=downloads) }}
</small>
</div>
<!-- </main> -->

@ -20,19 +20,19 @@
{% endblock %}
{% block content %}
<h1>Create Package</h1>
<h1>{{ _("Create Package") }}</h1>
<div class="alert alert-info">
<a class="float-right btn btn-sm btn-default" href="{{ url_for('flatpage', path='policy_and_guidance') }}">View</a>
<a class="float-right btn btn-sm btn-default" href="{{ url_for('flatpage', path='policy_and_guidance') }}">{{ _("View") }}</a>
Have you read the Package Inclusion Policy and Guidance yet?
{{ _("Have you read the Package Inclusion Policy and Guidance yet?") }}
</div>
<noscript>
<div class="alert alert-warning">
Javascript is needed to improve the user interface, and is needed for features
such as finding metadata from git, and autocompletion.<br />
Whilst disabled Javascript may work, it is not officially supported.
{{ _("Javascript is needed to improve the user interface, and is needed for features
such as finding metadata from git, and autocompletion.") }}<br />
{{ _("Whilst disabled Javascript may work, it is not officially supported.") }}
</div>
</noscript>
@ -42,7 +42,7 @@
{{ form.hidden_tag() }}
<fieldset>
<legend>Package</legend>
<legend>{{ _("Package") }}</legend>
<div class="row">
{{ render_field(form.type, class_="pkg_meta col-sm-2") }}
@ -63,7 +63,7 @@
</fieldset>
<fieldset class="pkg_meta">
<legend class="not_txp">Dependencies</legend>
<legend class="not_txp">{{ _("Dependencies") }}</legend>
{{ render_mpackage_field(form.provides_str, class_="not_txp", placeholder="Comma separated list") }}
{{ render_deps_field(form.harddep_str, class_="not_txp not_game", placeholder="Comma separated list") }}
@ -71,30 +71,29 @@
</fieldset>
<fieldset>
<legend class="pkg_meta">Repository and Links</legend>
<legend class="pkg_meta">{{ _("Repository and Links") }}</legend>
<div class="pkg_wiz_1">
<p>Enter the repo URL for the package.
If the repo uses git then the metadata will be automatically imported.</p>
<p>{{ _("Enter the repo URL for the package.
If the repo uses git then the metadata will be automatically imported.") }}</p>
<p>Leave blank if you don't have a repo. Click skip if the import fails.</p>
<p>{{ _("Leave blank if you don't have a repo. Click skip if the import fails.") }}</p>
</div>
{{ render_field(form.repo, class_="pkg_repo") }}
<div class="pkg_wiz_1">
<a id="pkg_wiz_1_next" class="btn btn-primary">Next (Autoimport)</a>
<a id="pkg_wiz_1_skip" class="btn btn-default">Skip Autoimport</a>
<a id="pkg_wiz_1_next" class="btn btn-primary">{{ _("Next (Autoimport)") }}</a>
<a id="pkg_wiz_1_skip" class="btn btn-default">{{ _("Skip Autoimport") }}</a>
</div>
<div class="pkg_wiz_2">
Importing... (This may take a while)
{{ _("Importing... (This may take a while)") }}
</div>
{{ render_field(form.website, class_="pkg_meta") }}
{{ render_field(form.issueTracker, class_="pkg_meta") }}
{{ render_field(form.forums, class_="pkg_meta", placeholder="Tip: paste in a forum topic URL") }}
{{ render_field(form.forums, class_="pkg_meta", placeholder=_("Tip: paste in a forum topic URL")) }}
</fieldset>
<div class="pkg_meta">{{ render_submit_field(form.submit) }}</div>

3
babel.cfg Normal file

@ -0,0 +1,3 @@
[python: app/**.py]
[jinja2: app/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_

@ -23,3 +23,7 @@ MAIL_SERVER=""
MAIL_PORT=587
MAIL_USE_TLS=True
MAIL_UTILS_ERROR_SEND_TO=[""]
LANGUAGES = {
'en': 'English',
}

@ -7,6 +7,7 @@ Flask-Menu~=0.7
Flask-Migrate~=2.3
Flask-SQLAlchemy~=2.3
Flask-User~=0.6
Flask-Babel
GitHub-Flask~=3.2
SQLAlchemy-Searchable==1.0.3