ChengLei Shao a7f964988b
fix: update association with a non-primary key table (#5495)
* fix: update association with non primaryKey table

* fix: test

* fix: test

* fix: get primary key attribute with multi filter target keys

* fix: update has one associations

* fix: test

* fix: test

* chore: test

* chore: test

* chore: test

* chore: test

* chore: middleware

* chore: error condition

* chore: test

* fix: test
2024-10-25 07:21:07 +08:00

36 lines
941 B
TypeScript

/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { Locale } from '../locale';
export async function i18n(ctx, next) {
ctx.getCurrentLocale = () => {
const lng =
ctx.get('X-Locale') ||
(ctx.request.query.locale as string) ||
ctx.app.i18n.language ||
ctx.acceptsLanguages().shift() ||
'en-US';
return lng;
};
const lng = ctx.getCurrentLocale();
const localeManager = ctx.app.localeManager as Locale;
const i18n = await localeManager.getI18nInstance(lng);
ctx.i18n = i18n;
ctx.t = i18n.t.bind(i18n);
if (lng !== '*' && lng) {
await i18n.changeLanguage(lng);
await localeManager.loadResourcesByLang(lng);
}
await next();
}