@medusajs/translation 3.0.0-snapshot-20251215083939 → 3.0.0-snapshot-20251216103925
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/loaders/config.d.ts +4 -0
- package/dist/loaders/config.d.ts.map +1 -0
- package/dist/loaders/config.js +9 -0
- package/dist/loaders/config.js.map +1 -0
- package/dist/migrations/Migration20251215083927.d.ts +6 -0
- package/dist/migrations/Migration20251215083927.d.ts.map +1 -0
- package/dist/migrations/Migration20251215083927.js +14 -0
- package/dist/migrations/Migration20251215083927.js.map +1 -0
- package/dist/models/translation.d.ts +1 -0
- package/dist/models/translation.d.ts.map +1 -1
- package/dist/models/translation.js +2 -1
- package/dist/models/translation.js.map +1 -1
- package/dist/services/translation-module.d.ts +8 -1
- package/dist/services/translation-module.d.ts.map +1 -1
- package/dist/services/translation-module.js +132 -1
- package/dist/services/translation-module.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/compute-translated-field-count.d.ts +12 -0
- package/dist/utils/compute-translated-field-count.d.ts.map +1 -0
- package/dist/utils/compute-translated-field-count.js +23 -0
- package/dist/utils/compute-translated-field-count.js.map +1 -0
- package/dist/utils/constants.d.ts +2 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/translatable-fields.d.ts +19 -0
- package/dist/utils/translatable-fields.d.ts.map +1 -0
- package/dist/utils/translatable-fields.js +38 -0
- package/dist/utils/translatable-fields.js.map +1 -0
- package/package.json +4 -4
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,MAAM,8BAA8B,CAAA;AAKnE,eAAO,MAAM,kBAAkB,gBAAgB,CAAA;;;;AAE/C,wBAGE"}
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.TRANSLATION_MODULE = void 0;
|
|
7
7
|
const translation_module_1 = __importDefault(require("./services/translation-module"));
|
|
8
8
|
const defaults_1 = __importDefault(require("./loaders/defaults"));
|
|
9
|
+
const config_1 = __importDefault(require("./loaders/config"));
|
|
9
10
|
const utils_1 = require("@medusajs/framework/utils");
|
|
10
11
|
exports.TRANSLATION_MODULE = "translation";
|
|
11
12
|
exports.default = (0, utils_1.Module)(exports.TRANSLATION_MODULE, {
|
|
12
13
|
service: translation_module_1.default,
|
|
13
|
-
loaders: [defaults_1.default],
|
|
14
|
+
loaders: [defaults_1.default, config_1.default],
|
|
14
15
|
});
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sFAAmE;AACnE,kEAA6C;AAC7C,qDAAkD;AAErC,QAAA,kBAAkB,GAAG,aAAa,CAAA;AAE/C,kBAAe,IAAA,cAAM,EAAC,0BAAkB,EAAE;IACxC,OAAO,EAAE,4BAAwB;IACjC,OAAO,EAAE,CAAC,kBAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sFAAmE;AACnE,kEAA6C;AAC7C,8DAAyC;AACzC,qDAAkD;AAErC,QAAA,kBAAkB,GAAG,aAAa,CAAA;AAE/C,kBAAe,IAAA,cAAM,EAAC,0BAAkB,EAAE;IACxC,OAAO,EAAE,4BAAwB;IACjC,OAAO,EAAE,CAAC,kBAAY,EAAE,gBAAU,CAAC;CACpC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/loaders/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;yBAKnC,eAAe,aAAa,KAAG,OAAO,CAAC,IAAI,CAAC;AAAlE,wBAKC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../utils/constants");
|
|
4
|
+
const awilix_1 = require("awilix");
|
|
5
|
+
const translatable_fields_1 = require("../utils/translatable-fields");
|
|
6
|
+
exports.default = async ({ container }) => {
|
|
7
|
+
container.register(constants_1.TRANSLATABLE_FIELDS_CONFIG_KEY, (0, awilix_1.asValue)(translatable_fields_1.translatableFieldsConfig));
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/loaders/config.ts"],"names":[],"mappings":";;AACA,gDAAiE;AACjE,mCAAgC;AAChC,sEAAuE;AAEvE,kBAAe,KAAK,EAAE,EAAE,SAAS,EAAiB,EAAiB,EAAE;IACnE,SAAS,CAAC,QAAQ,CAChB,0CAA8B,EAC9B,IAAA,gBAAO,EAAC,8CAAwB,CAAC,CAClC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20251215083927.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20251215083927.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAA;AAEpE,qBAAa,uBAAwB,SAAQ,SAAS;IACrC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAMnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAKrC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration20251215083927 = void 0;
|
|
4
|
+
const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
|
|
5
|
+
class Migration20251215083927 extends migrations_1.Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
this.addSql(`alter table if exists "translation" add column if not exists "translated_field_count" integer not null default 0;`);
|
|
8
|
+
}
|
|
9
|
+
async down() {
|
|
10
|
+
this.addSql(`alter table if exists "translation" drop column if exists "translated_field_count";`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Migration20251215083927 = Migration20251215083927;
|
|
14
|
+
//# sourceMappingURL=Migration20251215083927.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Migration20251215083927.js","sourceRoot":"","sources":["../../src/migrations/Migration20251215083927.ts"],"names":[],"mappings":";;;AAAA,yEAAoE;AAEpE,MAAa,uBAAwB,SAAQ,sBAAS;IAC3C,KAAK,CAAC,EAAE;QACf,IAAI,CAAC,MAAM,CACT,mHAAmH,CACpH,CAAA;IACH,CAAC;IAEQ,KAAK,CAAC,IAAI;QACjB,IAAI,CAAC,MAAM,CACT,qFAAqF,CACtF,CAAA;IACH,CAAC;CACF;AAZD,0DAYC"}
|
|
@@ -4,6 +4,7 @@ declare const Translation: import("@medusajs/framework/utils").DmlEntity<import(
|
|
|
4
4
|
reference: import("@medusajs/framework/utils").TextProperty;
|
|
5
5
|
locale_code: import("@medusajs/framework/utils").TextProperty;
|
|
6
6
|
translations: import("@medusajs/framework/utils").JSONProperty;
|
|
7
|
+
translated_field_count: import("@medusajs/framework/utils").NumberProperty;
|
|
7
8
|
}>, "translation">;
|
|
8
9
|
export default Translation;
|
|
9
10
|
//# sourceMappingURL=translation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation.d.ts","sourceRoot":"","sources":["../../src/models/translation.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"translation.d.ts","sourceRoot":"","sources":["../../src/models/translation.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,WAAW;;;;;;;kBA0Bb,CAAA;AAEJ,eAAe,WAAW,CAAA"}
|
|
@@ -7,7 +7,8 @@ const Translation = utils_1.model
|
|
|
7
7
|
reference_id: utils_1.model.text().searchable(),
|
|
8
8
|
reference: utils_1.model.text().searchable(), // e.g., "product", "product_variant", "product_category"
|
|
9
9
|
locale_code: utils_1.model.text().searchable(), // BCP 47 language tag, e.g., "en-US", "da-DK"
|
|
10
|
-
translations: utils_1.model.json(),
|
|
10
|
+
translations: utils_1.model.json(),
|
|
11
|
+
translated_field_count: utils_1.model.number().default(0), // Precomputed count of translated fields for performance
|
|
11
12
|
})
|
|
12
13
|
.indexes([
|
|
13
14
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation.js","sourceRoot":"","sources":["../../src/models/translation.ts"],"names":[],"mappings":";;AAAA,qDAAiD;AAEjD,MAAM,WAAW,GAAG,aAAK;KACtB,MAAM,CAAC,aAAa,EAAE;IACrB,EAAE,EAAE,aAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE;IAC9C,YAAY,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE;IACvC,SAAS,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,EAAE,yDAAyD;IAC/F,WAAW,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,EAAE,8CAA8C;IACtF,YAAY,EAAE,aAAK,CAAC,IAAI,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"translation.js","sourceRoot":"","sources":["../../src/models/translation.ts"],"names":[],"mappings":";;AAAA,qDAAiD;AAEjD,MAAM,WAAW,GAAG,aAAK;KACtB,MAAM,CAAC,aAAa,EAAE;IACrB,EAAE,EAAE,aAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE;IAC9C,YAAY,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE;IACvC,SAAS,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,EAAE,yDAAyD;IAC/F,WAAW,EAAE,aAAK,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,EAAE,8CAA8C;IACtF,YAAY,EAAE,aAAK,CAAC,IAAI,EAAE;IAC1B,sBAAsB,EAAE,aAAK,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,yDAAyD;CAC7G,CAAC;KACD,OAAO,CAAC;IACP;QACE,EAAE,EAAE,CAAC,cAAc,EAAE,aAAa,CAAC;QACnC,MAAM,EAAE,IAAI;KACb;IACD;QACE,EAAE,EAAE,CAAC,cAAc,EAAE,WAAW,EAAE,aAAa,CAAC;KACjD;IACD;QACE,EAAE,EAAE,CAAC,WAAW,EAAE,aAAa,CAAC;KACjC;IACD;QACE,EAAE,EAAE,CAAC,cAAc,EAAE,WAAW,CAAC;KAClC;IACD;QACE,EAAE,EAAE,CAAC,aAAa,CAAC;KACpB;CACF,CAAC,CAAA;AAEJ,kBAAe,WAAW,CAAA"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Context, CreateTranslationDTO, DAL, FilterableTranslationProps, FindConfig, ITranslationModuleService, ModulesSdkTypes, TranslationTypes } from "@medusajs/framework/types";
|
|
2
2
|
import Locale from "../models/locale";
|
|
3
3
|
import Translation from "../models/translation";
|
|
4
|
+
import { TRANSLATABLE_FIELDS_CONFIG_KEY } from "../utils/constants";
|
|
4
5
|
type InjectedDependencies = {
|
|
5
6
|
baseRepository: DAL.RepositoryService;
|
|
6
7
|
translationService: ModulesSdkTypes.IMedusaInternalService<typeof Translation>;
|
|
7
8
|
localeService: ModulesSdkTypes.IMedusaInternalService<typeof Locale>;
|
|
9
|
+
[TRANSLATABLE_FIELDS_CONFIG_KEY]: Record<string, string[]>;
|
|
8
10
|
};
|
|
9
11
|
declare const TranslationModuleService_base: import("@medusajs/framework/utils").MedusaServiceReturnType<{
|
|
10
12
|
Locale: {
|
|
@@ -18,7 +20,8 @@ export default class TranslationModuleService extends TranslationModuleService_b
|
|
|
18
20
|
protected baseRepository_: DAL.RepositoryService;
|
|
19
21
|
protected translationService_: ModulesSdkTypes.IMedusaInternalService<typeof Translation>;
|
|
20
22
|
protected localeService_: ModulesSdkTypes.IMedusaInternalService<typeof Locale>;
|
|
21
|
-
|
|
23
|
+
private readonly translatableFieldsConfig_;
|
|
24
|
+
constructor({ baseRepository, translationService, localeService, translatableFieldsConfig, }: InjectedDependencies);
|
|
22
25
|
static prepareFilters(filters: FilterableTranslationProps): FilterableTranslationProps;
|
|
23
26
|
listTranslations(filters?: FilterableTranslationProps, config?: FindConfig<TranslationTypes.TranslationDTO>, sharedContext?: Context): Promise<TranslationTypes.TranslationDTO[]>;
|
|
24
27
|
listAndCountTranslations(filters?: FilterableTranslationProps, config?: FindConfig<TranslationTypes.TranslationDTO>, sharedContext?: Context): Promise<[TranslationTypes.TranslationDTO[], number]>;
|
|
@@ -26,6 +29,10 @@ export default class TranslationModuleService extends TranslationModuleService_b
|
|
|
26
29
|
createLocales(data: TranslationTypes.CreateLocaleDTO, sharedContext?: Context): Promise<TranslationTypes.LocaleDTO>;
|
|
27
30
|
createTranslations(data: CreateTranslationDTO, sharedContext?: Context): Promise<TranslationTypes.TranslationDTO>;
|
|
28
31
|
createTranslations(data: CreateTranslationDTO[], sharedContext?: Context): Promise<TranslationTypes.TranslationDTO[]>;
|
|
32
|
+
updateTranslations(data: TranslationTypes.UpdateTranslationDTO, sharedContext?: Context): Promise<TranslationTypes.TranslationDTO>;
|
|
33
|
+
updateTranslations(data: TranslationTypes.UpdateTranslationDTO[], sharedContext?: Context): Promise<TranslationTypes.TranslationDTO[]>;
|
|
34
|
+
getTranslatableFields(entityType?: string): Record<string, string[]>;
|
|
35
|
+
getStatistics(input: TranslationTypes.TranslationStatisticsInput, sharedContext?: Context): Promise<TranslationTypes.TranslationStatisticsOutput>;
|
|
29
36
|
}
|
|
30
37
|
export {};
|
|
31
38
|
//# sourceMappingURL=translation-module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-module.d.ts","sourceRoot":"","sources":["../../src/services/translation-module.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,oBAAoB,EACpB,GAAG,EACH,0BAA0B,EAC1B,UAAU,EACV,yBAAyB,EAEzB,eAAe,EACf,gBAAgB,EACjB,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"translation-module.d.ts","sourceRoot":"","sources":["../../src/services/translation-module.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,oBAAoB,EACpB,GAAG,EACH,0BAA0B,EAC1B,UAAU,EACV,yBAAyB,EAEzB,eAAe,EACf,gBAAgB,EACjB,MAAM,2BAA2B,CAAA;AAUlC,OAAO,MAAM,MAAM,gBAAgB,CAAA;AACnC,OAAO,WAAW,MAAM,qBAAqB,CAAA;AAE7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAA;AAEjE,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,GAAG,CAAC,iBAAiB,CAAA;IACrC,kBAAkB,EAAE,eAAe,CAAC,sBAAsB,CAAC,OAAO,WAAW,CAAC,CAAA;IAC9E,aAAa,EAAE,eAAe,CAAC,sBAAsB,CAAC,OAAO,MAAM,CAAC,CAAA;IACpE,CAAC,8BAA8B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CAC3D,CAAA;;YAIW;QACN,GAAG,EAAE,gBAAgB,CAAC,SAAS,CAAA;KAChC;iBACY;QACX,GAAG,EAAE,gBAA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,gBAAgB,CAAC,cAAc,CAAC;IAG3C,kBAAkB,CAChB,IAAI,EAAE,oBAAoB,EAAE,EAC5B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,gBAAgB,CAAC,cAAc,EAAE,CAAC;IAkC7C,kBAAkB,CAChB,IAAI,EAAE,gBAAgB,CAAC,oBAAoB,EAC3C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,gBAAgB,CAAC,cAAc,CAAC;IAE3C,kBAAkB,CAChB,IAAI,EAAE,gBAAgB,CAAC,oBAAoB,EAAE,EAC7C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,gBAAgB,CAAC,cAAc,EAAE,CAAC;IA8D7C,qBAAqB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAQ9D,aAAa,CACjB,KAAK,EAAE,gBAAgB,CAAC,0BAA0B,EACjC,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,gBAAgB,CAAC,2BAA2B,CAAC;CA0GzD"}
|
|
@@ -16,18 +16,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const core_1 = require("@medusajs/framework/mikro-orm/core");
|
|
19
|
+
const types_1 = require("@medusajs/framework/types");
|
|
19
20
|
const utils_1 = require("@medusajs/framework/utils");
|
|
20
21
|
const locale_1 = __importDefault(require("../models/locale"));
|
|
21
22
|
const translation_1 = __importDefault(require("../models/translation"));
|
|
23
|
+
const compute_translated_field_count_1 = require("../utils/compute-translated-field-count");
|
|
24
|
+
const constants_1 = require("../utils/constants");
|
|
22
25
|
class TranslationModuleService extends (0, utils_1.MedusaService)({
|
|
23
26
|
Locale: locale_1.default,
|
|
24
27
|
Translation: translation_1.default,
|
|
25
28
|
}) {
|
|
26
|
-
constructor({ baseRepository, translationService, localeService, }) {
|
|
29
|
+
constructor({ baseRepository, translationService, localeService, translatableFieldsConfig, }) {
|
|
27
30
|
super(...arguments);
|
|
28
31
|
this.baseRepository_ = baseRepository;
|
|
29
32
|
this.translationService_ = translationService;
|
|
30
33
|
this.localeService_ = localeService;
|
|
34
|
+
this.translatableFieldsConfig_ = translatableFieldsConfig;
|
|
31
35
|
}
|
|
32
36
|
static prepareFilters(filters) {
|
|
33
37
|
let { q, ...restFilters } = filters;
|
|
@@ -71,11 +75,121 @@ class TranslationModuleService extends (0, utils_1.MedusaService)({
|
|
|
71
75
|
const normalizedData = dataArray.map((translation) => ({
|
|
72
76
|
...translation,
|
|
73
77
|
locale_code: (0, utils_1.normalizeLocale)(translation.locale_code),
|
|
78
|
+
translated_field_count: (0, compute_translated_field_count_1.computeTranslatedFieldCount)(translation.translations, this.translatableFieldsConfig_[translation.reference]),
|
|
74
79
|
}));
|
|
75
80
|
const createdTranslations = await this.translationService_.create(normalizedData, sharedContext);
|
|
76
81
|
const serialized = await this.baseRepository_.serialize(createdTranslations);
|
|
77
82
|
return Array.isArray(data) ? serialized : serialized[0];
|
|
78
83
|
}
|
|
84
|
+
// @ts-expect-error
|
|
85
|
+
async updateTranslations(data, sharedContext = {}) {
|
|
86
|
+
const dataArray = Array.isArray(data) ? data : [data];
|
|
87
|
+
const updatesWithTranslations = dataArray.filter((d) => d.translations);
|
|
88
|
+
if (updatesWithTranslations.length) {
|
|
89
|
+
const idsNeedingReference = updatesWithTranslations
|
|
90
|
+
.filter((d) => !d.reference)
|
|
91
|
+
.map((d) => d.id);
|
|
92
|
+
let referenceMap = {};
|
|
93
|
+
if (idsNeedingReference.length) {
|
|
94
|
+
const existingTranslations = await this.translationService_.list({ id: idsNeedingReference }, { select: ["id", "reference"] }, sharedContext);
|
|
95
|
+
referenceMap = Object.fromEntries(existingTranslations.map((t) => [t.id, t.reference]));
|
|
96
|
+
}
|
|
97
|
+
for (const update of dataArray) {
|
|
98
|
+
if (update.translations) {
|
|
99
|
+
const reference = update.reference || referenceMap[update.id];
|
|
100
|
+
update.translated_field_count = (0, compute_translated_field_count_1.computeTranslatedFieldCount)(update.translations, this.translatableFieldsConfig_[reference] || []);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const updatedTranslations = await this.translationService_.update(dataArray, sharedContext);
|
|
105
|
+
const serialized = await this.baseRepository_.serialize(updatedTranslations);
|
|
106
|
+
return Array.isArray(data) ? serialized : serialized[0];
|
|
107
|
+
}
|
|
108
|
+
getTranslatableFields(entityType) {
|
|
109
|
+
if (entityType) {
|
|
110
|
+
return { [entityType]: this.translatableFieldsConfig_[entityType] };
|
|
111
|
+
}
|
|
112
|
+
return this.translatableFieldsConfig_;
|
|
113
|
+
}
|
|
114
|
+
async getStatistics(input, sharedContext = {}) {
|
|
115
|
+
const { locales, entities } = input;
|
|
116
|
+
if (!locales || !locales.length) {
|
|
117
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "At least one locale must be provided");
|
|
118
|
+
}
|
|
119
|
+
if (!entities || !Object.keys(entities).length) {
|
|
120
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "At least one entity type must be provided");
|
|
121
|
+
}
|
|
122
|
+
const normalizedLocales = locales.map(utils_1.normalizeLocale);
|
|
123
|
+
const manager = (sharedContext.transactionManager ??
|
|
124
|
+
sharedContext.manager);
|
|
125
|
+
const knex = manager.getKnex();
|
|
126
|
+
const result = {};
|
|
127
|
+
const entityTypes = [];
|
|
128
|
+
for (const entityType of Object.keys(entities)) {
|
|
129
|
+
const translatableFields = this.translatableFieldsConfig_[entityType];
|
|
130
|
+
if (!translatableFields || translatableFields.length === 0) {
|
|
131
|
+
result[entityType] = {
|
|
132
|
+
expected: 0,
|
|
133
|
+
translated: 0,
|
|
134
|
+
missing: 0,
|
|
135
|
+
by_locale: Object.fromEntries(normalizedLocales.map((locale) => [
|
|
136
|
+
locale,
|
|
137
|
+
{ expected: 0, translated: 0, missing: 0 },
|
|
138
|
+
])),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
entityTypes.push(entityType);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (!entityTypes.length) {
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
const { rows } = await knex.raw(`
|
|
149
|
+
SELECT
|
|
150
|
+
reference,
|
|
151
|
+
locale_code,
|
|
152
|
+
COALESCE(SUM(translated_field_count), 0)::int AS translated_field_count
|
|
153
|
+
FROM translation
|
|
154
|
+
WHERE reference = ANY(?)
|
|
155
|
+
AND locale_code = ANY(?)
|
|
156
|
+
AND deleted_at IS NULL
|
|
157
|
+
GROUP BY reference, locale_code
|
|
158
|
+
`, [entityTypes, normalizedLocales]);
|
|
159
|
+
for (const entityType of entityTypes) {
|
|
160
|
+
const translatableFields = this.translatableFieldsConfig_[entityType];
|
|
161
|
+
const fieldsPerEntity = translatableFields.length;
|
|
162
|
+
const entityCount = entities[entityType].count;
|
|
163
|
+
const expectedPerLocale = entityCount * fieldsPerEntity;
|
|
164
|
+
result[entityType] = {
|
|
165
|
+
expected: expectedPerLocale * normalizedLocales.length,
|
|
166
|
+
translated: 0,
|
|
167
|
+
missing: expectedPerLocale * normalizedLocales.length,
|
|
168
|
+
by_locale: Object.fromEntries(normalizedLocales.map((locale) => [
|
|
169
|
+
locale,
|
|
170
|
+
{
|
|
171
|
+
expected: expectedPerLocale,
|
|
172
|
+
translated: 0,
|
|
173
|
+
missing: expectedPerLocale,
|
|
174
|
+
},
|
|
175
|
+
])),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
for (const row of rows) {
|
|
179
|
+
const entityType = row.reference;
|
|
180
|
+
const localeCode = row.locale_code;
|
|
181
|
+
const translatedCount = parseInt(row.translated_field_count, 10) || 0;
|
|
182
|
+
result[entityType].by_locale[localeCode].translated = translatedCount;
|
|
183
|
+
result[entityType].by_locale[localeCode].missing =
|
|
184
|
+
result[entityType].by_locale[localeCode].expected - translatedCount;
|
|
185
|
+
result[entityType].translated += translatedCount;
|
|
186
|
+
}
|
|
187
|
+
for (const entityType of entityTypes) {
|
|
188
|
+
result[entityType].missing =
|
|
189
|
+
result[entityType].expected - result[entityType].translated;
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
79
193
|
}
|
|
80
194
|
exports.default = TranslationModuleService;
|
|
81
195
|
__decorate([
|
|
@@ -116,4 +230,21 @@ __decorate([
|
|
|
116
230
|
__metadata("design:paramtypes", [Object, Object]),
|
|
117
231
|
__metadata("design:returntype", Promise)
|
|
118
232
|
], TranslationModuleService.prototype, "createTranslations", null);
|
|
233
|
+
__decorate([
|
|
234
|
+
(0, utils_1.InjectManager)(),
|
|
235
|
+
(0, utils_1.EmitEvents)()
|
|
236
|
+
// @ts-expect-error
|
|
237
|
+
,
|
|
238
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
239
|
+
__metadata("design:type", Function),
|
|
240
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
241
|
+
__metadata("design:returntype", Promise)
|
|
242
|
+
], TranslationModuleService.prototype, "updateTranslations", null);
|
|
243
|
+
__decorate([
|
|
244
|
+
(0, utils_1.InjectManager)(),
|
|
245
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
|
246
|
+
__metadata("design:type", Function),
|
|
247
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
248
|
+
__metadata("design:returntype", Promise)
|
|
249
|
+
], TranslationModuleService.prototype, "getStatistics", null);
|
|
119
250
|
//# sourceMappingURL=translation-module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-module.js","sourceRoot":"","sources":["../../src/services/translation-module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6DAAwD;
|
|
1
|
+
{"version":3,"file":"translation-module.js","sourceRoot":"","sources":["../../src/services/translation-module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6DAAwD;AACxD,qDAUkC;AAElC,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,GAAE,CAAA;;;;kEAwBjB;AAgBK;IAHL,IAAA,qBAAa,GAAE;IACf,IAAA,kBAAU,GAAE;IACb,mBAAmB;;IAKhB,WAAA,IAAA,qBAAa,GAAE,CAAA;;;;kEAmDjB;AAUK;IADL,IAAA,qBAAa,GAAE;IAGb,WAAA,IAAA,qBAAa,GAAE,CAAA;;;;6DA0GjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/index.ts","../src/loaders/defaults.ts","../src/migrations/Migration20251208124155.ts","../src/models/index.ts","../src/models/locale.ts","../src/models/translation.ts","../src/services/translation-module.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["../src/index.ts","../src/loaders/config.ts","../src/loaders/defaults.ts","../src/migrations/Migration20251208124155.ts","../src/migrations/Migration20251215083927.ts","../src/models/index.ts","../src/models/locale.ts","../src/models/translation.ts","../src/services/translation-module.ts","../src/utils/compute-translated-field-count.ts","../src/utils/constants.ts","../src/utils/translatable-fields.ts"],"version":"5.9.3"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the count of translated fields based on the translatable fields configuration.
|
|
3
|
+
* Only counts fields that are:
|
|
4
|
+
* 1. In the translatableFields array for the entity type
|
|
5
|
+
* 2. Have a non-null, non-empty value in the translations object
|
|
6
|
+
*
|
|
7
|
+
* @param translations - The translations JSON object from the translation record
|
|
8
|
+
* @param translatableFields - Array of field names that are translatable for this entity type
|
|
9
|
+
* @returns The count of translated fields
|
|
10
|
+
*/
|
|
11
|
+
export declare function computeTranslatedFieldCount(translations: Record<string, unknown> | undefined | null, translatableFields: string[] | undefined | null): number;
|
|
12
|
+
//# sourceMappingURL=compute-translated-field-count.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute-translated-field-count.d.ts","sourceRoot":"","sources":["../../src/utils/compute-translated-field-count.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,IAAI,EACxD,kBAAkB,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,GAC9C,MAAM,CASR"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeTranslatedFieldCount = computeTranslatedFieldCount;
|
|
4
|
+
/**
|
|
5
|
+
* Computes the count of translated fields based on the translatable fields configuration.
|
|
6
|
+
* Only counts fields that are:
|
|
7
|
+
* 1. In the translatableFields array for the entity type
|
|
8
|
+
* 2. Have a non-null, non-empty value in the translations object
|
|
9
|
+
*
|
|
10
|
+
* @param translations - The translations JSON object from the translation record
|
|
11
|
+
* @param translatableFields - Array of field names that are translatable for this entity type
|
|
12
|
+
* @returns The count of translated fields
|
|
13
|
+
*/
|
|
14
|
+
function computeTranslatedFieldCount(translations, translatableFields) {
|
|
15
|
+
if (!translations || !translatableFields?.length) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
return translatableFields.filter((field) => {
|
|
19
|
+
const value = translations[field];
|
|
20
|
+
return value != null && value !== "" && value !== "null";
|
|
21
|
+
}).length;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=compute-translated-field-count.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute-translated-field-count.js","sourceRoot":"","sources":["../../src/utils/compute-translated-field-count.ts"],"names":[],"mappings":";;AAUA,kEAYC;AAtBD;;;;;;;;;GASG;AACH,SAAgB,2BAA2B,CACzC,YAAwD,EACxD,kBAA+C;IAE/C,IAAI,CAAC,YAAY,IAAI,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC;QACjD,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACzC,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;QACjC,OAAO,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,MAAM,CAAA;IAC1D,CAAC,CAAC,CAAC,MAAM,CAAA;AACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,6BAA6B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,8BAA8B,GAAG,0BAA0B,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const PRODUCT_TRANSLATABLE_FIELDS: string[];
|
|
2
|
+
export declare const PRODUCT_VARIANT_TRANSLATABLE_FIELDS: string[];
|
|
3
|
+
export declare const PRODUCT_TYPE_TRANSLATABLE_FIELDS: string[];
|
|
4
|
+
export declare const PRODUCT_COLLECTION_TRANSLATABLE_FIELDS: string[];
|
|
5
|
+
export declare const PRODUCT_CATEGORY_TRANSLATABLE_FIELDS: string[];
|
|
6
|
+
export declare const PRODUCT_TAG_TRANSLATABLE_FIELDS: string[];
|
|
7
|
+
export declare const PRODUCT_OPTION_TRANSLATABLE_FIELDS: string[];
|
|
8
|
+
export declare const PRODUCT_OPTION_VALUE_TRANSLATABLE_FIELDS: string[];
|
|
9
|
+
export declare const translatableFieldsConfig: {
|
|
10
|
+
product: string[];
|
|
11
|
+
product_variant: string[];
|
|
12
|
+
product_type: string[];
|
|
13
|
+
product_collection: string[];
|
|
14
|
+
product_category: string[];
|
|
15
|
+
product_tag: string[];
|
|
16
|
+
product_option: string[];
|
|
17
|
+
product_option_value: string[];
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=translatable-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translatable-fields.d.ts","sourceRoot":"","sources":["../../src/utils/translatable-fields.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,UAMvC,CAAA;AACD,eAAO,MAAM,mCAAmC,UAAwB,CAAA;AACxE,eAAO,MAAM,gCAAgC,UAAY,CAAA;AACzD,eAAO,MAAM,sCAAsC,UAAY,CAAA;AAC/D,eAAO,MAAM,oCAAoC,UAA0B,CAAA;AAC3E,eAAO,MAAM,+BAA+B,UAAY,CAAA;AACxD,eAAO,MAAM,kCAAkC,UAAY,CAAA;AAC3D,eAAO,MAAM,wCAAwC,UAAY,CAAA;AAWjE,eAAO,MAAM,wBAAwB;;;;;;;;;CAcpC,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translatableFieldsConfig = exports.PRODUCT_OPTION_VALUE_TRANSLATABLE_FIELDS = exports.PRODUCT_OPTION_TRANSLATABLE_FIELDS = exports.PRODUCT_TAG_TRANSLATABLE_FIELDS = exports.PRODUCT_CATEGORY_TRANSLATABLE_FIELDS = exports.PRODUCT_COLLECTION_TRANSLATABLE_FIELDS = exports.PRODUCT_TYPE_TRANSLATABLE_FIELDS = exports.PRODUCT_VARIANT_TRANSLATABLE_FIELDS = exports.PRODUCT_TRANSLATABLE_FIELDS = void 0;
|
|
4
|
+
exports.PRODUCT_TRANSLATABLE_FIELDS = [
|
|
5
|
+
"title",
|
|
6
|
+
"description",
|
|
7
|
+
"material",
|
|
8
|
+
"subtitle",
|
|
9
|
+
"status",
|
|
10
|
+
];
|
|
11
|
+
exports.PRODUCT_VARIANT_TRANSLATABLE_FIELDS = ["title", "material"];
|
|
12
|
+
exports.PRODUCT_TYPE_TRANSLATABLE_FIELDS = ["value"];
|
|
13
|
+
exports.PRODUCT_COLLECTION_TRANSLATABLE_FIELDS = ["title"];
|
|
14
|
+
exports.PRODUCT_CATEGORY_TRANSLATABLE_FIELDS = ["name", "description"];
|
|
15
|
+
exports.PRODUCT_TAG_TRANSLATABLE_FIELDS = ["value"];
|
|
16
|
+
exports.PRODUCT_OPTION_TRANSLATABLE_FIELDS = ["title"];
|
|
17
|
+
exports.PRODUCT_OPTION_VALUE_TRANSLATABLE_FIELDS = ["value"];
|
|
18
|
+
// export const SHIPPING_OPTION_TRANSLATABLE_FIELDS = ["name"]
|
|
19
|
+
// export const SHIPPING_OPTION_TYPE_TRANSLATABLE_FIELDS = ["label", "description"]
|
|
20
|
+
// export const RETURN_REASON_TRANSLATABLE_FIELDS = [
|
|
21
|
+
// "value",
|
|
22
|
+
// "label",
|
|
23
|
+
// "description",
|
|
24
|
+
// ]
|
|
25
|
+
exports.translatableFieldsConfig = {
|
|
26
|
+
product: exports.PRODUCT_TRANSLATABLE_FIELDS,
|
|
27
|
+
product_variant: exports.PRODUCT_VARIANT_TRANSLATABLE_FIELDS,
|
|
28
|
+
product_type: exports.PRODUCT_TYPE_TRANSLATABLE_FIELDS,
|
|
29
|
+
product_collection: exports.PRODUCT_COLLECTION_TRANSLATABLE_FIELDS,
|
|
30
|
+
product_category: exports.PRODUCT_CATEGORY_TRANSLATABLE_FIELDS,
|
|
31
|
+
product_tag: exports.PRODUCT_TAG_TRANSLATABLE_FIELDS,
|
|
32
|
+
product_option: exports.PRODUCT_OPTION_TRANSLATABLE_FIELDS,
|
|
33
|
+
product_option_value: exports.PRODUCT_OPTION_VALUE_TRANSLATABLE_FIELDS,
|
|
34
|
+
// shipping_option: SHIPPING_OPTION_TRANSLATABLE_FIELDS,
|
|
35
|
+
// shipping_option_type: SHIPPING_OPTION_TYPE_TRANSLATABLE_FIELDS,
|
|
36
|
+
// return_reason: RETURN_REASON_TRANSLATABLE_FIELDS,
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=translatable-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translatable-fields.js","sourceRoot":"","sources":["../../src/utils/translatable-fields.ts"],"names":[],"mappings":";;;AAAa,QAAA,2BAA2B,GAAG;IACzC,OAAO;IACP,aAAa;IACb,UAAU;IACV,UAAU;IACV,QAAQ;CACT,CAAA;AACY,QAAA,mCAAmC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;AAC3D,QAAA,gCAAgC,GAAG,CAAC,OAAO,CAAC,CAAA;AAC5C,QAAA,sCAAsC,GAAG,CAAC,OAAO,CAAC,CAAA;AAClD,QAAA,oCAAoC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;AAC9D,QAAA,+BAA+B,GAAG,CAAC,OAAO,CAAC,CAAA;AAC3C,QAAA,kCAAkC,GAAG,CAAC,OAAO,CAAC,CAAA;AAC9C,QAAA,wCAAwC,GAAG,CAAC,OAAO,CAAC,CAAA;AAEjE,8DAA8D;AAC9D,mFAAmF;AAEnF,qDAAqD;AACrD,aAAa;AACb,aAAa;AACb,mBAAmB;AACnB,IAAI;AAES,QAAA,wBAAwB,GAAG;IACtC,OAAO,EAAE,mCAA2B;IACpC,eAAe,EAAE,2CAAmC;IACpD,YAAY,EAAE,wCAAgC;IAC9C,kBAAkB,EAAE,8CAAsC;IAC1D,gBAAgB,EAAE,4CAAoC;IACtD,WAAW,EAAE,uCAA+B;IAC5C,cAAc,EAAE,0CAAkC;IAClD,oBAAoB,EAAE,gDAAwC;IAE9D,wDAAwD;IACxD,kEAAkE;IAElE,oDAAoD;CACrD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/translation",
|
|
3
|
-
"version": "3.0.0-snapshot-
|
|
3
|
+
"version": "3.0.0-snapshot-20251216103925",
|
|
4
4
|
"description": "Medusa Translation module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"orm:cache:clear": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts MIKRO_ORM_ALLOW_GLOBAL_CLI=true medusa-mikro-orm cache:clear"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@medusajs/framework": "3.0.0-snapshot-
|
|
40
|
-
"@medusajs/test-utils": "3.0.0-snapshot-
|
|
39
|
+
"@medusajs/framework": "3.0.0-snapshot-20251216103925",
|
|
40
|
+
"@medusajs/test-utils": "3.0.0-snapshot-20251216103925"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@medusajs/framework": "3.0.0-snapshot-
|
|
43
|
+
"@medusajs/framework": "3.0.0-snapshot-20251216103925"
|
|
44
44
|
}
|
|
45
45
|
}
|