feat: add server default locale setting (#1536)

* feat: add server default locale setting

* fix: do not modify defaultLocale property of IntlProvider
This commit is contained in:
TheCatLady
2021-05-03 09:11:28 -04:00
committed by GitHub
parent 4fd452dd18
commit f256a444c5
14 changed files with 94 additions and 44 deletions

View File

@@ -32,6 +32,7 @@ export interface PublicSettingsResponse {
cacheImages: boolean;
vapidPublic: string;
enablePushRegistration: boolean;
locale: string;
}
export interface CacheItem {

View File

@@ -88,6 +88,7 @@ export interface MainSettings {
originalLanguage: string;
trustProxy: boolean;
partialRequestsEnabled: boolean;
locale: string;
}
interface PublicSettings {
@@ -106,6 +107,7 @@ interface FullPublicSettings extends PublicSettings {
cacheImages: boolean;
vapidPublic: string;
enablePushRegistration: boolean;
locale: string;
}
export interface NotificationAgentConfig {
@@ -249,6 +251,7 @@ class Settings {
originalLanguage: '',
trustProxy: false,
partialRequestsEnabled: true,
locale: 'en',
},
plex: {
name: '',
@@ -411,6 +414,7 @@ class Settings {
cacheImages: this.data.main.cacheImages,
vapidPublic: this.vapidPublic,
enablePushRegistration: this.data.notifications.agents.webpush.enabled,
locale: this.data.main.locale,
};
}

View File

@@ -5,6 +5,7 @@ import { getSettings } from '../lib/settings';
export const checkUser: Middleware = async (req, _res, next) => {
const settings = getSettings();
if (req.header('X-API-Key') === settings.main.apiKey) {
const userRepository = getRepository(User);
@@ -28,9 +29,12 @@ export const checkUser: Middleware = async (req, _res, next) => {
if (user) {
req.user = user;
req.locale = user.settings?.locale;
req.locale = user.settings?.locale
? user.settings?.locale
: settings.main.locale;
}
}
next();
};