diff --git a/.gitignore b/.gitignore index 382c3d6..7ab19d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ config.cfg *.env *.sqlite +.vscode custom.css tmp log.txt 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") }} -
    - Next (Autoimport) - Skip Autoimport + {{ _("Next (Autoimport)") }} + {{ _("Skip Autoimport") }}
    - 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) }}
    diff --git a/babel.cfg b/babel.cfg new file mode 100644 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_ diff --git a/config.example.cfg b/config.example.cfg index ae78f29..09aac7f 100644 --- a/config.example.cfg +++ b/config.example.cfg @@ -23,3 +23,7 @@ MAIL_SERVER="" MAIL_PORT=587 MAIL_USE_TLS=True MAIL_UTILS_ERROR_SEND_TO=[""] + +LANGUAGES = { + 'en': 'English', +} diff --git a/requirements.txt b/requirements.txt index 03ff5b0..10ef92e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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