Skip to content

Commit 253b4ff

Browse files
committed
fix: translating posts with multiple languages
1 parent 13a0b9d commit 253b4ff

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/components/PostCard.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ const PostDropdownMenu = ({ post, setTranslatedText }: { post: BSkyPost; setTran
6666
event.stopPropagation();
6767
const currentLanguage = navigator.language.split('-')[0];
6868
const langs = post.record.langs?.filter((lang) => lang.split('-')[0] !== currentLanguage) ?? [];
69-
toast.info('Translating post text from ' + langs[0] + ' to ' + currentLanguage);
69+
const source = (langs.length === 1 ? langs[0] : 'auto') ?? 'auto';
70+
toast.info('Translating post text from ' + source + ' to ' + currentLanguage);
7071
const response = await fetch(isProd ? 'https://translate.akari.blue' : 'http://localhost:8787', {
7172
method: 'POST',
7273
body: JSON.stringify({
7374
q: post.record.text,
74-
source: (langs.length === 1 ? langs[0] : 'auto') ?? 'auto',
75+
source,
7576
target: navigator.language,
7677
}),
7778
headers: { 'Content-Type': 'application/json' },

0 commit comments

Comments
 (0)