Skip to content

Commit

Permalink
🛠️ Server default language (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
MontaGhanmy authored Nov 3, 2023
1 parent fbecbab commit 650f394
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tdrive/backend/node/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"server": "PLUGINS_SERVER"
},
"drive": {
"rootAdmins": "DRIVE_ROOT_ADMINS"
"rootAdmins": "DRIVE_ROOT_ADMINS",
"defaultLanguage": "DRIVE_DEFAULT_LANGUAGE"
}
}
5 changes: 4 additions & 1 deletion tdrive/backend/node/src/services/documents/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
writeToTemporaryFile,
} from "../../utils/files";
import mimes from "../../utils/mime";
import { Configuration } from "../../core/platform/framework";
import gr from "../global-resolver";
import { stopWords } from "./const";
import { DriveFile } from "./entities/drive-file";
Expand Down Expand Up @@ -44,8 +45,10 @@ export const isSharedWithMeFolder = (id: string) => {
};

export const getVirtualFoldersNames = async (id: string, context: DriveExecutionContext) => {
const configuration = new Configuration("drive");
const defaultLang = configuration.get<string>("defaultLanguage") || "en";
const user = await gr.services.users.get({ id: context.user?.id });
const locale = user?.preferences?.locale || "en";
const locale = user?.preferences?.locale || defaultLang;

if (id.startsWith("user_")) {
return gr.services.i18n.translate("virtual-folder.my-drive", locale);
Expand Down
5 changes: 4 additions & 1 deletion tdrive/backend/node/src/utils/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import {
CompanyUserStatus,
UserObject,
} from "../services/user/web/types";
import { Configuration } from "../core/platform/framework";
import gr from "../services/global-resolver";

export async function formatUser(
user: User,
options?: { includeCompanies?: boolean },
): Promise<UserObject> {
if (!user) return null;
const configuration = new Configuration("drive");
const defaultLang = configuration.get<string>("defaultLanguage") || "en";

let resUser = {
id: user.id,
Expand Down Expand Up @@ -69,7 +72,7 @@ export async function formatUser(
...resUser,
preferences: {
...user.preferences,
locale: user.preferences?.language || user.language || "en",
locale: user.preferences?.language || user.language || defaultLang,
timezone: user.preferences?.timezone || parseInt(user.timezone) || 0,
allow_tracking: user.preferences?.allow_tracking || false,
},
Expand Down

0 comments on commit 650f394

Please sign in to comment.