@discord/intl-loader-core 0.5.2 → 0.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl-loader-core",
3
- "version": "0.5.2",
3
+ "version": "0.6.2",
4
4
  "license": "MIT",
5
5
  "description": "Core utilities for writing loaders and transformers using @discord/intl",
6
6
  "author": "Jon Egeland",
@@ -22,7 +22,7 @@
22
22
  "chokidar": "^3.6.0",
23
23
  "debug": "^4.3.6",
24
24
  "fast-glob": "^3.3.2",
25
- "@discord/intl-message-database": "0.5.2"
25
+ "@discord/intl-message-database": "0.6.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/debug": "^4.1.12"
package/src/processing.js CHANGED
@@ -16,6 +16,26 @@ function debugSourceFile(sourcePath, sourceFile) {
16
16
  );
17
17
  }
18
18
 
19
+ /**
20
+ *
21
+ * @param {string} sourcePath Path of the source file being processed, for debug logging
22
+ * @param {import('@discord/intl-message-database').IntlSourceFile} sourceFile SourceFile object from the database used to find translations.
23
+ * @param {string} translationsPath Fully-resolved path to the directory for translations.
24
+ * @returns {Record<string, string>}
25
+ */
26
+ function buildTranslationsLocaleMap(sourcePath, sourceFile, translationsPath) {
27
+ if (sourceFile.meta.translate === false) {
28
+ debug(`[${sourcePath}] translate is set to false, no locale map is needed`);
29
+ return {};
30
+ }
31
+ const map = findAllTranslationFiles(translationsPath);
32
+ if (map instanceof Error) {
33
+ debug(`[${sourcePath}] Failed to build locale map: [${map.name}] ${map.message}`);
34
+ return {};
35
+ }
36
+ return map;
37
+ }
38
+
19
39
  /**
20
40
  * @param {string} sourcePath
21
41
  * @param {string=} sourceContent
@@ -49,13 +69,11 @@ function processDefinitionsFile(sourcePath, sourceContent, options = {}) {
49
69
 
50
70
  const messageKeys = database.getSourceFileKeyMap(sourcePath);
51
71
  const translationsPath = path.resolve(path.dirname(sourcePath), sourceFile.meta.translationsPath);
52
- let translationsLocaleMap = findAllTranslationFiles(translationsPath);
53
- if (translationsLocaleMap instanceof Error) {
54
- debug(
55
- `[${sourcePath}] Failed to build translations locale map: [${translationsLocaleMap.name}] ${translationsLocaleMap.message}`,
56
- );
57
- translationsLocaleMap = {};
58
- }
72
+ const translationsLocaleMap = buildTranslationsLocaleMap(
73
+ sourcePath,
74
+ sourceFile,
75
+ translationsPath,
76
+ );
59
77
 
60
78
  if (processTranslations) {
61
79
  database.processAllTranslationFiles(translationsLocaleMap);
@@ -121,7 +139,7 @@ function processTranslationsFile(sourcePath, sourceContent, options = {}) {
121
139
  * @returns {Buffer | void}
122
140
  */
123
141
  function precompileFileForLocale(sourcePath, locale, options = {}) {
124
- const { format = IntlCompiledMessageFormat.Json, outputFile } = options;
142
+ const { format = IntlCompiledMessageFormat.KeylessJson, outputFile } = options;
125
143
  return outputFile != null
126
144
  ? database.precompile(sourcePath, locale, outputFile, format)
127
145
  : database.precompileToBuffer(sourcePath, locale, format);
package/src/watcher.js CHANGED
@@ -35,10 +35,17 @@ function processFile(filePath, assetExtension) {
35
35
  // Convert the file name from `.messages.js` to `.compiled.messages.jsona` for output.
36
36
  const outputPath = filePath.replace(/\.messages\.js$/, `.compiled.messages.${assetExtension}`);
37
37
  const result = processDefinitionsFile(filePath);
38
- precompileFileForLocale(filePath, result.locale, { format: IntlCompiledMessageFormat.Json });
38
+ precompileFileForLocale(filePath, result.locale, {
39
+ format: IntlCompiledMessageFormat.KeylessJson,
40
+ });
39
41
 
40
42
  database.processDefinitionsFile(filePath);
41
- database.precompile(filePath, DEFAULT_LOCALE, outputPath, IntlCompiledMessageFormat.Json);
43
+ database.precompile(
44
+ filePath,
45
+ DEFAULT_LOCALE,
46
+ outputPath,
47
+ IntlCompiledMessageFormat.KeylessJson,
48
+ );
42
49
  debug(`Wrote definitions to: ${outputPath}`);
43
50
  } catch (e) {
44
51
  debug('[INTL Error] Failed to compile messages');