Skip to content

Translations respect language of user profile #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: 1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/build/api/docs.jsonopenapi.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const initialState: UserInformation = {
isAdmin: false,
classes: [],
docTypes: [],
language: 'en',
activePerspective: 0,
perspectives: []
}
Expand Down
27 changes: 14 additions & 13 deletions assets/js/src/core/modules/app/app-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const AppLoader = (props: IAppLoaderProps): React.JSX.Element => {
// Register the modal instance to allow centralized error message display throughout the project
ErrorModalService.setModalInstance(modal)

async function initLoadUser (): Promise<any> {
async function initLoadUser(): Promise<any> {
const userFetcher = dispatch(api.endpoints.userGetCurrentInformation.initiate())
await fetchMercureCookie()

Expand All @@ -66,12 +66,12 @@ export const AppLoader = (props: IAppLoaderProps): React.JSX.Element => {
dispatch(setUser(data))
}
})
.catch(() => {})
.catch(() => { })

return await userFetcher
}

async function initSettings (): Promise<any> {
async function initSettings(): Promise<any> {
const settingsFetcher = dispatch(settingsApi.endpoints.systemSettingsGet.initiate())

settingsFetcher
Expand All @@ -82,22 +82,23 @@ export const AppLoader = (props: IAppLoaderProps): React.JSX.Element => {
dispatch(setSettings(data))
}
})
.catch(() => {})
.catch(() => { })

return await settingsFetcher
}

