@discord/intl-loader-core 0.6.1 → 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 +2 -2
- package/src/processing.js +25 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/intl-loader-core",
|
|
3
|
-
"version": "0.6.
|
|
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.6.
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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);
|