Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

implementing trial for text translation on templates #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
git_update="git fetch origin master && git reset --hard FETCH_HEAD"

help:
return "Make tasks for deployment. Checkout the makefile content."
@echo "Make tasks for deployment. Checkout the makefile content."

deploy:
ssh epidaurus "cd ~/tci-online && " ${git_update}
Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from core import app
from core.views import *
from core import views, templates # noqa: F401


# WSGI
Expand Down
20 changes: 20 additions & 0 deletions core/templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from flask import request, Markup
from tcii18n.template import flask_methods

import gfm

from . import app


def get_translations_file():
supported_languages = app.config.get('TRANSLATION_FILES').keys()
lang = (request.accept_languages.best_match(supported_languages) or
supported_languages[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we'll always have at least 1 language in app.config.get('TRANSLATION_FILES').keys() ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We should in most cases, but indeed the system should still work if the translation were not found.

return app.config.get('TRANSLATION_FILES').get(lang)

flask_methods(app, get_translations_file)


@app.template_filter('markdown')
def markdown_filter(string):
return Markup(gfm.markdown(gfm.gfm(string)))
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Flask==0.12
gfm==0.0.3
-e git+ssh://bitbucket.org/anthropedia/tci-database.git#egg=tci-database
-e git+ssh://bitbucket.org/anthropedia/tci-data.git#egg=tci-data

Flask==0.12
-e git+https://github.com/anthropedia/tci-i18n.git#egg=tci-i18n
6 changes: 6 additions & 0 deletions settings.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
'host': 'localhost',
'port': 27017,
}

TRANSLATION_FILES = {
'en': '/path/to/my/transfile.en.csv',
'fr': '/path/to/my/transfile.fr.csv',
'sv': '/path/to/my/transfile.sv.csv',
}
2 changes: 1 addition & 1 deletion templates/error.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'layout.html' %}
{% block main %}
<section>
<h2>Oops, the test didn't load.</h2>
<h2>{{ trans("Oops, the test didn't load.") }}</h2>
<p>There are a couple of reasons this might happen.</p>
<p>Please double-check that you are using a new valid link and not an old test.</p>
<p>Otherwise, you might have an invalid token. If you are sure you have the good link,
Expand Down