@itrocks/framework 0.6.4 → 0.6.5

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/README.md CHANGED
@@ -77,12 +77,12 @@ beforeFrameworkRun(() => import('./src/dependencies'))
77
77
  ### Request languages
78
78
 
79
79
  The framework can select one translation catalog for each request without sharing language state between concurrent
80
- requests. Configure the supported languages and the source language in the application configuration:
80
+ requests. Templates and translation keys are written in English. Configure the supported languages in the application
81
+ configuration:
81
82
 
82
83
  ```yaml
83
84
  translate:
84
85
  defaultLanguage: fr-FR
85
- sourceLanguage: en-US
86
86
  supportedLanguages:
87
87
  - en-US
88
88
  - fr-FR
@@ -90,7 +90,11 @@ translate:
90
90
 
91
91
  The language stored in `request.session.language` takes precedence. Otherwise, the framework negotiates the
92
92
  `Accept-Language` header, matching an exact locale first and then its base language. Unsupported values fall back to
93
- `defaultLanguage`. Every response includes `Content-Language` and varies on `Accept-Language`.
93
+ `defaultLanguage`. The framework loads each `<language>.csv` catalog directly; English needs no catalog because it is
94
+ the source language. Every response includes `Content-Language` and varies on `Accept-Language`.
95
+
96
+ Catalog rows contain lowercase, context-free fragments. Sentence periods stay in templates so the translation engine
97
+ can translate each sentence independently and restore contextual capitalization.
94
98
 
95
99
  ### Using framework reflection helpers
96
100
 
package/cjs/language.js CHANGED
@@ -12,7 +12,6 @@ const translate_3 = require("@itrocks/translate");
12
12
  const node_path_1 = require("node:path");
13
13
  let configuration = {
14
14
  defaultLanguage: 'fr-FR',
15
- sourceLanguage: 'en-US',
16
15
  supportedLanguages: ['fr-FR']
17
16
  };
18
17
  let loading = Promise.resolve(undefined);
@@ -27,14 +26,13 @@ function canonicalLanguage(value) {
27
26
  function configureLanguages() {
28
27
  const options = (config_1.config.translate ?? {});
29
28
  const defaultLanguage = canonicalLanguage(options.defaultLanguage) ?? 'fr-FR';
30
- const sourceLanguage = canonicalLanguage(options.sourceLanguage) ?? 'en-US';
31
29
  const supportedLanguages = options.supportedLanguages
32
30
  .map(language => canonicalLanguage(language))
33
31
  .filter((language) => !!language);
34
32
  if (!supportedLanguages.includes(defaultLanguage)) {
35
33
  supportedLanguages.push(defaultLanguage);
36
34
  }
37
- configuration = { defaultLanguage, sourceLanguage, supportedLanguages: [...new Set(supportedLanguages)] };
35
+ configuration = { defaultLanguage, supportedLanguages: [...new Set(supportedLanguages)] };
38
36
  (0, translate_1.trInit)(defaultLanguage);
39
37
  loading = (async () => {
40
38
  // TODO search language files everywhere in application modules, not only into app
@@ -42,10 +40,7 @@ function configureLanguages() {
42
40
  for (const language of configuration.supportedLanguages) {
43
41
  for (const directory of directories) {
44
42
  const file = (0, node_path_1.join)(directory, language + '.csv');
45
- await (0, translate_2.trLoad)(file, { language });
46
- if ((language !== sourceLanguage) && configuration.supportedLanguages.includes(sourceLanguage)) {
47
- await (0, translate_2.trLoad)(file, { language: sourceLanguage, reverse: true });
48
- }
43
+ await (0, translate_2.trLoad)(file, language);
49
44
  }
50
45
  }
51
46
  })();
package/package.json CHANGED
@@ -103,5 +103,5 @@
103
103
  "build:front": "tsc -p src/front/tsconfig.json && node -e \"const fs=require('node:fs');for(const file of fs.readdirSync('.').filter(file=>file.endsWith('.js')||file.endsWith('.d.ts')))fs.writeFileSync(file,fs.readFileSync(file,'utf8').replaceAll('../../',''))\"",
104
104
  "test": "npm run build && node --test test/*.test.js"
105
105
  },
106
- "version": "0.6.4"
106
+ "version": "0.6.5"
107
107
  }