From cb1c9122372c0a9ebba76c06bc689ae008e8f3b9 Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Fri, 9 Feb 2024 19:03:47 -0500 Subject: [PATCH] localize photo/video counters --- i18n/resources.json | 4 ++++ src/helpers/quote.ts | 4 ++-- src/render/photo.ts | 3 ++- src/render/video.ts | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/i18n/resources.json b/i18n/resources.json index 3058865..5c3da03 100644 --- a/i18n/resources.json +++ b/i18n/resources.json @@ -5,6 +5,10 @@ "quotedFrom": "Quoting {name} (@{screen_name})", "replyingTo": "Replying to @{screen_name}", "threadPartHeader": "A part of @${status.author.screen_name}'s thread", + + "photoCount": "Photo {number} / {total}", + "videoCount": "Video {number} / {total}", + "mediaCount": "Media {number} / {total}", "videoAltTextUnavailable": "{author}'s video. Alt text not available.", "gifAltTextUnavailable": "{author}'s GIF. Alt text not available.", diff --git a/src/helpers/quote.ts b/src/helpers/quote.ts index d3fdacf..c9a0e62 100644 --- a/src/helpers/quote.ts +++ b/src/helpers/quote.ts @@ -1,11 +1,11 @@ -import { Strings } from '../strings'; +import i18next from 'i18next'; /* Helper for Quote Tweets */ export const handleQuote = (quote: APIStatus): string | null => { console.log('Quoting status ', quote.id); let str = `\n`; - str += Strings.QUOTE_TEXT.format({ + str += i18next.t('quotedFrom').format({ name: quote.author?.name || '', screen_name: quote.author?.screen_name || '' }); diff --git a/src/render/photo.ts b/src/render/photo.ts index 62852a2..587400f 100644 --- a/src/render/photo.ts +++ b/src/render/photo.ts @@ -1,3 +1,4 @@ +import i18next from 'i18next'; import { Constants } from '../constants'; import { Strings } from '../strings'; @@ -13,7 +14,7 @@ export const renderPhoto = ( const all = status.media?.all as APIMedia[]; const baseString = - all.length === status.media?.photos?.length ? Strings.PHOTO_COUNT : Strings.MEDIA_COUNT; + all.length === status.media?.photos?.length ? i18next.t('photoCount') : i18next.t('mediaCount'); const photoCounter = baseString.format({ number: String(all.indexOf(photo) + 1), diff --git a/src/render/video.ts b/src/render/video.ts index a07a867..19b4588 100644 --- a/src/render/video.ts +++ b/src/render/video.ts @@ -1,3 +1,4 @@ +import i18next from 'i18next'; import { Constants } from '../constants'; import { Experiment, experimentCheck } from '../experiments'; import { handleQuote } from '../helpers/quote'; @@ -33,7 +34,7 @@ export const renderVideo = ( we'll put an indicator if there are more than one video */ if (all && all.length > 1 && (userAgent?.indexOf('Telegram') ?? 0) > -1) { const baseString = - all.length === status.media?.videos?.length ? Strings.VIDEO_COUNT : Strings.MEDIA_COUNT; + all.length === status.media?.videos?.length ? i18next.t('videoCount') : i18next.t('mediaCount'); const videoCounter = baseString.format({ number: String(all.indexOf(video) + 1), total: String(all.length)