diff --git a/CHANGELOG.md b/CHANGELOG.md index cc6e95d..df122c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 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 + Added support for database URLs: you can now specify the URL of the database diff --git a/README.md b/README.md index 3864c25..152761c 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ suitable as a community or team knowledge base. + **Python** 3.6+. + **Flask** web framework (and Flask-Login / Flask-WTF extensions). + **Peewee** ORM. ++ **Markdown** for page rendering. ++ **Python-I18n**. ### Optional requirements diff --git a/app.py b/app.py index b2a35e2..489bd62 100644 --- a/app.py +++ b/app.py @@ -24,16 +24,10 @@ import csv, datetime, hashlib, html, importlib, json, markdown, os, random, \ from functools import lru_cache, partial from urllib.parse import quote from configparser import ConfigParser -try: - import gzip -except ImportError: - gzip = None -try: - from slugify import slugify -except ImportError: - slugify = None +import i18n +import gzip -__version__ = '0.6' +__version__ = '0.7-dev' #### CONSTANTS #### @@ -428,26 +422,12 @@ def remove_tags(text, convert=True, headings=True): #### I18N #### -lang_poses = {'en': 1, 'en-US': 1, 'it': 2, 'it-IT': 2} - -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 + ')' +i18n.load_path.append(os.path.join(APP_BASE_DIR, 'i18n')) +i18n.set('file_format', 'json') +def get_string(loc, s): + i18n.set('locale', loc) + return i18n.t('salvi.' + s) #### APPLICATION CONFIG #### @@ -479,9 +459,8 @@ def _before_request(): for l in request.headers.get('accept-language', 'it,en').split(','): if ';' in l: l, _ = l.split(';') - if l in lang_poses: - lang = l - break + lang = l + break else: lang = 'en' g.lang = lang @@ -797,9 +776,6 @@ def listtag(tag, page=1): return render_template('listtag.html', tagname=tag, tagged_notes=page_query, page_n=page, total_count=general_query.count(), min=min) -@app.route('/media/') -def media(fp): - return send_from_directory(UPLOAD_DIR, fp) # symbolic route as of v0.5 @app.route('/upload/', methods=['GET']) @@ -811,7 +787,7 @@ def stats(): return render_template('stats.html', notes_count=Page.select().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() ) diff --git a/i18n/salvi.en.json b/i18n/salvi.en.json new file mode 100644 index 0000000..7f81eec --- /dev/null +++ b/i18n/salvi.en.json @@ -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" + } +} \ No newline at end of file diff --git a/i18n/salvi.it.json b/i18n/salvi.it.json new file mode 100644 index 0000000..224d179 --- /dev/null +++ b/i18n/salvi.it.json @@ -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" + } +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..18bfb00 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +flask +peewee +markdown +flask-login +flask-wtf +python-i18n \ No newline at end of file