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

View file

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