P
Prisma•2w ago
om3r

multi language setup in prisma

I have a question is there anyway to make a for example a model name hotel_en and hotel_fr and hotel_de dynamically so I can add multi language , or how can I create multi language similar to booking or expedia , trying to understand how big websites generates multi languages.
3 Replies
Nurul
Nurul•2w ago
Hello @om3r 👋 There isn't a direct way in Prisma to dynamically create models for multiple languages like hotel_en, hotel_fr. You could create a separate model for translations linked to your main model like this which stores translations like this:
model Hotel {
id Int @id @default(autoincrement())
name String
description String
translations HotelTranslation[]
}

model HotelTranslation {
id Int @id @default(autoincrement())
hotelId Int
hotel Hotel @relation(fields: [hotelId], references: [id])
language String
name String
description String
}
model Hotel {
id Int @id @default(autoincrement())
name String
description String
translations HotelTranslation[]
}

model HotelTranslation {
id Int @id @default(autoincrement())
hotelId Int
hotel Hotel @relation(fields: [hotelId], references: [id])
language String
name String
description String
}
You could do something like this as well:
model Hotel {
id Int @id @default(autoincrement())
nameEn String @map("name_en")
nameFr String @map("name_fr")
nameDe String @map("name_de")

@@map("hotels")
}
model Hotel {
id Int @id @default(autoincrement())
nameEn String @map("name_en")
nameFr String @map("name_fr")
nameDe String @map("name_de")

@@map("hotels")
}
om3r
om3rOP•2w ago
thanks for the example but if I have like 1 million hotels with 7 languages , that will make the hotel table has 7 million records ? if so that will make the hotel table alot bigger also i will have to duplicate titles , description and it will make my database model has alot of records.
Nurul
Nurul•2d ago
Other option would be to use a JSON column and store all translations in that column. That approach comes with different overheads though 😄
Want results from more Discord servers?
Add your server