From 60483ef542662af2dc4d87fd6b1a78e39f2260b3 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 29 Jul 2019 21:44:39 +0100 Subject: Add translation support --- app/__init__.py | 8 ++++++++ app/templates/base.html | 24 ++++++++++++------------ app/templates/index.html | 20 ++++++++++---------- app/templates/packages/create_edit.html | 33 ++++++++++++++++----------------- 4 files changed, 46 insertions(+), 39 deletions(-) (limited to 'app') diff --git a/app/__init__.py b/app/__init__.py index 385c613..2768fb0 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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 * diff --git a/app/templates/base.html b/app/templates/base.html index 3d8bcda..05b12bc 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -79,24 +79,24 @@ Your unadded topics {% if current_user.canAccessTodoList() %} - - + + {% endif %} {% if current_user.rank == current_user.rank.ADMIN %} - + {% endif %} {% if current_user.rank == current_user.rank.MODERATOR %} - - + + {% endif %} - + {% else %} -
  • Sign in
  • +
  • {{ _("Sign in") }}
  • {% endif %} @@ -131,10 +131,10 @@ diff --git a/app/templates/index.html b/app/templates/index.html index 4d54b2d..0cb39dd 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block title %} -Welcome +{{ _("Welcome") }} {% endblock %} {% block scriptextra %} @@ -38,35 +38,35 @@ Welcome - See more + {{ _("See more") }} -

    Recently Added

    +

    {{ _("Recently Added") }}

    {{ render_pkggrid(new) }} - See more + {{ _("See more") }} -

    Top Mods

    +

    {{ _("Top Mods") }}

    {{ render_pkggrid(pop_mod) }} - See more + {{ _("See more") }} -

    Top Games

    +

    {{ _("Top Games") }}

    {{ render_pkggrid(pop_gam) }} - See more + {{ _("See more") }} -

    Top Texture Packs

    +

    {{ _("Top Texture Packs") }}

    {{ render_pkggrid(pop_txp) }}
    - 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) }}
    diff --git a/app/templates/packages/create_edit.html b/app/templates/packages/create_edit.html index 47c600a..c2b03e1 100644 --- a/app/templates/packages/create_edit.html +++ b/app/templates/packages/create_edit.html @@ -20,19 +20,19 @@ {% endblock %} {% block content %} -

    Create Package

    +

    {{ _("Create Package") }}

    - View + {{ _("View") }} - Have you read the Package Inclusion Policy and Guidance yet? + {{ _("Have you read the Package Inclusion Policy and Guidance yet?") }}
    @@ -42,7 +42,7 @@ {{ form.hidden_tag() }}
    - Package + {{ _("Package") }}
    {{ render_field(form.type, class_="pkg_meta col-sm-2") }} @@ -63,7 +63,7 @@
    - Dependencies + {{ _("Dependencies") }} {{ 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 @@
    - Repository and Links + {{ _("Repository and Links") }}
    -

    Enter the repo URL for the package. - If the repo uses git then the metadata will be automatically imported.

    +

    {{ _("Enter the repo URL for the package. + If the repo uses git then the metadata will be automatically imported.") }}

    -

    Leave blank if you don't have a repo. Click skip if the import fails.

    +

    {{ _("Leave blank if you don't have a repo. Click skip if the import fails.") }}

    {{ render_field(form.repo, class_="pkg_repo") }} -
    - Importing... (This may take a while) + {{ _("Importing... (This may take a while)") }}
    {{ 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")) }}
    {{ render_submit_field(form.submit) }}
    -- cgit v1.2.3