mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2025-05-14 05:52:55 +00:00
Auto self-translation
This commit is contained in:
parent
50c9b62595
commit
3cbbd8ae16
10 changed files with 135 additions and 60 deletions
|
@ -19,6 +19,7 @@ from flask_babel import Babel, gettext as _
|
|||
|
||||
from libretranslate import flood, remove_translated_files, security
|
||||
from libretranslate.language import detect_languages, improve_translation_formatting
|
||||
from libretranslate.locales import get_available_locales
|
||||
|
||||
from .api_keys import Database, RemoteDatabase
|
||||
from .suggestions import Database as SuggestionsDatabase
|
||||
|
@ -1020,11 +1021,11 @@ def create_app(args):
|
|||
@babel.localeselector
|
||||
def get_locale():
|
||||
# TODO: populate from available locales
|
||||
return request.accept_languages.best_match(['en', 'it'])
|
||||
return request.accept_languages.best_match(get_available_locales())
|
||||
|
||||
def gettext_escaped(*args, **kwargs):
|
||||
return _(*args, **kwargs).replace("'", "\\'")
|
||||
app.jinja_env.globals.update(_e=gettext_escaped)
|
||||
app.jinja_env.globals.update(N_=gettext_escaped)
|
||||
|
||||
# Call factory function to create our blueprint
|
||||
swaggerui_blueprint = get_swaggerui_blueprint(SWAGGER_URL, API_URL)
|
||||
|
|
9
libretranslate/locales.py
Normal file
9
libretranslate/locales.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
import os
|
||||
from functools import cache
|
||||
|
||||
@cache
|
||||
def get_available_locales():
|
||||
locales_dir = os.path.join(os.path.dirname(__file__), 'locales')
|
||||
dirs = [os.path.join(locales_dir, d) for d in os.listdir(locales_dir)]
|
||||
|
||||
return ['en'] + [os.path.basename(d) for d in dirs if os.path.isdir(os.path.join(d, 'LC_MESSAGES'))]
|
|
@ -7,24 +7,24 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PROJECT VERSION\n"
|
||||
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
|
||||
"POT-Creation-Date: 2023-01-04 12:27-0500\n"
|
||||
"POT-Creation-Date: 2023-01-04 15:34-0500\n"
|
||||
"PO-Revision-Date: 2023-01-04 12:27-0500\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language: it\n"
|
||||
"Language-Team: it <LL@li.org>\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"Language: it\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=utf-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"Generated-By: Babel 2.11.0\n"
|
||||
|
||||
#: libretranslate/app.py:57
|
||||
#: libretranslate/app.py:58
|
||||
msgid "Invalid JSON format"
|
||||
msgstr ""
|
||||
msgstr "Formato JSON non valido"
|
||||
|
||||
#: libretranslate/app.py:125
|
||||
#: libretranslate/app.py:126
|
||||
msgid "Auto Detect"
|
||||
msgstr ""
|
||||
msgstr "Rilevamento automatico"
|
||||
|
||||
#: libretranslate/templates/app.js.template:31
|
||||
msgid "Copy text"
|
||||
|
@ -33,9 +33,8 @@ msgstr "Copia testo"
|
|||
#: libretranslate/templates/app.js.template:72
|
||||
#, python-format
|
||||
msgid "Cannot load %(url)s"
|
||||
msgstr "Impossibile caricare' %(url)s"
|
||||
msgstr "Non riesco a caricare %(url)s"
|
||||
|
||||
#: libretranslate/templates/index.html:6
|
||||
msgid "Free and Open Source Machine Translation API"
|
||||
msgstr "API di traduzione automatica open source"
|
||||
|
|
@ -28,7 +28,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
|
||||
detectedLangText: "",
|
||||
|
||||
copyTextLabel: '{{ _e("Copy text") }}',
|
||||
copyTextLabel: '{{ N_("Copy text") }}',
|
||||
|
||||
suggestions: false,
|
||||
isSuggesting: false,
|
||||
|
@ -69,7 +69,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
}
|
||||
}
|
||||
} else {
|
||||
self.error = '{{ _e("Cannot load %(url)s", url="/frontend/settings") }}';
|
||||
self.error = '{{ N_("Cannot load %(url)s", url="/frontend/settings") }}';
|
||||
self.loading = false;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue