Skip to content

Commit

Permalink
fix: translating posts with multiple languages
Browse files Browse the repository at this point in the history
  • Loading branch information
ImLunaHey committed Jan 9, 2025
1 parent 13a0b9d commit 253b4ff
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ const PostDropdownMenu = ({ post, setTranslatedText }: { post: BSkyPost; setTran
event.stopPropagation();
const currentLanguage = navigator.language.split('-')[0];
const langs = post.record.langs?.filter((lang) => lang.split('-')[0] !== currentLanguage) ?? [];
toast.info('Translating post text from ' + langs[0] + ' to ' + currentLanguage);
const source = (langs.length === 1 ? langs[0] : 'auto') ?? 'auto';
toast.info('Translating post text from ' + source + ' to ' + currentLanguage);
const response = await fetch(isProd ? 'https://translate.akari.blue' : 'http://localhost:8787', {
method: 'POST',
body: JSON.stringify({
q: post.record.text,
source: (langs.length === 1 ? langs[0] : 'auto') ?? 'auto',
source,
target: navigator.language,
}),
headers: { 'Content-Type': 'application/json' },
Expand Down

0 comments on commit 253b4ff

Please sign in to comment.