forked from miguelgrinberg/microblog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2f24e8
commit 388177a
Showing
9 changed files
with
119 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import json | ||
import requests | ||
from flask_babel import _ | ||
from app import app | ||
|
||
|
||
def translate(text, source_language, dest_language): | ||
if 'MS_TRANSLATOR_KEY' not in app.config or \ | ||
not app.config['MS_TRANSLATOR_KEY']: | ||
return _('Error: the translation service is not configured.') | ||
auth = {'Ocp-Apim-Subscription-Key': app.config['MS_TRANSLATOR_KEY']} | ||
r = requests.get('https://api.microsofttranslator.com/v2/Ajax.svc' | ||
'/Translate?text={}&from={}&to={}'.format( | ||
text, source_language, dest_language), | ||
headers=auth) | ||
if r.status_code != 200: | ||
return _('Error: the translation service failed.') | ||
return json.loads(r.content.decode('utf-8-sig')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ class Config(object): | |
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') | ||
ADMINS = ['[email protected]'] | ||
LANGUAGES = ['en', 'es'] | ||
MS_TRANSLATOR_KEY = os.environ.get('MS_TRANSLATOR_KEY') | ||
POSTS_PER_PAGE = 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""add language to posts | ||
Revision ID: 2b017edaa91f | ||
Revises: ae346256b650 | ||
Create Date: 2017-10-04 22:48:34.494465 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '2b017edaa91f' | ||
down_revision = 'ae346256b650' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('post', sa.Column('language', sa.String(length=5), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('post', 'language') | ||
# ### end Alembic commands ### |