@configuratorware/configurator-frontendgui 1.49.5 → 1.49.6

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.
@@ -358,47 +358,63 @@ function setConfiguration(customApplicationConfiguration) {
358
358
  }
359
359
  function setLanguage() {
360
360
  var language;
361
- // if the default language is defined in the configuration
362
- if (applicationConfiguration.language) {
363
- language = applicationConfiguration.language;
364
- }
365
- // if there is a locales array in the configuration...
366
- else if (applicationConfiguration.locales) {
367
- var browserLanguage = (0, _get["default"])(navigator, 'languages[0]', navigator.language).replace('-', '_');
368
- var matchToBrowserLanguage = (0, _find["default"])(applicationConfiguration.locales, {
369
- code: browserLanguage
370
- });
371
- var preferred = (0, _find["default"])(applicationConfiguration.locales, {
372
- preferred: true
373
- });
361
+ //fetch default language and set
362
+ _Api["default"].request({
363
+ url: 'languages'
364
+ }).then(function (response) {
365
+ var _response$data$find;
366
+ language = (_response$data$find = response.data.find(function (lang) {
367
+ return lang.isDefault;
368
+ })) === null || _response$data$find === void 0 ? void 0 : _response$data$find.iso;
369
+ // if the default language is defined in the configuration
370
+ if (applicationConfiguration.language) {
371
+ language = applicationConfiguration.language;
372
+ } else if (!language) {
373
+ // if there is a locales array in the configuration...
374
+ if (applicationConfiguration.locales) {
375
+ var browserLanguage = (0, _get["default"])(navigator, 'languages[0]', navigator.language).replace('-', '_');
376
+ var matchToBrowserLanguage = (0, _find["default"])(applicationConfiguration.locales, {
377
+ code: browserLanguage
378
+ });
379
+ var preferred = (0, _find["default"])(applicationConfiguration.locales, {
380
+ preferred: true
381
+ });
374
382
 
375
- // if there is a match with the browser language use that
376
- if (matchToBrowserLanguage) {
377
- language = matchToBrowserLanguage.code;
378
- }
379
- // if the preferred language is set use it
380
- else if (preferred) {
381
- language = preferred.code;
383
+ // if there is a match with the browser language use that
384
+ if (matchToBrowserLanguage) {
385
+ language = matchToBrowserLanguage.code;
386
+ }
387
+ // if the preferred language is set use it
388
+ else if (preferred) {
389
+ language = preferred.code;
390
+ }
391
+ // otherwise use the first from the locales list
392
+ else {
393
+ language = (0, _first["default"])(applicationConfiguration.locales).code;
394
+ }
395
+ }
396
+ // we have no info about the language, so try to use the browser language
397
+ else {
398
+ language = (0, _get["default"])(navigator, 'languages[0]', navigator.language).replace('-', '_') || 'de_DE';
399
+ }
382
400
  }
383
- // otherwise use the first from the locales list
384
- else {
385
- language = (0, _first["default"])(applicationConfiguration.locales).code;
401
+ if (!(0, _find["default"])(applicationConfiguration.locales, {
402
+ code: language.replace('-', '_')
403
+ })) {
404
+ // eslint-disable-next-line no-console
405
+ console.warn("The selected language (".concat(language, ") is not listed in the available languages!"));
406
+ language = (0, _find["default"])(applicationConfiguration.locales, {
407
+ preferred: true
408
+ }).code;
386
409
  }
387
- }
388
- // we have no info about the language, so try to use the browser language
389
- else {
390
- language = (0, _get["default"])(navigator, 'languages[0]', navigator.language).replace('-', '_') || 'de_DE';
391
- }
392
- if (!(0, _find["default"])(applicationConfiguration.locales, {
393
- code: language
394
- })) {
410
+ applicationConfiguration.language = language.replace('_', '-');
411
+ _Api["default"].setLanguage(applicationConfiguration.language);
412
+ document.documentElement.lang = language.substring(0, 2);
413
+ (0, _Translations.initLanguage)(applicationConfiguration.language, applicationConfiguration.network.baseURL);
414
+ })["catch"](function (error) {
395
415
  // eslint-disable-next-line no-console
396
- console.warn("The selected language (".concat(language, ") is not listed in the available languages!"));
397
- }
398
- applicationConfiguration.language = language.replace('_', '-');
399
- _Api["default"].setLanguage(applicationConfiguration.language);
400
- document.documentElement.lang = language.substring(0, 2);
401
- (0, _Translations.initLanguage)(applicationConfiguration.language, applicationConfiguration.network.baseURL);
416
+ console.error('Error by loading api default language!', error);
417
+ });
402
418
  }
403
419
 
404
420
  // backward compatibility alias
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@configuratorware/configurator-frontendgui",
3
- "version": "1.49.5",
3
+ "version": "1.49.6",
4
4
  "license": "UNLICENSED",
5
5
  "private": false,
6
6
  "main": "./index.js",
7
7
  "dependencies": {
8
8
  "@babel/polyfill": "^7.12.1",
9
- "@configuratorware/scripts": "1.49.5",
9
+ "@configuratorware/scripts": "1.49.6",
10
10
  "@material-ui/core": "^4.12.4",
11
11
  "@material-ui/icons": "^4.11.3",
12
12
  "@material-ui/lab": "^4.0.0-alpha.61",
@@ -36,8 +36,8 @@
36
36
  "react-router-dom": "^5.3.4",
37
37
  "react-swipeable": "^5.5.1",
38
38
  "react-zoom-pan-pinch": "^2.1.3",
39
- "redhotmagma-graphics-editor": "1.49.5",
40
- "redhotmagma-visualization": "1.49.5",
39
+ "redhotmagma-graphics-editor": "1.49.6",
40
+ "redhotmagma-visualization": "1.49.6",
41
41
  "redux": "^4.1.0",
42
42
  "redux-logger": "^3.0.6",
43
43
  "redux-persist": "^5.10.0",
@@ -404,41 +404,67 @@ export function setConfiguration(customApplicationConfiguration) {
404
404
 
405
405
  function setLanguage() {
406
406
  let language;
407
- // if the default language is defined in the configuration
408
- if (applicationConfiguration.language) {
409
- language = applicationConfiguration.language;
410
- }
411
- // if there is a locales array in the configuration...
412
- else if (applicationConfiguration.locales) {
413
- const browserLanguage = get(navigator, 'languages[0]', navigator.language).replace('-', '_');
414
- const matchToBrowserLanguage = find(applicationConfiguration.locales, { code: browserLanguage });
415
- const preferred = find(applicationConfiguration.locales, { preferred: true });
416
-
417
- // if there is a match with the browser language use that
418
- if (matchToBrowserLanguage) {
419
- language = matchToBrowserLanguage.code;
420
- }
421
- // if the preferred language is set use it
422
- else if (preferred) {
423
- language = preferred.code;
424
- }
425
- // otherwise use the first from the locales list
426
- else {
427
- language = first(applicationConfiguration.locales).code;
428
- }
429
- }
430
- // we have no info about the language, so try to use the browser language
431
- else {
432
- language = get(navigator, 'languages[0]', navigator.language).replace('-', '_') || 'de_DE';
433
- }
434
- if (!find(applicationConfiguration.locales, { code: language })) {
435
- // eslint-disable-next-line no-console
436
- console.warn(`The selected language (${language}) is not listed in the available languages!`);
437
- }
438
- applicationConfiguration.language = language.replace('_', '-');
439
- Api.setLanguage(applicationConfiguration.language);
440
- document.documentElement.lang = language.substring(0, 2);
441
- initLanguage(applicationConfiguration.language, applicationConfiguration.network.baseURL);
407
+ //fetch default language and set
408
+ Api.request({
409
+ url: 'languages',
410
+ })
411
+ .then(response => {
412
+ language = response.data.find(lang => lang.isDefault)?.iso;
413
+ // if the default language is defined in the configuration
414
+ if (applicationConfiguration.language) {
415
+ language = applicationConfiguration.language;
416
+ } else if (!language) {
417
+ // if there is a locales array in the configuration...
418
+ if (applicationConfiguration.locales) {
419
+ const browserLanguage = get(navigator, 'languages[0]', navigator.language).replace(
420
+ '-',
421
+ '_'
422
+ );
423
+ const matchToBrowserLanguage = find(applicationConfiguration.locales, {
424
+ code: browserLanguage,
425
+ });
426
+ const preferred = find(applicationConfiguration.locales, {
427
+ preferred: true,
428
+ });
429
+
430
+ // if there is a match with the browser language use that
431
+ if (matchToBrowserLanguage) {
432
+ language = matchToBrowserLanguage.code;
433
+ }
434
+ // if the preferred language is set use it
435
+ else if (preferred) {
436
+ language = preferred.code;
437
+ }
438
+ // otherwise use the first from the locales list
439
+ else {
440
+ language = first(applicationConfiguration.locales).code;
441
+ }
442
+ }
443
+ // we have no info about the language, so try to use the browser language
444
+ else {
445
+ language =
446
+ get(navigator, 'languages[0]', navigator.language).replace('-', '_') || 'de_DE';
447
+ }
448
+ }
449
+
450
+ if (
451
+ !find(applicationConfiguration.locales, {
452
+ code: language.replace('-', '_'),
453
+ })
454
+ ) {
455
+ // eslint-disable-next-line no-console
456
+ console.warn(`The selected language (${language}) is not listed in the available languages!`);
457
+ language = find(applicationConfiguration.locales, { preferred: true }).code;
458
+ }
459
+ applicationConfiguration.language = language.replace('_', '-');
460
+ Api.setLanguage(applicationConfiguration.language);
461
+ document.documentElement.lang = language.substring(0, 2);
462
+ initLanguage(applicationConfiguration.language, applicationConfiguration.network.baseURL);
463
+ })
464
+ .catch(error => {
465
+ // eslint-disable-next-line no-console
466
+ console.error('Error by loading api default language!', error);
467
+ });
442
468
  }
443
469
 
444
470
  // backward compatibility alias