async function initActivePerspective (): Promise<any> {
async function initActivePerspective(): Promise<any> {
const user = selectCurrentUser(store.getState())
const perspectiveId = String(user?.activePerspective ?? 'studio_default_perspective')
return await loadPerspective(perspectiveId)
}

async function loadTranslations (): Promise<any> {
await translations({ translation: { locale: 'en', keys: [] } })
async function loadTranslations(): Promise<any> {
const user = selectCurrentUser(store.getState())
await translations({ translation: { locale: user.language, keys: [] } })
.unwrap()
.then(response => {
i18n.addResourceBundle('en', 'translation', response.keys ?? [], true, true)
i18n.addResourceBundle(user.language, 'translation', response.keys ?? [], true, true)
})
.catch(() => {
trackError(new GeneralError('Error loading translations'))
Expand All @@ -109,19 +110,19 @@ export const AppLoader = (props: IAppLoaderProps): React.JSX.Element => {

if (isSuccessInitSetting === true) {
Promise.allSettled([
initActivePerspective()
initActivePerspective(),
loadTranslations()
]).then(() => {
}).catch(() => {})
}).catch(() => { })
}
}

useEffect(() => {
Promise.all([
initLoadUser(),
loadTranslations()
initLoadUser()
]).then(() => {
setIsLoading(false)
}).catch(() => {})
}).catch(() => { })
}, [])

useEffect(() => {
Expand Down
139 changes: 26 additions & 113 deletions assets/js/src/core/modules/asset/asset-api-slice.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ const injectedRtkApi = api
query: (queryArg) => ({ url: `/pimcore-studio/api/assets/${queryArg.id}/download` }),
providesTags: ["Assets"],
}),
assetExportCsvAsset: build.mutation<AssetExportCsvAssetApiResponse, AssetExportCsvAssetApiArg>({
query: (queryArg) => ({
url: `/pimcore-studio/api/assets/export/csv/asset`,
method: "POST",
body: queryArg.body,
}),
invalidatesTags: ["Assets"],
}),
assetExportCsvFolder: build.mutation<AssetExportCsvFolderApiResponse, AssetExportCsvFolderApiArg>({
query: (queryArg) => ({
url: `/pimcore-studio/api/assets/export/csv/folder`,
method: "POST",
body: queryArg.body,
}),
invalidatesTags: ["Assets"],
}),
assetExportZipAsset: build.mutation<AssetExportZipAssetApiResponse, AssetExportZipAssetApiArg>({
query: (queryArg) => ({
url: `/pimcore-studio/api/assets/export/zip/asset`,
Expand Down Expand Up @@ -400,75 +384,6 @@ export type AssetDownloadByIdApiArg = {
/** Id of the asset */
id: number;
};
export type AssetExportCsvAssetApiResponse =
/** status 201 Successfully created <strong>jobRun</strong> for csv export */ {
/** ID of created jobRun */
jobRunId: number;
};
export type AssetExportCsvAssetApiArg = {
body: {
assets?: number[];
columns?: GridColumnRequest[];
config?: {
delimiter?: string;
header?:
| "id"
| "custom_report_config"
| "custom_report_to_export"
| "asset_to_export"
| "folder_to_export"
| "csv_export_data"
| "config"
| "columns"
| "filters"
| "delimiter"
| "header"
| "no_header"
| "title"
| "name"
| "\r\n"
| "array"
| "int"
| "string"
| "bool";
};
};
};
export type AssetExportCsvFolderApiResponse =
/** status 201 Successfully created <strong>jobRun</strong> for csv export */ {
/** ID of created jobRun */
jobRunId: number;
};
export type AssetExportCsvFolderApiArg = {
body: {
folders?: number[];
columns?: GridColumnRequest[];
filters?: GridFilter;
config?: {
delimiter?: string;
header?:
| "id"
| "custom_report_config"
| "custom_report_to_export"
| "asset_to_export"
| "folder_to_export"
| "csv_export_data"
| "config"
| "columns"
| "filters"
| "delimiter"
| "header"
| "no_header"
| "title"
| "name"
| "\r\n"
| "array"
| "int"
| "string"
| "bool";
};
};
};
export type AssetExportZipAssetApiResponse =
/** status 201 Successfully created <strong>jobRun</strong> for zip export */ {
/** ID of created jobRun */
Expand Down Expand Up @@ -894,32 +809,6 @@ export type CustomSettings = {
/** dynamic custom settings - can be any key-value pair */
dynamicCustomSettings?: object[];
};
export type RelationFieldConfig = {
/** Relation Getter */
relation: string;
/** Field getter */
field: string;
};
export type SimpleFieldConfig = {
/** Field getter */
field: string;
};
export type AdvancedColumnConfig = {
/** advancedColumns */
advancedColumn?: (RelationFieldConfig | SimpleFieldConfig)[];
};
export type GridColumnRequest = {
/** Key */
key: string;
/** Locale */
locale?: any;
/** Type */
type: string;
/** Group */
group?: any;
/** Config */
config: (string | AdvancedColumnConfig)[];
};
export type GridFilter = {
/** Page */
page: number;
Expand Down Expand Up @@ -1185,6 +1074,32 @@ export type GridColumnData = {
/** inheritance */
inheritance?: any;
};
export type RelationFieldConfig = {
/** Relation Getter */
relation: string;
/** Field getter */
field: string;
};
export type SimpleFieldConfig = {
/** Field getter */
field: string;
};
export type AdvancedColumnConfig = {
/** advancedColumns */
advancedColumn?: (RelationFieldConfig | SimpleFieldConfig)[];
};
export type GridColumnRequest = {
/** Key */
key: string;
/** Locale */
locale?: any;
/** Type */
type: string;
/** Group */
group?: any;
/** Config */
config: (string | AdvancedColumnConfig)[];
};
export type PatchCustomMetadata = {
/** Name */
name: string;
Expand Down Expand Up @@ -1217,8 +1132,6 @@ export const {
useAssetDownloadZipQuery,
useAssetDeleteZipMutation,
useAssetDownloadByIdQuery,
useAssetExportCsvAssetMutation,
useAssetExportCsvFolderMutation,
useAssetExportZipAssetMutation,
useAssetExportZipFolderMutation,
useAssetGetByIdQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export type UserInformation = {
classes: string[];
/** Allowed doc types to create */
docTypes: string[];
/** User Language */
language: string;
/** Active studio perspective ID */
activePerspective: any;
/** Allowed studio perspectives */
Expand Down
2 changes: 2 additions & 0 deletions assets/js/src/core/modules/auth/user/user-api-slice.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ export type UserInformation = {
classes: string[];
/** Allowed doc types to create */
docTypes: string[];
/** User Language */
language: string;
/** Active studio perspective ID */
activePerspective: any;
/** Allowed studio perspectives */
Expand Down
1 change: 1 addition & 0 deletions assets/js/src/core/modules/auth/user/user-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const initialState: UserInformation = {
isAdmin: false,
classes: [],
docTypes: [],
language: 'en',
activePerspective: 0,
perspectives: []
}
Expand Down
2 changes: 2 additions & 0 deletions assets/js/src/core/modules/user/user-api-slice.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ export type UserInformation = {
classes: string[];
/** Allowed doc types to create */
docTypes: string[];
/** User Language */
language: string;
/** Active studio perspective ID */
activePerspective: any;
/** Allowed studio perspectives */
Expand Down