Translate Frontend Utilities

This commit is contained in:
Stevie Robinson 2023-09-04 19:28:46 +02:00 committed by GitHub
parent faecdc855f
commit 3f0e8ce863
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 107 additions and 27 deletions

View File

@ -1,4 +1,5 @@
import moment from 'moment'; import moment from 'moment';
import translate from 'Utilities/String/translate';
import formatTime from './formatTime'; import formatTime from './formatTime';
import isToday from './isToday'; import isToday from './isToday';
import isTomorrow from './isTomorrow'; import isTomorrow from './isTomorrow';
@ -10,15 +11,15 @@ function getRelativeDay(date, includeRelativeDate) {
} }
if (isYesterday(date)) { if (isYesterday(date)) {
return 'Yesterday, '; return translate('Yesterday');
} }
if (isToday(date)) { if (isToday(date)) {
return 'Today, '; return translate('Today');
} }
if (isTomorrow(date)) { if (isTomorrow(date)) {
return 'Tomorrow, '; return translate('Tomorrow');
} }
return ''; return '';
@ -33,7 +34,10 @@ function formatDateTime(date, dateFormat, timeFormat, { includeSeconds = false,
const formattedDate = moment(date).format(dateFormat); const formattedDate = moment(date).format(dateFormat);
const formattedTime = formatTime(date, timeFormat, { includeMinuteZero: true, includeSeconds }); 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; export default formatDateTime;

View File

@ -1,4 +1,5 @@
import moment from 'moment'; import moment from 'moment';
import translate from 'Utilities/String/translate';
function formatShortTimeSpan(timeSpan) { function formatShortTimeSpan(timeSpan) {
if (!timeSpan) { if (!timeSpan) {
@ -12,14 +13,14 @@ function formatShortTimeSpan(timeSpan) {
const seconds = Math.floor(duration.asSeconds()); const seconds = Math.floor(duration.asSeconds());
if (hours > 0) { if (hours > 0) {
return `${hours} hour(s)`; return translate('FormatShortTimeSpanHours', { hours });
} }
if (minutes > 0) { if (minutes > 0) {
return `${minutes} minute(s)`; return translate('FormatShortTimeSpanMinutes', { minutes });
} }
return `${seconds} second(s)`; return translate('FormatShortTimeSpanSeconds', { seconds });
} }
export default formatShortTimeSpan; export default formatShortTimeSpan;

View File

@ -1,5 +1,6 @@
import moment from 'moment'; import moment from 'moment';
import padNumber from 'Utilities/Number/padNumber'; import padNumber from 'Utilities/Number/padNumber';
import translate from 'Utilities/String/translate';
function formatTimeSpan(timeSpan) { function formatTimeSpan(timeSpan) {
if (!timeSpan) { if (!timeSpan) {
@ -16,7 +17,7 @@ function formatTimeSpan(timeSpan) {
const time = `${hours}:${minutes}:${seconds}`; const time = `${hours}:${minutes}:${seconds}`;
if (days > 0) { if (days > 0) {
return `${days}d ${time}`; return translate('FormatTimeSpanDays', { days, time });
} }
return time; return time;

View File

@ -4,6 +4,7 @@ import isInNextWeek from 'Utilities/Date/isInNextWeek';
import isToday from 'Utilities/Date/isToday'; import isToday from 'Utilities/Date/isToday';
import isTomorrow from 'Utilities/Date/isTomorrow'; import isTomorrow from 'Utilities/Date/isTomorrow';
import isYesterday from 'Utilities/Date/isYesterday'; import isYesterday from 'Utilities/Date/isYesterday';
import translate from 'Utilities/String/translate';
function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat, includeSeconds = false, timeForToday = false } = {}) { function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat, includeSeconds = false, timeForToday = false } = {}) {
if (!date) { if (!date) {
@ -21,15 +22,15 @@ function getRelativeDate(date, shortDateFormat, showRelativeDates, { timeFormat,
} }
if (isYesterday(date)) { if (isYesterday(date)) {
return 'Yesterday'; return translate('Yesterday');
} }
if (isTodayDate) { if (isTodayDate) {
return 'Today'; return translate('Today');
} }
if (isTomorrow(date)) { if (isTomorrow(date)) {
return 'Tomorrow'; return translate('Tomorrow');
} }
if (isInNextWeek(date)) { if (isInNextWeek(date)) {

View File

@ -1,3 +1,5 @@
import translate from 'Utilities/String/translate';
function formatAge(age, ageHours, ageMinutes) { function formatAge(age, ageHours, ageMinutes) {
age = Math.round(age); age = Math.round(age);
ageHours = parseFloat(ageHours); ageHours = parseFloat(ageHours);
@ -5,13 +7,13 @@ function formatAge(age, ageHours, ageMinutes) {
if (age < 2 && ageHours) { if (age < 2 && ageHours) {
if (ageHours < 2 && !!ageMinutes) { 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; export default formatAge;

View File

@ -1,3 +1,5 @@
import translate from 'Utilities/String/translate';
function formatRuntime(runtime: number) { function formatRuntime(runtime: number) {
if (!runtime) { if (!runtime) {
return ''; return '';
@ -8,11 +10,11 @@ function formatRuntime(runtime: number) {
const result = []; const result = [];
if (hours) { if (hours) {
result.push(`${hours}h`); result.push(translate('FormatRuntimeHours', { hours }));
} }
if (minutes) { if (minutes) {
result.push(`${minutes}m`); result.push(translate('FormatRuntimeMinutes', { minutes }));
} }
return result.join(' '); return result.join(' ');

View File

@ -1,14 +1,66 @@
import translate from 'Utilities/String/translate';
const monitorOptions = [ const monitorOptions = [
{ key: 'all', value: 'All Episodes' }, {
{ key: 'future', value: 'Future Episodes' }, key: 'all',
{ key: 'missing', value: 'Missing Episodes' }, get value() {
{ key: 'existing', value: 'Existing Episodes' }, return translate('MonitorAllEpisodes');
{ key: 'pilot', value: 'Pilot Episode' }, }
{ key: 'firstSeason', value: 'Only First Season' }, },
{ key: 'latestSeason', value: 'Only Latest Season' }, {
{ key: 'monitorSpecials', value: 'Monitor Specials' }, key: 'future',
{ key: 'unmonitorSpecials', value: 'Unmonitor Specials' }, get value() {
{ key: 'none', value: 'None' } return translate('MonitorFutureEpisodes');
}
},
{
key: 'missing',
get value() {
return translate('MonitorMissingEpisodes');
}
},
{
key: 'existing',
get value() {
return translate('MonitorExistingEpisodes');
}
},
{
key: 'pilot',
get value() {
return translate('MonitorPilotEpisode');
}
},
{
key: 'firstSeason',
get value() {
return translate('MonitorFirstSeason');
}
},
{
key: 'latestSeason',
get value() {
return translate('MonitorLatestSeason');
}
},
{
key: 'monitorSpecials',
get value() {
return translate('MonitorSpecials');
}
},
{
key: 'unmonitorSpecials',
get value() {
return translate('UnmonitorSpecials');
}
},
{
key: 'none',
get value() {
return translate('MonitorNone');
}
}
]; ];
export default monitorOptions; export default monitorOptions;

View File

@ -525,6 +525,20 @@
"Folder": "Folder", "Folder": "Folder",
"Folders": "Folders", "Folders": "Folders",
"Forecast": "Forecast", "Forecast": "Forecast",
"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", "Formats": "Formats",
"Forums": "Forums", "Forums": "Forums",
"FreeSpace": "Free Space", "FreeSpace": "Free Space",
@ -784,6 +798,7 @@
"MonitorMissingEpisodesDescription": "Monitor episodes that do not have files or have not aired yet", "MonitorMissingEpisodesDescription": "Monitor episodes that do not have files or have not aired yet",
"MonitorNone": "None", "MonitorNone": "None",
"MonitorNoneDescription": "No episodes will be monitored", "MonitorNoneDescription": "No episodes will be monitored",
"MonitorPilotEpisode": "Pilot Episode",
"MonitorSelected": "Monitor Selected", "MonitorSelected": "Monitor Selected",
"MonitorSeries": "Monitor Series", "MonitorSeries": "Monitor Series",
"MonitorSpecials": "Monitor Specials", "MonitorSpecials": "Monitor Specials",
@ -1357,6 +1372,7 @@
"ToggleMonitoredSeriesUnmonitored ": "Cannot toggle monitored state when series is unmonitored", "ToggleMonitoredSeriesUnmonitored ": "Cannot toggle monitored state when series is unmonitored",
"ToggleMonitoredToUnmonitored": "Monitored, click to unmonitor", "ToggleMonitoredToUnmonitored": "Monitored, click to unmonitor",
"ToggleUnmonitoredToMonitored": "Unmonitored, click to monitor", "ToggleUnmonitoredToMonitored": "Unmonitored, click to monitor",
"Tomorrow": "Tomorrow",
"TorrentDelay": "Torrent Delay", "TorrentDelay": "Torrent Delay",
"TorrentDelayHelpText": "Delay in minutes to wait before grabbing a torrent", "TorrentDelayHelpText": "Delay in minutes to wait before grabbing a torrent",
"TorrentDelayTime": "Torrent Delay: {torrentDelay}", "TorrentDelayTime": "Torrent Delay: {torrentDelay}",
@ -1466,5 +1482,6 @@
"WouldYouLikeToRestoreBackup": "Would you like to restore the backup '{name}'?", "WouldYouLikeToRestoreBackup": "Would you like to restore the backup '{name}'?",
"Year": "Year", "Year": "Year",
"Yes": "Yes", "Yes": "Yes",
"YesCancel": "Yes, Cancel" "YesCancel": "Yes, Cancel",
"Yesterday": "Yesterday"
} }