__init__.py 1.69 KB
Newer Older
Timo Heikkilä's avatar
Timo Heikkilä committed
1
2
3
4
5
6
7
from flask import Flask
from flask_bootstrap import Bootstrap
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_babel import Babel
Timo Heikkilä's avatar
Timo Heikkilä committed
8
9
10
from flask import request
from flask import session
from flask import flash
Timo Heikkilä's avatar
Timo Heikkilä committed
11
12
13


app = Flask(__name__)
Timo Heikkilä's avatar
Timo Heikkilä committed
14
15
#app.config['BABEL_DEFAULT_LOCALE'] = 'fin'
#app.config['BABEL_TRANSLATION_DIRECTORIES'] ='C:/Users/Timo/git/pet-rating/app/translations'
Timo Heikkilä's avatar
Timo Heikkilä committed
16
17
babel = Babel(app)

Timo Heikkilä's avatar
Timo Heikkilä committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@babel.localeselector
def get_locale():
    if request.args.get('lang'):

        session['lang'] = request.args.get('lang')
        
        if session['lang'] == 'en':
            session['language'] = 'English'

        if session['lang'] == 'fi':
            session['language'] = 'Finnish'

        if session['lang'] == 'fa':
            session['language'] = 'Persian'

        if session['lang'] == 'el':
            session['language'] = 'Greek'
            
        if session['lang'] == 'it':
            session['language'] = 'Italian'
    
        if session['lang'] == 'zh':
            session['language'] = 'Chinese'

    
    
    return session.get('lang', 'en')



"""
@babel.localeselector
def get_locale():
Timo Heikkilä's avatar
Timo Heikkilä committed
51

Timo Heikkilä's avatar
Timo Heikkilä committed
52
53
54
55
56
57
58
59
60
    if session:
        
        return 'fi'
        
    else:
        
        return 'en'
"""
"""
Timo Heikkilä's avatar
Timo Heikkilä committed
61
62
@babel.localeselector
def get_locale():
Timo Heikkilä's avatar
Timo Heikkilä committed
63
64
    return request.accept_languages.best_match(app.config['LANGUAGES'])
"""
Timo Heikkilä's avatar
Timo Heikkilä committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81


#mariabd mysql portti 3306 tarkista?

Bootstrap(app)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
login = LoginManager(app)
login.login_view = 'login'


app.secret_key = 'random string'
"""app.secret_key = os.urandom(24)"""


from app import routes, models