tachybase_todo/packages/plugins/system-settings/src/migrations/20220714204714-update-enabled-languages.ts
金昶 c9dfc2682c
feat: improve language settings (#627)
* feat: fix system local setting

* feat: improve language settings

* fix: improve code

* feat: update doc

* feat: add migration

Co-authored-by: chenos <chenlinxh@gmail.com>
2022-07-14 20:57:26 +08:00

18 lines
632 B
TypeScript

import { Migration } from '@nocobase/server';
export default class UpdateEnabledLanguagesMigration extends Migration {
async up() {
const result = await this.app.version.satisfies('<=0.7.2-alpha.7');
if (!result) {
return;
}
const SystemSetting = this.context.db.getRepository('systemSettings');
const setting = await SystemSetting.findOne();
const enabledLanguages = setting.get('enabledLanguages') || [];
if (Array.isArray(enabledLanguages) && enabledLanguages.length === 0) {
setting.set('enabledLanguages', [setting.get('appLang') || 'en-US']);
await setting.save();
}
}
}