1 import { model } from "@medusajs/framework/utils"
2
3 const Translation = model
4 .define("translation", {
5 id: model.id({ prefix: "trans" }).primaryKey(),
6 /**
7 * The ID of the entity that the translation belongs to. For example, the ID of a product or a product variant.
8 */
9 reference_id: model.text().searchable(),
10 /**
11 * The name of the table that the translation belongs to. For example, "product" or "product_variant".
12 */
13 reference: model.text().searchable(),
14 /**
15 * The BCP 47 language tag code of the locale
16 *
17 * @example
18 * "en-US"
19 */
20 locale_code: model.text().searchable(),
21 /**
22 * The translations of the entity.
23 * The object's keys are the field names of the entity, and its value is the translated value.
24 *
25 * @example
26 * {
27 * "title": "Product Title",
28 * "description": "Product Description",
29 * }
30 */
31 translations: model.json(),
32 /**
33 * Precomputed count of translated fields of a resource.
34 * Useful for optimization purposes.
35 */
36 translated_field_count: model.number().default(0),
37 })
38 .indexes([
39 {
40 on: ["reference_id", "locale_code"],
41 unique: true,
42 },
43 {
44 on: ["reference_id", "reference", "locale_code"],
45 },
46 {
47 on: ["reference", "locale_code"],
48 },
49 {
50 on: ["reference_id", "reference"],
51 },
52 {
53 on: ["locale_code"],
54 },
55 ])
56
57 export default Translation