import ResourceBundle from 'sap/base/i18n/ResourceBundle'; import ResourceModel from 'sap/ui/model/resource/ResourceModel'; const BUNDLE_CACHE: Record = {}; const MODEL_CACHE: Record = {}; export async function getResourceBundle(key: string): Promise { const cachedBundle = BUNDLE_CACHE[key]; if (cachedBundle) { return cachedBundle; } const bundle = await ResourceBundle.create({ bundleUrl: '/preview/client/messagebundle.properties', url: '/preview/client/messagebundle.properties', supportedLocales: [''], locale: '', async: true }); BUNDLE_CACHE[key] = bundle; return bundle; } export async function getResourceModel(key = 'open.ux.preview.client'): Promise { const cachedModel = MODEL_CACHE[key]; if (cachedModel) { return cachedModel; } const bundle = await getResourceBundle(key); const model = new ResourceModel({ bundle }); MODEL_CACHE[key] = model; return model; } export class TextBundle { constructor(private readonly bundle: ResourceBundle) {} getText(key: string, args?: string[]): string { return this.bundle.getText(key, args) ?? key; } } export async function getTextBundle(key = 'open.ux.preview.client'): Promise { const bundle = await getResourceBundle(key); return new TextBundle(bundle); }