@adminforth/i18n 1.0.11 → 1.0.12

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.
package/Changelog.md CHANGED
@@ -5,9 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.12]
9
+
10
+ ### Fixed
11
+
12
+ - live mode frontend translations loading when tmp dir is nopt preserver (e.g. docker cached /tmp pipeline)
13
+
14
+ ## [1.0.11]
15
+
16
+ ### Fixed
17
+
18
+ - cache invalidations on delete
19
+
8
20
  ## [v1.0.10]
9
21
 
10
- ## Fixed
22
+ ### Fixed
11
23
 
12
24
  - fix automatic translations for duplicate strings
13
25
  - improve slavik pluralization generations by splitting the requests
@@ -43,7 +43,7 @@
43
43
  import 'flag-icon-css/css/flag-icons.min.css';
44
44
  import { IconCaretDownSolid } from '@iconify-prerendered/vue-flowbite';
45
45
 
46
- import { setLang, getCountryCodeFromLangCode, getLocalLang } from './langCommon';
46
+ import { setLang, getCountryCodeFromLangCode, getLocalLang, setLocalLang } from './langCommon';
47
47
 
48
48
  import { computed, ref, onMounted, watch } from 'vue';
49
49
  import { useI18n } from 'vue-i18n';
@@ -56,7 +56,7 @@ const props = defineProps(['meta', 'resource']);
56
56
  const selectedLanguage = ref('');
57
57
 
58
58
  function doChangeLang(lang) {
59
- setLang({ setLocaleMessage, locale }, props.meta.pluginInstanceId, lang);
59
+ setLocalLang(lang);
60
60
  // unfortunately, we need this to recall all APIs
61
61
  document.location.reload();
62
62
 
@@ -43,7 +43,7 @@
43
43
  import 'flag-icon-css/css/flag-icons.min.css';
44
44
  import { IconCaretDownSolid } from '@iconify-prerendered/vue-flowbite';
45
45
 
46
- import { setLang, getCountryCodeFromLangCode, getLocalLang } from './langCommon';
46
+ import { setLang, getCountryCodeFromLangCode, getLocalLang, setLocalLang } from './langCommon';
47
47
 
48
48
  import { computed, ref, onMounted, watch } from 'vue';
49
49
  import { useI18n } from 'vue-i18n';
@@ -56,7 +56,7 @@ const props = defineProps(['meta', 'resource']);
56
56
  const selectedLanguage = ref('');
57
57
 
58
58
  function doChangeLang(lang) {
59
- setLang({ setLocaleMessage, locale }, props.meta.pluginInstanceId, lang);
59
+ setLocalLang(lang);
60
60
  // unfortunately, we need this to recall all APIs
61
61
  document.location.reload();
62
62
 
package/dist/index.js CHANGED
@@ -287,7 +287,7 @@ export default class I18N extends AdminForthPlugin {
287
287
  this.updateUntranslatedMenuBadge();
288
288
  return {
289
289
  ok: true, error: undefined,
290
- successMessage: yield tr(`Translated {count} items`, 'frontend', { count: selectedIds.length }),
290
+ successMessage: yield tr(`Translated {count} items`, 'backend', { count: selectedIds.length }),
291
291
  };
292
292
  })
293
293
  });
@@ -469,9 +469,9 @@ ${JSON.stringify(strings.reduce((acc, s) => {
469
469
  }
470
470
  tryProcessAndWatch(adminforth) {
471
471
  return __awaiter(this, void 0, void 0, function* () {
472
- const spaDir = adminforth.codeInjector.spaTmpPath();
472
+ const serveDir = adminforth.codeInjector.getServeDir();
473
473
  // messages file is in i18n-messages.json
474
- const messagesFile = path.join(spaDir, '..', 'spa_tmp', 'i18n-messages.json');
474
+ const messagesFile = path.join(serveDir, 'i18n-messages.json');
475
475
  console.log('🪲messagesFile', messagesFile);
476
476
  this.processExtractedMessages(adminforth, messagesFile);
477
477
  // we use watcher because file can't be yet created when we start - bundleNow can be done in build time or can be done now
@@ -518,10 +518,15 @@ ${JSON.stringify(strings.reduce((acc, s) => {
518
518
  if (!msg) {
519
519
  return msg;
520
520
  }
521
+ if (category === 'frontend') {
522
+ throw new Error(`Category 'frontend' is reserved for frontend messages, use any other category for backend messages`);
523
+ }
521
524
  // console.log('🪲tr', msg, category, lang);
522
525
  // if lang is not supported , throw
523
526
  if (!this.options.supportedLanguages.includes(lang)) {
524
- throw new Error(`Language ${lang} is not entered to be supported by requested by browser in request headers accept-language`);
527
+ lang = 'en'; // for now simply fallback to english
528
+ // throwing like line below might be too strict, e.g. for custom apis made with fetch which don't pass accept-language
529
+ // throw new Error(`Language ${lang} is not entered to be supported by requested by browser in request headers accept-language`);
525
530
  }
526
531
  let result;
527
532
  // try to get translation from cache
package/index.ts CHANGED
@@ -326,7 +326,7 @@ export default class I18N extends AdminForthPlugin {
326
326
  this.updateUntranslatedMenuBadge();
327
327
  return {
328
328
  ok: true, error: undefined,
329
- successMessage: await tr(`Translated {count} items`, 'frontend', {count: selectedIds.length}),
329
+ successMessage: await tr(`Translated {count} items`, 'backend', {count: selectedIds.length}),
330
330
  };
331
331
  }
332
332
  }
@@ -560,15 +560,13 @@ ${
560
560
 
561
561
  // updateBadge
562
562
  this.updateUntranslatedMenuBadge()
563
-
564
-
565
563
  }
566
564
 
567
565
 
568
566
  async tryProcessAndWatch(adminforth: IAdminForth) {
569
- const spaDir = adminforth.codeInjector.spaTmpPath();
567
+ const serveDir = adminforth.codeInjector.getServeDir();
570
568
  // messages file is in i18n-messages.json
571
- const messagesFile = path.join(spaDir, '..', 'spa_tmp', 'i18n-messages.json');
569
+ const messagesFile = path.join(serveDir, 'i18n-messages.json');
572
570
  console.log('🪲messagesFile', messagesFile);
573
571
  this.processExtractedMessages(adminforth, messagesFile);
574
572
  // we use watcher because file can't be yet created when we start - bundleNow can be done in build time or can be done now
@@ -619,11 +617,18 @@ ${
619
617
  if (!msg) {
620
618
  return msg;
621
619
  }
620
+
621
+ if (category === 'frontend') {
622
+ throw new Error(`Category 'frontend' is reserved for frontend messages, use any other category for backend messages`);
623
+ }
622
624
  // console.log('🪲tr', msg, category, lang);
623
625
 
624
626
  // if lang is not supported , throw
625
627
  if (!this.options.supportedLanguages.includes(lang as LanguageCode)) {
626
- throw new Error(`Language ${lang} is not entered to be supported by requested by browser in request headers accept-language`);
628
+ lang = 'en'; // for now simply fallback to english
629
+
630
+ // throwing like line below might be too strict, e.g. for custom apis made with fetch which don't pass accept-language
631
+ // throw new Error(`Language ${lang} is not entered to be supported by requested by browser in request headers accept-language`);
627
632
  }
628
633
 
629
634
  let result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/i18n",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",