use external json file
This commit is contained in:
parent
7f98e9256b
commit
4690b7f715
@ -1,11 +1,26 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
def get_dictionary(filename='fastionary/enfr.json'):
|
||||||
|
print (filename)
|
||||||
|
if os.path.exists(filename):
|
||||||
|
with open (filename, 'r') as json_file:
|
||||||
|
dictionary = json.load(json_file)
|
||||||
|
else:
|
||||||
|
dictionary = {}
|
||||||
|
# what happens if dictionary not found?
|
||||||
|
# return dummy dictionary?
|
||||||
|
# display that no dictionary file was found
|
||||||
|
# where should this be handled
|
||||||
|
return dictionary
|
||||||
|
|
||||||
def get_translations(word):
|
def get_translations(word):
|
||||||
dictionary={'yes':'oui', 'no':'non', 'cheese':'fromage', 'yesterday':'hier', 'tomorrow':'demain', 'yes man':'jasager'}
|
dictionary=get_dictionary()
|
||||||
translation = None
|
translation = None
|
||||||
if word != None or word != '':
|
if word != None or word != '':
|
||||||
translation = dictionary.get(word)
|
translation = dictionary.get(word)
|
||||||
|
|||||||
1
fastionary/enfr.json
Normal file
1
fastionary/enfr.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"yes":"oui", "no":"non", "cheese":"fromage", "yesterday":"hier", "tomorrow":"demain", "yes man":"jasager"}
|
||||||
Loading…
Reference in New Issue
Block a user