Update README.md
Browse files
README.md
CHANGED
|
@@ -1,197 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
- ✨ Traduzione automatica dall'italiano a più di 30 lingue
|
| 8 |
-
- 🔧 Preserva i tag HTML e i placeholder con parentesi graffe
|
| 9 |
-
- 🚀 API REST facile da usare
|
| 10 |
-
- 🎯 Ottimizzato per oggetti locale di applicazioni web
|
| 11 |
-
- 🏠 Completamente locale, nessun servizio esterno richiesto
|
| 12 |
-
|
| 13 |
-
## Installazione
|
| 14 |
-
|
| 15 |
-
1. Clona il repository:
|
| 16 |
-
|
| 17 |
-
```bash
|
| 18 |
-
git clone <repository-url>
|
| 19 |
-
cd locale_translate_server
|
| 20 |
-
```
|
| 21 |
-
|
| 22 |
-
2. Installa le dipendenze:
|
| 23 |
-
|
| 24 |
-
```bash
|
| 25 |
-
pip install -r requirements.txt
|
| 26 |
-
```
|
| 27 |
-
|
| 28 |
-
3. Avvia il server:
|
| 29 |
-
|
| 30 |
-
```bash
|
| 31 |
-
python app.py
|
| 32 |
-
```
|
| 33 |
-
|
| 34 |
-
Il server sarà disponibile su `http://localhost:8000`
|
| 35 |
-
|
| 36 |
-
## Uso dell'API
|
| 37 |
-
|
| 38 |
-
### Endpoint Principali
|
| 39 |
-
|
| 40 |
-
#### 1. Traduci Oggetti Locale - `POST /translate`
|
| 41 |
-
|
| 42 |
-
Traduce un oggetto JSON contenente locales dall'italiano alla lingua specificata.
|
| 43 |
-
|
| 44 |
-
**Parametri:**
|
| 45 |
-
|
| 46 |
-
- `target_language` (query parameter): Codice della lingua target (es: "en", "fr", "de")
|
| 47 |
-
|
| 48 |
-
**Body della richiesta:**
|
| 49 |
-
|
| 50 |
-
```json
|
| 51 |
-
{
|
| 52 |
-
"locales": {
|
| 53 |
-
"welcome_message": "Benvenuto nella nostra applicazione!",
|
| 54 |
-
"button_save": "Salva",
|
| 55 |
-
"error_required": "Questo campo è obbligatorio",
|
| 56 |
-
"html_content": "<p>Clicca <a href='#'>qui</a> per continuare</p>",
|
| 57 |
-
"template_message": "Ciao {name}, hai {count} nuovi messaggi"
|
| 58 |
-
}
|
| 59 |
-
}
|
| 60 |
-
```
|
| 61 |
-
|
| 62 |
-
**Esempio di richiesta:**
|
| 63 |
-
|
| 64 |
-
```bash
|
| 65 |
-
curl -X POST "http://localhost:8000/translate?target_language=en" \
|
| 66 |
-
-H "Content-Type: application/json" \
|
| 67 |
-
-d '{
|
| 68 |
-
"locales": {
|
| 69 |
-
"welcome": "Benvenuto!",
|
| 70 |
-
"save_btn": "Salva documento"
|
| 71 |
-
}
|
| 72 |
-
}'
|
| 73 |
-
```
|
| 74 |
-
|
| 75 |
-
**Risposta:**
|
| 76 |
-
|
| 77 |
-
```json
|
| 78 |
-
{
|
| 79 |
-
"translated_locales": {
|
| 80 |
-
"welcome": "Welcome!",
|
| 81 |
-
"save_btn": "Save document"
|
| 82 |
-
},
|
| 83 |
-
"source_language": "it",
|
| 84 |
-
"target_language": "en"
|
| 85 |
-
}
|
| 86 |
-
```
|
| 87 |
-
|
| 88 |
-
#### 2. Traduci Singolo Testo - `POST /translate-single`
|
| 89 |
-
|
| 90 |
-
Traduce un singolo testo per test rapidi.
|
| 91 |
-
|
| 92 |
-
**Parametri:**
|
| 93 |
-
|
| 94 |
-
- `text` (query parameter): Testo in italiano da tradurre
|
| 95 |
-
- `target_language` (query parameter): Codice della lingua target
|
| 96 |
-
|
| 97 |
-
**Esempio:**
|
| 98 |
-
|
| 99 |
-
```bash
|
| 100 |
-
curl -X POST "http://localhost:8000/translate-single?text=Ciao mondo&target_language=en"
|
| 101 |
-
```
|
| 102 |
-
|
| 103 |
-
#### 3. Lingue Supportate - `GET /languages`
|
| 104 |
-
|
| 105 |
-
Restituisce la lista delle lingue supportate.
|
| 106 |
-
|
| 107 |
-
**Risposta:**
|
| 108 |
-
|
| 109 |
-
```json
|
| 110 |
-
{
|
| 111 |
-
"supported_languages": ["en", "fr", "de", "es", "pt", "ru", "ja", "ko", "zh", ...]
|
| 112 |
-
}
|
| 113 |
-
```
|
| 114 |
-
|
| 115 |
-
### Lingue Supportate
|
| 116 |
-
|
| 117 |
-
Il servizio supporta traduzione verso le seguenti lingue:
|
| 118 |
-
|
| 119 |
-
- **en** - English
|
| 120 |
-
- **fr** - French
|
| 121 |
-
- **de** - German
|
| 122 |
-
- **es** - Spanish
|
| 123 |
-
- **pt** - Portuguese
|
| 124 |
-
- **ru** - Russian
|
| 125 |
-
- **ja** - Japanese
|
| 126 |
-
- **ko** - Korean
|
| 127 |
-
- **zh** - Chinese
|
| 128 |
-
- **ar** - Arabic
|
| 129 |
-
- **hi** - Hindi
|
| 130 |
-
- **nl** - Dutch
|
| 131 |
-
- **sv** - Swedish
|
| 132 |
-
- **da** - Danish
|
| 133 |
-
- **no** - Norwegian
|
| 134 |
-
- **fi** - Finnish
|
| 135 |
-
- **pl** - Polish
|
| 136 |
-
- **cs** - Czech
|
| 137 |
-
- **hu** - Hungarian
|
| 138 |
-
- **ro** - Romanian
|
| 139 |
-
- **bg** - Bulgarian
|
| 140 |
-
- **hr** - Croatian
|
| 141 |
-
- **sk** - Slovak
|
| 142 |
-
- **sl** - Slovenian
|
| 143 |
-
- **et** - Estonian
|
| 144 |
-
- **lv** - Latvian
|
| 145 |
-
- **lt** - Lithuanian
|
| 146 |
-
- **mt** - Maltese
|
| 147 |
-
- **el** - Greek
|
| 148 |
-
- **tr** - Turkish
|
| 149 |
-
|
| 150 |
-
## Caratteristiche Speciali
|
| 151 |
-
|
| 152 |
-
### Preservazione di HTML e Placeholder
|
| 153 |
-
|
| 154 |
-
Il servizio preserva automaticamente:
|
| 155 |
-
|
| 156 |
-
1. **Tag HTML**: `<p>`, `<a>`, `<strong>`, etc.
|
| 157 |
-
2. **Placeholder con parentesi graffe**: `{name}`, `{count}`, `{date}`, etc.
|
| 158 |
-
|
| 159 |
-
**Esempio:**
|
| 160 |
-
|
| 161 |
-
```
|
| 162 |
-
Input: "Ciao {name}, hai <strong>{count}</strong> messaggi"
|
| 163 |
-
Output: "Hello {name}, you have <strong>{count}</strong> messages"
|
| 164 |
-
```
|
| 165 |
-
|
| 166 |
-
## Configurazione
|
| 167 |
-
|
| 168 |
-
Puoi configurare il servizio tramite variabili d'ambiente:
|
| 169 |
-
|
| 170 |
-
- `MODEL_NAME`: Nome del modello T5 da utilizzare (default: "google/t5-v1_1-base")
|
| 171 |
-
- `ENVIRONMENT`: Ambiente di esecuzione (default: "development")
|
| 172 |
-
- `DEBUG`: Abilita debug logging (default: "true")
|
| 173 |
-
|
| 174 |
-
## Documentazione API
|
| 175 |
-
|
| 176 |
-
Una volta avviato il server, puoi accedere alla documentazione interativa Swagger UI su:
|
| 177 |
-
|
| 178 |
-
`http://localhost:8000/docs`
|
| 179 |
-
|
| 180 |
-
## Performance
|
| 181 |
-
|
| 182 |
-
Il modello T5-base offre un buon bilanciamento tra qualità di traduzione e velocità. Per applicazioni che richiedono traduzione di alta qualità, puoi configurare un modello più grande tramite la variabile d'ambiente `MODEL_NAME`:
|
| 183 |
-
|
| 184 |
-
```bash
|
| 185 |
-
export MODEL_NAME="google/t5-v1_1-large"
|
| 186 |
-
python app.py
|
| 187 |
-
```
|
| 188 |
-
|
| 189 |
-
## Docker
|
| 190 |
-
|
| 191 |
-
Il progetto include un Dockerfile per facilità di deployment:
|
| 192 |
-
|
| 193 |
-
```bash
|
| 194 |
-
docker build -t locale-translate-server .
|
| 195 |
-
docker run -p 8000:8000 locale-translate-server
|
| 196 |
-
```
|
| 197 |
-
sdk: docker
|
|
|
|
| 1 |
+
title: locale translate server
|
| 2 |
+
emoji: 🐨
|
| 3 |
+
colorFrom: indigo
|
| 4 |
+
colorTo: purple
|
| 5 |
+
sdk: docker
|
| 6 |
+
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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