Multi-language navigation with slice machine

Hey Prismic
I'm new at Prismic. I just wanted to ask is there any boilerplate for Multi-language and navigation with slice machine, all in one boilerplate?

Hi @nzrahi123,

Thanks for posting, and welcome to the Prismic community :slight_smile:

We don't have a multilanguage example with Slice Machine yet. If you're using Next.js, you could look at the code for our example Slice Machine project and the code for a non-Slice Machine multi-language project. I hope that helps!

Best,
Sam

Hey @samlittlefair Many thanks
I read multilingual-templating

I can not understand how could I get alternate languages in home page and dynamic page.
could you pls give me an example for home page and dynamic page?

In a 〜/pages/[lang]/[uid].js file:

I use :

const PageTemplate = ({ slices, alternate_languages, lang }) => {
  return (
    <section>
      <LanguageSwitcher altLangs={alternate_languages} />
      <SliceZone resolver={resolver} slices={slices}/>
    </section>
  );
};

but alternate_languages is an empty array.

In a 〜/pages/index.js file:
I have no idea how can I get alternate_languages;
I would appreciate it if you could tell me how to resolve it!

Hey @nzrahi123 ,

Could you let me know your repo name so I can take a look at your language settings? (Feel free to send it in a DM if you don't want to share it publicly.)

Sam

Hey @nzrahi123 ,

Thanks for sending your repo name :slight_smile:

It looks like you haven't translated any documents yet. Once you translate a document, the details will start appearing in the alternate languages array.

Let me know if the problem persists, or if I'm misunderstanding.

Sam

aha first I should create a document in a different language? right?
how about getting the alternate language In a 〜/pages/index.js file:

@nzrahi123 The process should be the same. In your index file, I assume you're querying a document from Prismic (maybe a "homepage" document). That document will have an alternate_languages array.

You'll need to decide how you want to link to alternate languages on the homepage. You might have:

  • / as your default language
  • /cc-dd as a secondary language

Or, you could just make

  • / redirect to your primary language, /aa-bb
  • /cc-dd as your secondary language

Of course, I'm sure there are many other ways to handle this as well.

Let me know if you have any other questions.

Sam