GithubHelp home page GithubHelp logo

SSR Example about i18n HOT 4 CLOSED

nanostores avatar nanostores commented on August 16, 2024
SSR Example

from i18n.

Comments (4)

ai avatar ai commented on August 16, 2024

Does it helps? https://github.com/nanostores/i18n#server-side-rendering

from i18n.

popuguytheparrot avatar popuguytheparrot commented on August 16, 2024

in this example let locale, i18n will shared for all users on each request.

How can i hydrate locales to store and cleanup on server?

So, in Next.js i need serialised data to gssp props

import { locale } from 'nanostores'

let locale, i18n

if (isServer) {
  locale = atom(db.getUser(userId).locale || parseHttpLocaleHeader())
  i18n = createI18n(locale, {
    async get (code) {
      return JSON.parse(await readFile(`public/translations/${code}.json`))
    }
  })
} else {
  
}

export { locale, i18n }

from i18n.

ai avatar ai commented on August 16, 2024

in this example let locale, i18n will shared for all users on each request.

You need to use your framework’s APIs for this. You can avoid using a separated file for every store and initialize all stores together in some functions like buildContext(). Or you can export store builder from every file.

So, in Next.js i need serialised data to gssp props

Sorry, I do not use Next.js to suggest exact solution.

If you need some specific API, ask for it.

from i18n.

ai avatar ai commented on August 16, 2024

I am closing this issue. We have a similar “What is the best SSR integration” discussion in main Nano Stores repository.

But without an API suggestions from Next.js users I can’t help.

from i18n.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.