Skip to content

How to create Multilanguage component or layout? #457

Answered by oscarotero
cawa-93 asked this question in Q&A
Discussion options

You must be logged in to vote

The Multilanguage plugin doesn't transform the data from layouts or components, only pages. You can store this value in a _data file, so it's used by all pages and passed to the layout.

If you want to keep the copies in the layout file, you can do something like this:

export const copies = {
    uk: { switchLang: 'Switch language' },
    en: { switchLang: 'Змінити мову' },
};

export default ({children, comp, alternates, lang, copies}) => {
    const langLinkToDisplay = alternates.find(a => a.lang !== lang)
    const switchLang = copies[lang].switchLang;

    return (
        <>
            <header>
              <a href={langLinkToDisplay.url}>
                  <img src="..."  alt={swit…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cawa-93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants