@sap-ux/preview-middleware 0.25.7 → 0.25.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -308,6 +308,19 @@ export declare class FlpSandbox {
308
308
  * @returns {Promise<void>} A promise that resolves when the operation is complete.
309
309
  */
310
310
  private storeI18nKeysHandler;
311
+ /**
312
+ * Parses i18n configuration from manifest and returns path and locale settings.
313
+ *
314
+ * @returns i18n path, supported locales, and fallback locale
315
+ */
316
+ private parseI18nConfig;
317
+ /**
318
+ * Extracts i18n path from object configuration (bundleName or bundleUrl).
319
+ *
320
+ * @param i18nConfig - The i18n configuration object
321
+ * @returns The resolved i18n path
322
+ */
323
+ private getI18nPathFromConfig;
311
324
  /**
312
325
  * Adds a route to store i18n properties in the i18n file.
313
326
  * This function updates the i18n file with new properties provided in the request body.
package/dist/base/flp.js CHANGED
@@ -833,30 +833,20 @@ class FlpSandbox {
833
833
  */
834
834
  async storeI18nKeysHandler(req, res) {
835
835
  try {
836
- // getSourcePath() returns the webapp path directly for all project types
837
836
  const webappPath = this.utils.getProject().getSourcePath();
838
- const i18nConfig = this.manifest['sap.app'].i18n;
839
- let i18nPath = 'i18n/i18n.properties';
840
- let fallbackLocale;
841
- let supportedLocales = [];
842
- if (typeof i18nConfig === 'string') {
843
- i18nPath = i18nConfig;
837
+ const { i18nPath, supportedLocales, fallbackLocale } = this.parseI18nConfig();
838
+ let requestedLocale = req.query.locale ?? fallbackLocale ?? '';
839
+ if (!requestedLocale && supportedLocales.length > 0) {
840
+ requestedLocale = supportedLocales[0];
844
841
  }
845
- else if (typeof i18nConfig === 'object' && i18nConfig !== null && 'bundleUrl' in i18nConfig) {
846
- const { bundleUrl: i18nPathFromConfig, supportedLocales: locales = [], fallbackLocale: fallback } = i18nConfig;
847
- i18nPath = i18nPathFromConfig;
848
- supportedLocales = locales;
849
- fallbackLocale = fallback;
842
+ if (requestedLocale && supportedLocales.length > 0 && !supportedLocales.includes(requestedLocale)) {
843
+ this.sendResponse(res, 'text/plain', 400, `Locale "${requestedLocale}" is not supported. Supported: ${supportedLocales.join(', ')}`);
844
+ return;
850
845
  }
851
- const requestedLocale = req.query.locale ?? fallbackLocale ?? '';
852
846
  const baseFilePath = (0, node_path_1.join)(webappPath, i18nPath);
853
847
  const filePath = requestedLocale
854
848
  ? baseFilePath.replace('.properties', `_${requestedLocale}.properties`)
855
849
  : baseFilePath;
856
- if (requestedLocale && supportedLocales.length > 0 && !supportedLocales.includes(requestedLocale)) {
857
- this.sendResponse(res, 'text/plain', 400, `Locale "${requestedLocale}" is not supported. Supported: ${supportedLocales.join(', ')}`);
858
- return;
859
- }
860
850
  const entries = (req.body || []).map((entry) => ({
861
851
  ...entry,
862
852
  annotation: entry.comment ?? entry.annotation
@@ -869,6 +859,48 @@ class FlpSandbox {
869
859
  this.sendResponse(res, 'text/plain', 500, 'File could not be updated.');
870
860
  }
871
861
  }
862
+ /**
863
+ * Parses i18n configuration from manifest and returns path and locale settings.
864
+ *
865
+ * @returns i18n path, supported locales, and fallback locale
866
+ */
867
+ parseI18nConfig() {
868
+ const i18nConfig = this.manifest['sap.app'].i18n;
869
+ let i18nPath = 'i18n/i18n.properties';
870
+ let fallbackLocale;
871
+ let supportedLocales = [];
872
+ if (typeof i18nConfig === 'string') {
873
+ i18nPath = i18nConfig;
874
+ }
875
+ else if (typeof i18nConfig === 'object' && i18nConfig !== null) {
876
+ i18nPath = this.getI18nPathFromConfig(i18nConfig);
877
+ supportedLocales = i18nConfig.supportedLocales ?? [];
878
+ fallbackLocale = i18nConfig.fallbackLocale;
879
+ }
880
+ return { i18nPath, supportedLocales, fallbackLocale };
881
+ }
882
+ /**
883
+ * Extracts i18n path from object configuration (bundleName or bundleUrl).
884
+ *
885
+ * @param i18nConfig - The i18n configuration object
886
+ * @returns The resolved i18n path
887
+ */
888
+ getI18nPathFromConfig(i18nConfig) {
889
+ if ('bundleName' in i18nConfig && i18nConfig.bundleName) {
890
+ const appId = this.manifest['sap.app'].id;
891
+ const bundlePath = i18nConfig.bundleName.startsWith(`${appId}.`)
892
+ ? i18nConfig.bundleName.substring(appId.length + 1)
893
+ : i18nConfig.bundleName;
894
+ if ('bundleUrl' in i18nConfig && i18nConfig.bundleUrl) {
895
+ this.logger.info(`Both bundleName and bundleUrl are provided in i18n config. Using bundleName: ${i18nConfig.bundleName}`);
896
+ }
897
+ return `${bundlePath.replaceAll('.', '/')}.properties`;
898
+ }
899
+ if ('bundleUrl' in i18nConfig && i18nConfig.bundleUrl) {
900
+ return i18nConfig.bundleUrl;
901
+ }
902
+ return 'i18n/i18n.properties';
903
+ }
872
904
  /**
873
905
  * Adds a route to store i18n properties in the i18n file.
874
906
  * This function updates the i18n file with new properties provided in the request body.
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apreview-middleware"
11
11
  },
12
- "version": "0.25.7",
12
+ "version": "0.25.9",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "mem-fs-editor": "9.4.0",
28
28
  "qrcode": "1.5.4",
29
29
  "@sap/bas-sdk": "3.13.3",
30
- "@sap-ux/adp-tooling": "0.18.105",
30
+ "@sap-ux/adp-tooling": "0.18.106",
31
31
  "@sap-ux/btp-utils": "1.1.12",
32
32
  "@sap-ux/control-property-editor-sources": "npm:@sap-ux/control-property-editor@0.7.22",
33
33
  "@sap-ux/feature-toggle": "0.3.7",