1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #4005 from dmitrylyzo/fix-last-seen

Fix locale with suffix
This commit is contained in:
Bill Thornton 2022-10-06 17:04:16 -04:00 committed by GitHub
commit b14d76a3d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 9 deletions

View file

@ -1,7 +1,7 @@
import type { UserDto } from '@thornbill/jellyfin-sdk/dist/generated-client'; import type { UserDto } from '@thornbill/jellyfin-sdk/dist/generated-client';
import React, { FunctionComponent } from 'react'; import React, { FunctionComponent } from 'react';
import { formatDistanceToNow } from 'date-fns'; import { formatDistanceToNow } from 'date-fns';
import { localeWithSuffix } from '../../../scripts/dfnshelper'; import { getLocaleWithSuffix } from '../../../scripts/dfnshelper';
import globalize from '../../../scripts/globalize'; import globalize from '../../../scripts/globalize';
import cardBuilder from '../../cardbuilder/cardBuilder'; import cardBuilder from '../../cardbuilder/cardBuilder';
@ -31,7 +31,7 @@ type IProps = {
const getLastSeenText = (lastActivityDate?: string | null) => { const getLastSeenText = (lastActivityDate?: string | null) => {
if (lastActivityDate) { if (lastActivityDate) {
return globalize.translate('LastSeen', formatDistanceToNow(Date.parse(lastActivityDate), localeWithSuffix)); return globalize.translate('LastSeen', formatDistanceToNow(Date.parse(lastActivityDate), getLocaleWithSuffix()));
} }
return ''; return '';

View file

@ -6,7 +6,7 @@ import serverNotifications from '../../scripts/serverNotifications';
import dom from '../../scripts/dom'; import dom from '../../scripts/dom';
import globalize from '../../scripts/globalize'; import globalize from '../../scripts/globalize';
import { formatDistanceToNow } from 'date-fns'; import { formatDistanceToNow } from 'date-fns';
import { localeWithSuffix } from '../../scripts/dfnshelper'; import { getLocaleWithSuffix } from '../../scripts/dfnshelper';
import loading from '../../components/loading/loading'; import loading from '../../components/loading/loading';
import playMethodHelper from '../../components/playback/playmethodhelper'; import playMethodHelper from '../../components/playback/playmethodhelper';
import cardBuilder from '../../components/cardbuilder/cardBuilder'; import cardBuilder from '../../components/cardbuilder/cardBuilder';
@ -476,7 +476,7 @@ import confirm from '../../components/confirm/confirm';
// how dates are returned by the server when the session is active and show something like 'Active now', instead of past/future sentences // how dates are returned by the server when the session is active and show something like 'Active now', instead of past/future sentences
if (!nowPlayingItem) { if (!nowPlayingItem) {
return { return {
html: globalize.translate('LastSeen', formatDistanceToNow(Date.parse(session.LastActivityDate), localeWithSuffix)), html: globalize.translate('LastSeen', formatDistanceToNow(Date.parse(session.LastActivityDate), getLocaleWithSuffix())),
image: imgUrl image: imgUrl
}; };
} }

View file

@ -5,7 +5,7 @@ import dom from '../../../scripts/dom';
import globalize from '../../../scripts/globalize'; import globalize from '../../../scripts/globalize';
import imageHelper from '../../../scripts/imagehelper'; import imageHelper from '../../../scripts/imagehelper';
import { formatDistanceToNow } from 'date-fns'; import { formatDistanceToNow } from 'date-fns';
import { localeWithSuffix } from '../../../scripts/dfnshelper'; import { getLocaleWithSuffix } from '../../../scripts/dfnshelper';
import '../../../elements/emby-button/emby-button'; import '../../../elements/emby-button/emby-button';
import '../../../elements/emby-itemscontainer/emby-itemscontainer'; import '../../../elements/emby-itemscontainer/emby-itemscontainer';
import '../../../components/cardbuilder/card.scss'; import '../../../components/cardbuilder/card.scss';
@ -91,6 +91,8 @@ import confirm from '../../../components/confirm/confirm';
} }
function load(page, devices) { function load(page, devices) {
const localeWithSuffix = getLocaleWithSuffix();
let html = ''; let html = '';
html += devices.map(function (device) { html += devices.map(function (device) {
let deviceHtml = ''; let deviceHtml = '';

View file

@ -4,7 +4,7 @@ import { Events } from 'jellyfin-apiclient';
import globalize from '../../../scripts/globalize'; import globalize from '../../../scripts/globalize';
import serverNotifications from '../../../scripts/serverNotifications'; import serverNotifications from '../../../scripts/serverNotifications';
import { formatDistance, formatDistanceToNow } from 'date-fns'; import { formatDistance, formatDistanceToNow } from 'date-fns';
import { getLocale, localeWithSuffix } from '../../../scripts/dfnshelper'; import { getLocale, getLocaleWithSuffix } from '../../../scripts/dfnshelper';
import '../../../components/listview/listview.scss'; import '../../../components/listview/listview.scss';
import '../../../elements/emby-button/emby-button'; import '../../../elements/emby-button/emby-button';
@ -77,7 +77,7 @@ import '../../../elements/emby-button/emby-button';
if (task.LastExecutionResult) { if (task.LastExecutionResult) {
const endtime = Date.parse(task.LastExecutionResult.EndTimeUtc); const endtime = Date.parse(task.LastExecutionResult.EndTimeUtc);
const starttime = Date.parse(task.LastExecutionResult.StartTimeUtc); const starttime = Date.parse(task.LastExecutionResult.StartTimeUtc);
html += globalize.translate('LabelScheduledTaskLastRan', formatDistanceToNow(endtime, localeWithSuffix), html += globalize.translate('LabelScheduledTaskLastRan', formatDistanceToNow(endtime, getLocaleWithSuffix()),
formatDistance(starttime, endtime, { locale: getLocale() })); formatDistance(starttime, endtime, { locale: getLocale() }));
if (task.LastExecutionResult.Status === 'Failed') { if (task.LastExecutionResult.Status === 'Failed') {
html += " <span style='color:#FF0000;'>(" + globalize.translate('LabelFailed') + ')</span>'; html += " <span style='color:#FF0000;'>(" + globalize.translate('LabelFailed') + ')</span>';

View file

@ -68,9 +68,14 @@ export function getLocale() {
return dateLocales(globalize.getCurrentLocale()) || dateLocales(globalize.getCurrentLocale().replace(/-.*/, '')) || enUS; return dateLocales(globalize.getCurrentLocale()) || dateLocales(globalize.getCurrentLocale().replace(/-.*/, '')) || enUS;
} }
export const localeWithSuffix = { addSuffix: true, locale: getLocale() }; export function getLocaleWithSuffix() {
return {
addSuffix: true,
locale: getLocale()
};
}
export default { export default {
getLocale: getLocale, getLocale: getLocale,
localeWithSuffix: localeWithSuffix getLocaleWithSuffix
}; };