From 8b85d4c941e5fc3b1fc8f0f3c6be83658e58c942 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 11 Feb 2024 21:30:31 -0600 Subject: [PATCH] Translate Frontend Utilities Closes #4096 Co-Authored-By: Stevie Robinson --- .../Artist/monitorNewItemsOptions.js | 6 +-- .../src/Utilities/Artist/monitorOptions.js | 51 ++++++++++++++++--- frontend/src/Utilities/Date/formatDateTime.js | 12 +++-- .../src/Utilities/Date/formatShortTimeSpan.js | 7 +-- frontend/src/Utilities/Date/formatTimeSpan.js | 3 +- .../src/Utilities/Date/getRelativeDate.js | 7 +-- frontend/src/Utilities/Number/formatAge.js | 8 +-- src/NzbDrone.Core/Localization/Core/en.json | 29 +++++++++-- 8 files changed, 96 insertions(+), 27 deletions(-) diff --git a/frontend/src/Utilities/Artist/monitorNewItemsOptions.js b/frontend/src/Utilities/Artist/monitorNewItemsOptions.js index 2f352be3a..f45095b6e 100644 --- a/frontend/src/Utilities/Artist/monitorNewItemsOptions.js +++ b/frontend/src/Utilities/Artist/monitorNewItemsOptions.js @@ -4,19 +4,19 @@ const monitorNewItemsOptions = [ { key: 'all', get value() { - return translate('AllAlbums'); + return translate('MonitorAllAlbums'); } }, { key: 'none', get value() { - return translate('None'); + return translate('MonitorNoNewAlbums'); } }, { key: 'new', get value() { - return translate('New'); + return translate('MonitorNewAlbums'); } } ]; diff --git a/frontend/src/Utilities/Artist/monitorOptions.js b/frontend/src/Utilities/Artist/monitorOptions.js index b5e942ae6..a06a79a96 100644 --- a/frontend/src/Utilities/Artist/monitorOptions.js +++ b/frontend/src/Utilities/Artist/monitorOptions.js @@ -1,11 +1,48 @@ +import translate from 'Utilities/String/translate'; + const monitorOptions = [ - { key: 'all', value: 'All Albums' }, - { key: 'future', value: 'Future Albums' }, - { key: 'missing', value: 'Missing Albums' }, - { key: 'existing', value: 'Existing Albums' }, - { key: 'first', value: 'Only First Album' }, - { key: 'latest', value: 'Only Latest Album' }, - { key: 'none', value: 'None' } + { + key: 'all', + get value() { + return translate('MonitorAllAlbums'); + } + }, + { + key: 'future', + get value() { + return translate('MonitorFutureAlbums'); + } + }, + { + key: 'missing', + get value() { + return translate('MonitorMissingAlbums'); + } + }, + { + key: 'existing', + get value() { + return translate('MonitorExistingAlbums'); + } + }, + { + key: 'first', + get value() { + return translate('MonitorFirstAlbum'); + } + }, + { + key: 'latest', + get value() { + return translate('MonitorLastestAlbum'); + } + }, + { + key: 'none', + get value() { + return translate('MonitorNoAlbums'); + } + } ]; export default monitorOptions; diff --git a/frontend/src/Utilities/Date/formatDateTime.js b/frontend/src/Utilities/Date/formatDateTime.js index f36f4f3e0..fb50230e1 100644 --- a/frontend/src/Utilities/Date/formatDateTime.js +++ b/frontend/src/Utilities/Date/formatDateTime.js @@ -1,4 +1,5 @@ import moment from 'moment'; +import translate from 'Utilities/String/translate'; import formatTime from './formatTime'; import isToday from './isToday'; import isTomorrow from './isTomorrow'; @@ -10,15 +11,15 @@ function getRelativeDay(date, includeRelativeDate) { } if (isYesterday(date)) { - return 'Yesterday, '; + return translate('Yesterday'); } if (isToday(date)) { - return 'Today, '; + return translate('Today'); } if (isTomorrow(date)) { - return 'Tomorrow, '; + return translate('Tomorrow'); } return ''; @@ -33,7 +34,10 @@ function formatDateTime(date, dateFormat, timeFormat, { includeSeconds = false, const formattedDate = moment(date).format(dateFormat); const formattedTime = formatTime(date, timeFormat, { includeMinuteZero: true, includeSeconds }); - return `${relativeDay}${formattedDate} ${formattedTime}`; + if (relativeDay) { + return translate('FormatDateTimeRelative', { relativeDay, formattedDate, formattedTime }); + } + return translate('FormatDateTime', { formattedDate, formattedTime }); } export default formatDateTime; diff --git a/frontend/src/Utilities/Date/formatShortTimeSpan.js b/frontend/src/Utilities/Date/formatShortTimeSpan.js index c14251e68..148dc2627 100644 --- a/frontend/src/Utilities/Date/formatShortTimeSpan.js +++ b/frontend/src/Utilities/Date/formatShortTimeSpan.js @@ -1,4 +1,5 @@ import moment from 'moment'; +import translate from 'Utilities/String/translate'; function formatShortTimeSpan(timeSpan) { if (!timeSpan) { @@ -12,14 +13,14 @@ function formatShortTimeSpan(timeSpan) { const seconds = Math.floor(duration.asSeconds()); if (hours > 0) { - return `${hours} hour(s)`; + return translate('FormatShortTimeSpanHours', { hours }); } if (minutes > 0) { - return `${minutes} minute(s)`; + return translate('FormatShortTimeSpanMinutes', { minutes }); } - return `${seconds} second(s)`; + return translate('FormatShortTimeSpanSeconds', { seconds }); } export default formatShortTimeSpan; diff --git a/frontend/src/Utilities/Date/formatTimeSpan.js b/frontend/src/Utilities/Date/formatTimeSpan.js index 1ebe6b9e3..2422e19d5 100644 --- a/frontend/src/Utilities/Date/formatTimeSpan.js +++ b/frontend/src/Utilities/Date/formatTimeSpan.js @@ -1,5 +1,6 @@ import moment from 'moment'; import padNumber from 'Utilities/Number/padNumber'; +import translate from 'Utilities/String/translate'; function formatTimeSpan(timeSpan) { if (!timeSpan) { @@ -16,7 +17,7 @@ function formatTimeSpan(timeSpan) { const time = `${hours}:${minutes}:${seconds}`; if (days > 0) { - return `${days}d ${time}`; + return translate('FormatTimeSpanDays', { days, time }); } return time; diff --git a/frontend/src/Utilities/Date/getRelativeDate.js b/frontend/src/Utilities/Date/getRelativeDate.js index 0a60135ce..812064272 100644 --- a/frontend/src/Utilities/Date/getRelativeDate.js +++ b/frontend/src/Utilities/Date/getRelativeDate.js @@ -4,6 +4,7 @@ import isInNextWeek from 'Utilities/Date/isInNextWeek'; import isToday from 'Utilities/Date/isToday'; import isTomorrow from 'Utilities/Date/isTomorrow'; import isYesterday from 'Utilities/Date/isYesterday'; +import translate from 'Utilities/String/translate'; function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat, includeSeconds = false, timeForToday = false } = {}) { if (!date) { @@ -21,15 +22,15 @@ function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat, } if (isYesterday(date)) { - return 'Yesterday'; + return translate('Yesterday'); } if (isTodayDate) { - return 'Today'; + return translate('Today'); } if (isTomorrow(date)) { - return 'Tomorrow'; + return translate('Tomorrow'); } if (isInNextWeek(date)) { diff --git a/frontend/src/Utilities/Number/formatAge.js b/frontend/src/Utilities/Number/formatAge.js index b8a4aacc5..a8f0e9f65 100644 --- a/frontend/src/Utilities/Number/formatAge.js +++ b/frontend/src/Utilities/Number/formatAge.js @@ -1,3 +1,5 @@ +import translate from 'Utilities/String/translate'; + function formatAge(age, ageHours, ageMinutes) { age = Math.round(age); ageHours = parseFloat(ageHours); @@ -5,13 +7,13 @@ function formatAge(age, ageHours, ageMinutes) { if (age < 2 && ageHours) { if (ageHours < 2 && !!ageMinutes) { - return `${ageMinutes.toFixed(0)} ${ageHours === 1 ? 'minute' : 'minutes'}`; + return `${ageMinutes.toFixed(0)} ${ageHours === 1 ? translate('FormatAgeMinute') : translate('FormatAgeMinutes')}`; } - return `${ageHours.toFixed(1)} ${ageHours === 1 ? 'hour' : 'hours'}`; + return `${ageHours.toFixed(1)} ${ageHours === 1 ? translate('FormatAgeHour') : translate('FormatAgeHours')}`; } - return `${age} ${age === 1 ? 'day' : 'days'}`; + return `${age} ${age === 1 ? translate('FormatAgeDay') : translate('FormatAgeDays')}`; } export default formatAge; diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 4b5f966c9..520837a8f 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -476,6 +476,20 @@ "ForNewImportsOnly": "For new imports only", "ForeignId": "Foreign Id", "ForeignIdHelpText": "The Musicbrainz Id of the artist/album to exclude", + "FormatAgeDay": "day", + "FormatAgeDays": "days", + "FormatAgeHour": "hour", + "FormatAgeHours": "hours", + "FormatAgeMinute": "minute", + "FormatAgeMinutes": "minutes", + "FormatDateTimeRelative": "{relativeDay}, {formattedDate} {formattedTime}", + "FormatDateTime": "{formattedDate} {formattedTime}", + "FormatRuntimeHours": "{hours}h", + "FormatRuntimeMinutes": "{minutes}m", + "FormatShortTimeSpanHours": "{hours} hour(s)", + "FormatShortTimeSpanMinutes": "{minutes} minute(s)", + "FormatShortTimeSpanSeconds": "{seconds} second(s)", + "FormatTimeSpanDays": "{days}d {time}", "Formats": "Formats", "FreeSpace": "Free Space", "FutureAlbums": "Future Albums", @@ -680,12 +694,19 @@ "Monitor": "Monitor", "MonitorAlbum": "Monitor Album", "MonitorAlbumExistingOnlyWarning": "This is a one off adjustment of the monitored setting for each album. Use the option under Artist/Edit to control what happens for newly added albums", + "MonitorAllAlbums": "All Albums", "MonitorArtist": "Monitor Artist", "MonitorArtists": "Monitor Artists", - "MonitorExistingAlbums": "Monitor Existing Albums", - "MonitorNewAlbums": "Monitor New Albums", + "MonitorExistingAlbums": "Existing Albums", + "MonitorFirstAlbum": "First Album", + "MonitorFutureAlbums": "Future Albums", + "MonitorLastestAlbum": "Lastest Album", + "MonitorMissingAlbums": "Missing Albums", + "MonitorNewAlbums": "New Albums", "MonitorNewItems": "Monitor New Albums", "MonitorNewItemsHelpText": "Which new albums should be monitored", + "MonitorNoAlbums": "None", + "MonitorNoNewAlbums": "No New Albums", "Monitored": "Monitored", "MonitoredHelpText": "Download monitored albums from this artist", "MonitoredOnly": "Monitored Only", @@ -1099,6 +1120,7 @@ "TimeFormat": "Time Format", "TimeLeft": "Time Left", "Title": "Title", + "Tomorrow": "Tomorrow", "TorrentDelay": "Torrent Delay", "TorrentDelayHelpText": "Delay in minutes to wait before grabbing a torrent", "Torrents": "Torrents", @@ -1220,5 +1242,6 @@ "WriteMetadataToAudioFiles": "Write Metadata to Audio Files", "Year": "Year", "Yes": "Yes", - "YesCancel": "Yes, Cancel" + "YesCancel": "Yes, Cancel", + "Yesterday": "Yesterday" }