version advance + i18n change
This commit is contained in:
parent
4524436a5b
commit
b09d32d5e8
6 changed files with 90 additions and 35 deletions
|
|
@ -1,5 +1,10 @@
|
||||||
# What’s New
|
# What’s New
|
||||||
|
|
||||||
|
## 0.7
|
||||||
|
|
||||||
|
+ Added `python-i18n` as a dependency. Therefore, i18n changed format, using JSON files now.
|
||||||
|
+ Like it or not, now gzip library is required.
|
||||||
|
|
||||||
## 0.6
|
## 0.6
|
||||||
|
|
||||||
+ Added support for database URLs: you can now specify the URL of the database
|
+ Added support for database URLs: you can now specify the URL of the database
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ suitable as a community or team knowledge base.
|
||||||
+ **Python** 3.6+.
|
+ **Python** 3.6+.
|
||||||
+ **Flask** web framework (and Flask-Login / Flask-WTF extensions).
|
+ **Flask** web framework (and Flask-Login / Flask-WTF extensions).
|
||||||
+ **Peewee** ORM.
|
+ **Peewee** ORM.
|
||||||
|
+ **Markdown** for page rendering.
|
||||||
|
+ **Python-I18n**.
|
||||||
|
|
||||||
### Optional requirements
|
### Optional requirements
|
||||||
|
|
||||||
|
|
|
||||||
40
app.py
40
app.py
|
|
@ -24,16 +24,10 @@ import csv, datetime, hashlib, html, importlib, json, markdown, os, random, \
|
||||||
from functools import lru_cache, partial
|
from functools import lru_cache, partial
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
try:
|
import i18n
|
||||||
import gzip
|
import gzip
|
||||||
except ImportError:
|
|
||||||
gzip = None
|
|
||||||
try:
|
|
||||||
from slugify import slugify
|
|
||||||
except ImportError:
|
|
||||||
slugify = None
|
|
||||||
|
|
||||||
__version__ = '0.6'
|
__version__ = '0.7-dev'
|
||||||
|
|
||||||
#### CONSTANTS ####
|
#### CONSTANTS ####
|
||||||
|
|
||||||
|
|
@ -428,26 +422,12 @@ def remove_tags(text, convert=True, headings=True):
|
||||||
|
|
||||||
#### I18N ####
|
#### I18N ####
|
||||||
|
|
||||||
lang_poses = {'en': 1, 'en-US': 1, 'it': 2, 'it-IT': 2}
|
i18n.load_path.append(os.path.join(APP_BASE_DIR, 'i18n'))
|
||||||
|
i18n.set('file_format', 'json')
|
||||||
def read_strings():
|
|
||||||
with open(APP_BASE_DIR + '/strings.csv', encoding='utf-8') as f:
|
|
||||||
return csv.reader(f)
|
|
||||||
|
|
||||||
@lru_cache(maxsize=1000)
|
|
||||||
def get_string(lang, name):
|
|
||||||
with open(APP_BASE_DIR + '/strings.csv', encoding='utf-8') as f:
|
|
||||||
for line in csv.reader(f):
|
|
||||||
if not line[0] or line[0].startswith('#'):
|
|
||||||
continue
|
|
||||||
if line[0] == name:
|
|
||||||
ln = lang_poses[lang]
|
|
||||||
if len(line) > ln and line[ln]:
|
|
||||||
return line[ln]
|
|
||||||
elif len(line) > 1:
|
|
||||||
return line[1]
|
|
||||||
return '(' + name + ')'
|
|
||||||
|
|
||||||
|
def get_string(loc, s):
|
||||||
|
i18n.set('locale', loc)
|
||||||
|
return i18n.t('salvi.' + s)
|
||||||
|
|
||||||
#### APPLICATION CONFIG ####
|
#### APPLICATION CONFIG ####
|
||||||
|
|
||||||
|
|
@ -479,7 +459,6 @@ def _before_request():
|
||||||
for l in request.headers.get('accept-language', 'it,en').split(','):
|
for l in request.headers.get('accept-language', 'it,en').split(','):
|
||||||
if ';' in l:
|
if ';' in l:
|
||||||
l, _ = l.split(';')
|
l, _ = l.split(';')
|
||||||
if l in lang_poses:
|
|
||||||
lang = l
|
lang = l
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
@ -797,9 +776,6 @@ def listtag(tag, page=1):
|
||||||
return render_template('listtag.html', tagname=tag, tagged_notes=page_query,
|
return render_template('listtag.html', tagname=tag, tagged_notes=page_query,
|
||||||
page_n=page, total_count=general_query.count(), min=min)
|
page_n=page, total_count=general_query.count(), min=min)
|
||||||
|
|
||||||
@app.route('/media/<path:fp>')
|
|
||||||
def media(fp):
|
|
||||||
return send_from_directory(UPLOAD_DIR, fp)
|
|
||||||
|
|
||||||
# symbolic route as of v0.5
|
# symbolic route as of v0.5
|
||||||
@app.route('/upload/', methods=['GET'])
|
@app.route('/upload/', methods=['GET'])
|
||||||
|
|
@ -811,7 +787,7 @@ def stats():
|
||||||
return render_template('stats.html',
|
return render_template('stats.html',
|
||||||
notes_count=Page.select().count(),
|
notes_count=Page.select().count(),
|
||||||
notes_with_url=Page.select().where(Page.url != None).count(),
|
notes_with_url=Page.select().where(Page.url != None).count(),
|
||||||
upload_count=Upload.select().count(),
|
#upload_count=Upload.select().count(),
|
||||||
revision_count=PageRevision.select().count()
|
revision_count=PageRevision.select().count()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
33
i18n/salvi.en.json
Normal file
33
i18n/salvi.en.json
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"en": {
|
||||||
|
"welcome": "Welcome to {0}!",
|
||||||
|
"homepage": "Homepage",
|
||||||
|
"latest-notes": "Latest notes",
|
||||||
|
"latest-uploads": "Latest uploads",
|
||||||
|
"new-note": "New note",
|
||||||
|
"upload-file": "Upload file",
|
||||||
|
"easter-date-calc": "Easter date calculation",
|
||||||
|
"easter": "Easter",
|
||||||
|
"other-dates": "Other dates",
|
||||||
|
"jump-to-actions": "Jump to actions",
|
||||||
|
"last-changed": "Last changed",
|
||||||
|
"page-id": "Page ID",
|
||||||
|
"action-edit": "Edit",
|
||||||
|
"action-history": "History",
|
||||||
|
"tags": "Tags",
|
||||||
|
"old-revision-notice": "Showing an old revision of the page as of",
|
||||||
|
"notes-tagged": "Notes tagged",
|
||||||
|
"include-tags": "Include tags",
|
||||||
|
"notes-tagged-empty": "None found :(",
|
||||||
|
"search-no-results": "No results for",
|
||||||
|
"random-page": "Random page",
|
||||||
|
"search": "Search",
|
||||||
|
"year": "Year",
|
||||||
|
"calculate": "Calculate",
|
||||||
|
"show-all": "Show all",
|
||||||
|
"just-now": "just now",
|
||||||
|
"n-minutes-ago": "{0} minutes ago",
|
||||||
|
"n-hours-ago": "{0} hours ago",
|
||||||
|
"n-days-ago": "{0} days ago"
|
||||||
|
}
|
||||||
|
}
|
||||||
33
i18n/salvi.it.json
Normal file
33
i18n/salvi.it.json
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"it": {
|
||||||
|
"welcome": "Benvenuti in {0}!",
|
||||||
|
"homepage": "Pagina iniziale",
|
||||||
|
"latest-notes": "Note pi\u00f9 recenti",
|
||||||
|
"latest-uploads": "Caricamenti pi\u00f9 recenti",
|
||||||
|
"new-note": "Crea nota",
|
||||||
|
"upload-file": "Carica immagine",
|
||||||
|
"easter-date-calc": "Calcolo della data di Pasqua",
|
||||||
|
"easter": "Pasqua",
|
||||||
|
"other-dates": "Altre date",
|
||||||
|
"jump-to-actions": "Salta alle azioni",
|
||||||
|
"last-changed": "Ultima modifica",
|
||||||
|
"page-id": "ID pagina",
|
||||||
|
"action-edit": "Modifica",
|
||||||
|
"action-history": "Cronologia",
|
||||||
|
"tags": "Etichette",
|
||||||
|
"old-revision-notice": "\u00c8 mostrata una revisione vecchia della pagina, risalente al",
|
||||||
|
"notes-tagged": "Note con etichetta",
|
||||||
|
"include-tags": "Includi etichette",
|
||||||
|
"notes-tagged-empty": "Non c\u2019\u00e8 nulla :(",
|
||||||
|
"search-no-results": "Nessun risultato per",
|
||||||
|
"random-page": "Pagina casuale",
|
||||||
|
"search": "Cerca",
|
||||||
|
"year": "Anno",
|
||||||
|
"calculate": "Calcola",
|
||||||
|
"show-all": "Mostra tutto",
|
||||||
|
"just-now": "poco fa",
|
||||||
|
"n-minutes-ago": "{0} minuti fa",
|
||||||
|
"n-hours-ago": "{0} ore fa",
|
||||||
|
"n-days-ago": "{0} giorni fa"
|
||||||
|
}
|
||||||
|
}
|
||||||
6
requirements.txt
Normal file
6
requirements.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
flask
|
||||||
|
peewee
|
||||||
|
markdown
|
||||||
|
flask-login
|
||||||
|
flask-wtf
|
||||||
|
python-i18n
|
||||||
Loading…
Add table
Add a link
Reference in a new issue