Skip to content

Commit 4d63125

Browse files
committed
Fix improve_formatting
1 parent baa13d6 commit 4d63125

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ You can use the LTEngine API using the following bindings:
143143
- [ ] Better language detection for short texts (port [LexiLang](https://github.com/LibreTranslate/LexiLang) to Rust)
144144
- [ ] Test/add more LLM models aside from Gemma3
145145
- [ ] Create comparative benchmarks between LTEngine and proprietary software.
146-
- [ ] Normalize punctuation, uppercase/lowercase
147146
- [ ] Add support for command line inference (run `./ltengine translate` as a command line app separate from `./ltengine server`)
148147
- [ ] Make ltengine available as a library, possibly creating bindings for other languages like Python.
149148
- [ ] Automated builds / CI

ltengine/src/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,19 @@ fn check_params(body: &TranslateRequest, args: &Args, required_params: &[(&str,
142142
}
143143

144144
fn improve_formatting(q: &String, translation: &String) -> String {
145+
let t = translation.trim().to_string();
146+
145147
if q.len() == 0 {
146148
return String::new();
147149
}
148150

149-
if translation.len() == 0 {
150-
return q.clone()
151+
if t.len() == 0 {
152+
return q.clone();
151153
}
152154

153155
let q_last_char = q.chars().rev().next().unwrap();
154-
let translation_last_char = translation.chars().rev().next().unwrap();
155-
let mut result = translation.clone();
156+
let translation_last_char = t.chars().rev().next().unwrap();
157+
let mut result = t.clone();
156158

157159
const PUNCTUATION_CHARS: [char; 6] = ['!', '?', '.', ',', ';', '。'];
158160
if PUNCTUATION_CHARS.contains(&q_last_char){
@@ -177,9 +179,9 @@ fn improve_formatting(q: &String, translation: &String) -> String {
177179

178180
if let (Some(q0), Some(r0)) = (q.chars().next(), result.chars().next()) {
179181
if q0.is_lowercase() && r0.is_uppercase() {
180-
result.replace_range(0..r0.len_utf8(), &r0.to_uppercase().to_string());
181-
}else if q0.is_uppercase() && r0.is_lowercase() {
182182
result.replace_range(0..r0.len_utf8(), &r0.to_lowercase().to_string());
183+
}else if q0.is_uppercase() && r0.is_lowercase() {
184+
result.replace_range(0..r0.len_utf8(), &r0.to_uppercase().to_string());
183185
}
184186
}
185187

0 commit comments

Comments
 (0)