Show supported file format and add it to settings

This commit is contained in:
Sébastien Thuret 2021-10-24 16:57:45 +02:00
parent 0da21d96d2
commit ae5d67d966
No known key found for this signature in database
GPG key ID: 4742E2D66933BB08
3 changed files with 19 additions and 2 deletions

View file

@ -12,6 +12,7 @@ from app.language import detect_languages, transliterate
from .api_keys import Database from .api_keys import Database
from .suggestions import Database as SuggestionsDatabase from .suggestions import Database as SuggestionsDatabase
from argostranslatefiles import get_supported_formats
from translatehtml import translate_html from translatehtml import translate_html
def get_json_dict(request): def get_json_dict(request):
@ -94,6 +95,12 @@ def create_app(args):
iter([l for l in languages if l.code == args.frontend_language_target]), None iter([l for l in languages if l.code == args.frontend_language_target]), None
) )
frontend_argos_supported_files_format = []
for file_format in get_supported_formats():
for ff in file_format.supported_file_extensions:
frontend_argos_supported_files_format.append(ff)
# Raise AttributeError to prevent app startup if user input is not valid. # Raise AttributeError to prevent app startup if user input is not valid.
if frontend_argos_language_source is None: if frontend_argos_language_source is None:
raise AttributeError( raise AttributeError(
@ -571,6 +578,11 @@ def create_app(args):
suggestions: suggestions:
type: boolean type: boolean
description: Whether submitting suggestions is enabled. description: Whether submitting suggestions is enabled.
supportedFilesFormat:
type: array
items:
type: string
description: Supported files format
language: language:
type: object type: object
properties: properties:
@ -598,6 +610,7 @@ def create_app(args):
"charLimit": args.char_limit, "charLimit": args.char_limit,
"frontendTimeout": args.frontend_timeout, "frontendTimeout": args.frontend_timeout,
"suggestions": args.suggestions, "suggestions": args.suggestions,
"supportedFilesFormat": frontend_argos_supported_files_format,
"language": { "language": {
"source": { "source": {
"code": frontend_argos_language_source.code, "code": frontend_argos_language_source.code,

View file

@ -31,6 +31,7 @@ document.addEventListener('DOMContentLoaded', function(){
suggestions: false, suggestions: false,
isSuggesting: false, isSuggesting: false,
supportedFilesFormat : [],
translationType: "text" translationType: "text"
}, },
mounted: function(){ mounted: function(){
@ -46,6 +47,7 @@ document.addEventListener('DOMContentLoaded', function(){
self.targetLang = self.settings.language.target.code; self.targetLang = self.settings.language.target.code;
self.charactersLimit = self.settings.charLimit; self.charactersLimit = self.settings.charLimit;
self.suggestions = self.settings.suggestions; self.suggestions = self.settings.suggestions;
self.supportedFilesFormat = self.settings.supportedFilesFormat;
}else { }else {
self.error = "Cannot load /frontend/settings"; self.error = "Cannot load /frontend/settings";
self.loading = false; self.loading = false;
@ -141,7 +143,9 @@ document.addEventListener('DOMContentLoaded', function(){
'', '',
'console.log(await res.json());'].join("\n"); 'console.log(await res.json());'].join("\n");
}, },
supportedFilesFormatFormatted: function() {
return this.supportedFilesFormat.join(', ');
},
isHtml: function(){ isHtml: function(){
return htmlRegex.test(this.inputText); return htmlRegex.test(this.inputText);
}, },

View file

@ -175,7 +175,7 @@
<div class="row" v-if="translationType === 'files'"> <div class="row" v-if="translationType === 'files'">
<div class="file-dropzone"> <div class="file-dropzone">
<div class="dropzone-content"> <div class="dropzone-content">
<span>Supported file format: </span> <span>Supported file format: [[ supportedFilesFormatFormatted ]]</span>
<form action="#"> <form action="#">
<div class="file-field input-field"> <div class="file-field input-field">
<div class="btn"> <div class="btn">