I'm trying to make my simple e-commerce website multi-language, the data of products is in local file, myproject/server/api/products/[id].ts, not on external source, because it has just few products.
I knew how to translate using i18n, but they were just sections, and were not api data.
Right now I don't know how to do it, I searched web but didn't find solution, asked from AI, but It seems AI didn't understand me :)
As a Beginner developer I could not try anything, and I ask help of yours.
Example for producst in server / api / products / [id].ts:
export default defineEventHandler(async (event) => {
const id = getRouterParam(event, 'id')
const products = [
{
"id": "1",
"title": "Alpman tabletkalari N60",
"price": 235000,
"img": "/alpman.webp",
"btnText": "Batafsil",
"tgLink": ";,
"about": `< b > Alpman - testosteron darajasini oshiradi va urug' sifatini yaxshilaydi. </>
Uning tarkibiga kiritilgan ...`,
"about_sections": [
{
"title": "Tarkibi va ishlab chiqarilish shakli",
"type": "table",
"content": [
{ name: 'Tribulus', amount: '500mg' },
{ name: 'Uzun bargli evrikoma', amount: '100mg' },
{ name: 'L-arginin', amount: '125mg' },
{ name: 'L-karnitin', amount: '125mg' },
{ name: 'Vitamin E', amount: '7,5mg' },
{ name: 'Koenzim Q10', amount: '100mg' },
{ name: 'Selen', amount: '50mkg' },
{ name: 'Metilfolat', amount: '400mkg' },
{ name: 'Sink', amount: '15mg' },
],
"form": "60ta tabletka flakonda"
},
{
"title": "Qo'llash mumkin bo'lmagan holatlar",
"type": 'text',
"content": `
- Tarkibiy qismlarga individual ko'tarolmaslik;\n
- Uyqusizlik, tajanlik; \n
- Yuqori qon bosimi; \n
- Yurak qon tomir kasalliklari insult, miokard infarkti o‘tkir yoki og‘ir holati; \n
- Yurak qon tomir sistemasining tartibsiz kasalliklari(nestabil stenokardiya, surunkali yurak yetishmovchiligi); \n
- Surunkali buyrak yetishmovchiligi; \n
- 18 yoshdan kichik bo‘lgan bolalar.`
},
{
"title": "Saqlash usuli:",
"type": "text",
"content": `25 °C dan yuqori bo‘lmagan haroratda butinligi buzilmagan holatda saqlansin.\n
Quruq, yorug’likdan himoyalangan, bolalar qo‘li yetmaydigan joyda saqlang. `
},
{
"title": "Yaroqlilik muddati:",
"type": "text",
"content": `2 yil.Qopqoqda ko‘rsatilgan yaroqlilik muddati o‘tgandan so‘ng ishlatmang.`
},
]
},
// ... MORE PRODUCTS
]
return products.find(p => p.id == id) || { error: "Product not found" }
})
PS.Just one product shown above.