Quick-translate from timeline to Post page

This commit is contained in:
Lim Chee Aun 2023-05-03 10:22:15 +08:00
parent 0e1579ebf1
commit 8519f68e9f
2 changed files with 23 additions and 10 deletions

View file

@ -79,6 +79,7 @@ function Status({
readOnly,
contentTextWeight,
enableTranslate,
forceTranslate: _forceTranslate,
previewMode,
allowFilters,
onMediaClick,
@ -233,7 +234,7 @@ function Status({
);
}
const [forceTranslate, setForceTranslate] = useState(false);
const [forceTranslate, setForceTranslate] = useState(_forceTranslate);
const targetLanguage = getTranslateTargetLanguage(true);
const contentTranslationHideLanguages =
snapStates.settings.contentTranslationHideLanguages || [];
@ -403,6 +404,14 @@ function Status({
}
};
const differentLanguage =
language &&
language !== targetLanguage &&
!match([language], [targetLanguage]) &&
!contentTranslationHideLanguages.find(
(l) => language === l || match([language], [l]),
);
const menuInstanceRef = useRef();
const StatusMenuItems = (
<>
@ -530,7 +539,7 @@ function Status({
</div>
</>
)}
{enableTranslate && (
{enableTranslate ? (
<MenuItem
disabled={forceTranslate}
onClick={() => {
@ -540,6 +549,15 @@ function Status({
<Icon icon="translate" />
<span>Translate</span>
</MenuItem>
) : (
(!language || differentLanguage) && (
<MenuLink
to={`${instance ? `/${instance}` : ''}/s/${id}?translate=1`}
>
<Icon icon="translate" />
<span>Translate</span>
</MenuLink>
)
)}
{((!isSizeLarge && sameInstance) || enableTranslate) && <MenuDivider />}
<MenuItem href={url} target="_blank">
@ -996,14 +1014,7 @@ function Status({
}}
/>
)}
{((enableTranslate &&
!!content.trim() &&
language &&
language !== targetLanguage &&
!match([language], [targetLanguage]) &&
!contentTranslationHideLanguages.find(
(l) => language === l || match([language], [l]),
)) ||
{((enableTranslate && !!content.trim() && differentLanguage) ||
forceTranslate) && (
<TranslationBlock
forceTranslate={forceTranslate}

View file

@ -149,6 +149,7 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
const mediaParam = searchParams.get('media');
const showMedia = parseInt(mediaParam, 10) > 0;
const [viewMode, setViewMode] = useState(searchParams.get('view'));
const translate = !!parseInt(searchParams.get('translate'));
const { masto, instance } = api({ instance: propInstance });
const {
masto: currentMasto,
@ -801,6 +802,7 @@ function StatusThread({ id, closeLink = '/', instance: propInstance }) {
withinContext
size="l"
enableTranslate
forceTranslate={translate}
/>
</InView>
{uiState !== 'loading' && !authenticated ? (