最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nuxt.js - How to translate static data using i18n in Nuxt3 - Stack Overflow

programmeradmin5浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论