]> git.lizzy.rs Git - cheatdb.git/commitdiff
Add translation support
authorrubenwardy <rw@rubenwardy.com>
Mon, 29 Jul 2019 20:44:39 +0000 (21:44 +0100)
committerrubenwardy <rw@rubenwardy.com>
Mon, 29 Jul 2019 20:44:39 +0000 (21:44 +0100)
.gitignore
app/__init__.py
app/templates/base.html
app/templates/index.html
app/templates/packages/create_edit.html
babel.cfg [new file with mode: 0644]
config.example.cfg
requirements.txt

index 382c3d6e24a1fbab35910270114d0ca5b985c9aa..7ab19d38ff5db130bb46b173fc5c1213c1d9111f 100644 (file)
@@ -1,6 +1,7 @@
 config.cfg
 *.env
 *.sqlite
+.vscode
 custom.css
 tmp
 log.txt
index 385c613b1c0165503f5019ca91d799f160553e5b..2768fb0f16ea95f86c143cbc250da765aa033e5c 100644 (file)
@@ -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 *
index 3d8bcdab93c4e1cca7fa4d1e20279bd8a25c19eb..05b12bc898b42032e6af8b0d32fc292b7d04a942 100644 (file)
                                                                        <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>
        <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>
index 4d54b2d819fcf22e09b859d5baadfdc936a9b879..0cb39dde5194ccc48f96aa043024ffe9d0116074 100644 (file)
@@ -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> -->
index 47c600a9772a706da6b9e4f9a53923f9678ac8fb..c2b03e1e6a59b7ba31dd0a0c26d3f710a568d859 100644 (file)
 {% 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") }}
                </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>
diff --git a/babel.cfg b/babel.cfg
new file mode 100644 (file)
index 0000000..c40b2e8
--- /dev/null
+++ b/babel.cfg
@@ -0,0 +1,3 @@
+[python: app/**.py]
+[jinja2: app/templates/**.html]
+extensions=jinja2.ext.autoescape,jinja2.ext.with_
index ae78f29bee08ea92a31aa09018843c71d57a4918..09aac7f5629ec3f4d743521903b9eb9206edc722 100644 (file)
@@ -23,3 +23,7 @@ MAIL_SERVER=""
 MAIL_PORT=587
 MAIL_USE_TLS=True
 MAIL_UTILS_ERROR_SEND_TO=[""]
+
+LANGUAGES = {
+    'en': 'English',
+}
index 03ff5b03b24a0d9529953d9a2e765fa02f16b868..10ef92e37bf8ca63ff85365de01eeca5dde12d65 100644 (file)
@@ -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