mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-04 05:08:42 +08:00
fix(l10n): issue of publishing locale resources (#5416)
This commit is contained in:
parent
c4ee286f12
commit
3e8326f941
2
packages/core/cache/src/cache-manager.ts
vendored
2
packages/core/cache/src/cache-manager.ts
vendored
@ -100,7 +100,7 @@ export class CacheManager {
|
||||
|
||||
async createCache(options: { name: string; prefix?: string; store?: string; [key: string]: any }) {
|
||||
const { name, prefix, store = this.defaultStore, ...config } = options;
|
||||
if (!lodash.isEmpty(config)) {
|
||||
if (!lodash.isEmpty(config) || store === 'memory') {
|
||||
const newStore = await this.createStore({ name, storeType: store, ...config });
|
||||
return this.newCache({ name, prefix, store: newStore });
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ export interface ResourceStorer {
|
||||
getResources(lang: string): Promise<{
|
||||
[ns: string]: Record<string, string>;
|
||||
}>;
|
||||
reset?: () => Promise<void>;
|
||||
}
|
||||
|
||||
export class Locale {
|
||||
@ -45,14 +46,15 @@ export class Locale {
|
||||
name: 'locale',
|
||||
prefix: 'locale',
|
||||
store: 'memory',
|
||||
max: 2000
|
||||
});
|
||||
|
||||
await this.get(this.defaultLang);
|
||||
}
|
||||
|
||||
async reload() {
|
||||
await this.cache.reset();
|
||||
const storers = Array.from(this.resourceStorers.getValues());
|
||||
const promises = storers.map((storer) => storer.reset());
|
||||
await Promise.all([this.cache.reset(), ...promises]);
|
||||
}
|
||||
|
||||
setLocaleFn(name: string, fn: (lang: string) => Promise<any>) {
|
||||
|
@ -27,9 +27,11 @@ describe('actions', () => {
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
process.env.APP_ENV = 'production';
|
||||
app = await createMockServer({
|
||||
plugins: ['localization'],
|
||||
});
|
||||
await app.emitAsync('afterLoad');
|
||||
db = app.db;
|
||||
repo = db.getRepository('localizationTexts');
|
||||
agent = app.agent();
|
||||
@ -106,5 +108,28 @@ describe('actions', () => {
|
||||
expect(res.body.data[0].translation).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('publish', async () => {
|
||||
await repo.create({
|
||||
values: [
|
||||
{
|
||||
module: 'test',
|
||||
text: 'text',
|
||||
translations: [
|
||||
{
|
||||
locale: 'en-US',
|
||||
translation: 'translation',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
const { resources } = await app.localeManager.get('en-US');
|
||||
expect(resources.test).toBeUndefined();
|
||||
await agent.resource('localization').publish();
|
||||
const { resources: resources2 } = await app.localeManager.get('en-US');
|
||||
expect(resources2.test).toBeDefined();
|
||||
expect(resources2.test.text).toBe('translation');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -118,6 +118,7 @@ export class PluginLocalizationServer extends Plugin {
|
||||
|
||||
this.app.localeManager.registerResourceStorer('plugin-localization', {
|
||||
getResources: (lang: string) => this.resources.getResources(lang),
|
||||
reset: () => this.resources.reset(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ export default class Resources {
|
||||
await this.cache.set(`texts`, [...existTexts, ...newTexts]);
|
||||
}
|
||||
|
||||
async resetCache(locale: string) {
|
||||
await this.cache.del(`translations:${locale}`);
|
||||
async reset() {
|
||||
await this.cache.reset();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user