@@ -38,6 +38,7 @@ def collection_list():
@collections_app.route('/backstage/collection/create', methods=['POST'])
def create():
form = CollectionCreateForm()
+ eng_name = get_trans_title_url_name(form.title.data)
front_matter = '''---
title: "{}"\n\
date: {}\n\
@@ -50,11 +51,11 @@ description: "{}"\n\
get_now_time(),
'false',
'collection',
- '/collection/{}'.format(get_trans_title_url_name(form.title.data)),
+ '/collection/{}'.format(eng_name),
form.image.data.filename,
form.description.data)
data = {'frontMatter': front_matter,
- 'name': request.form['title'],
+ 'name': eng_name,
'type': 'collection'}
return create_content(data, form.image.data)
@@ -1,10 +1,14 @@
-from googletrans import Translator
+# coding:utf-8
+from translate import Translator
+#from googletrans import Translator
from datetime import datetime, timezone, timedelta
def translate(text):
- result = Translator().translate(text, dest='en')
- return result.text
+ #result = Translator().translate(text, dest='en')
+ translator= Translator(from_lang="zh-tw",to_lang="en")
+ result = translator.translate(text)
+ return str(result).lower()
def get_now_time():
@@ -37,7 +37,10 @@ def remove_content():
def get_trans_title_url_name(title):
- return translate(title).replace(' ', '_')
+ tary = translate(title).replace('$','_').replace('&','_').replace('+','_').replace(',','_').replace('/','_').replace(':','_').replace(';','_').replace('=','_').replace('?','_').replace('@','_').replace(' ','_').split('_')
+ while("" in tary) :
+ tary.remove("")
+ return ('_'.join(tary))
#return translate(title).replace(' ', '_')