Skip to content
Open
Changes from 4 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
22 changes: 18 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as fsAsync from 'fs/promises'
import * as appindex from '@sap/cds/app/index'
import * as req_locale from '@sap/cds/lib/req/locale'
//import * as cds from '@sap/cds-dk';
import { parse, parseLines, stringify } from 'dot-properties';
const cds = require('@sap/cds-dk');
Expand Down Expand Up @@ -43,7 +44,7 @@ export class cds_launchpad_plugin{
// Mount path for launchpad sandbox configuration
router.use('/appconfig/fioriSandboxConfig.json', async (request, response, next) => {
// debugger;
response.send(await this.prepareAppConfigJSON(options));
response.send(await this.prepareAppConfigJSON(request, options));
});

// Component preload generation
Expand Down Expand Up @@ -131,7 +132,7 @@ export class cds_launchpad_plugin{
return { appDirs, cwd, depsPaths };
}

async prepareAppConfigJSON(options: LaunchpadConfig): Promise<string> {
async prepareAppConfigJSON(request: express.Request, options: LaunchpadConfig): Promise<string> {
let template = options.template === 'legacy' || options.template === '' || options.template === undefined ? 'legacy' : options.template;

// Read app config template
Expand Down Expand Up @@ -190,8 +191,21 @@ export class cds_launchpad_plugin{
i18nPath += i18nsetting;
}

if (options.locale) {
i18nPath = i18nPath.replace(/(\.properties)$/,`_${options.locale}$1`);
// define locale to use
let locale = null;

// check for existing files
if(!locale && options.locale && fs.existsSync(i18nPath.replace(/(\.properties)$/, `_${options.locale}$1`))) locale = i18nPath.replace(/(\.properties)$/, `_${options.locale}$1`)
// https://cap.cloud.sap/docs/node.js/events#locale => req.locale or old (cds.user.locale)
if(!locale && req_locale.default(request) && fs.existsSync(i18nPath.replace(/(\.properties)$/, `_${cds.user?.local}$1`))) locale = i18nPath.replace(/(\.properties)$/, `_${req_locale.default(request)}$1`)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(!locale && req_locale.default(request) && fs.existsSync(i18nPath.replace(/(.properties)$/, _${req_locale.default(request)}$1))) locale = i18nPath.replace(/(.properties)$/, _${req_locale.default(request)}$1)

if(!locale && cds.env.i18n.default_language && fs.existsSync(i18nPath.replace(/(\.properties)$/, `_${cds.user?.local}$1`))) locale = i18nPath.replace(/(\.properties)$/, `_${cds.env.i18n.default_language}$1`)
if(!locale && fs.existsSync(i18nPath)) locale = i18nPath // allow fallback i18n

// use langu from settings options
if (locale){
i18nPath = locale
} else {
return cdsLaunchpadLogger.error(`i18n file not found: ${i18nPath}`)
}
const i18n = parse(fs.readFileSync( i18nPath ).toString());
const tileconfigs = manifest["sap.app"]?.crossNavigation?.inbounds;
Expand Down