Skip to content

Dynamic Routes and translations with getStaticPaths #588

Answered by aralroca
vemec asked this question in Q&A
Discussion options

You must be logged in to vote

@vemec did you tried the returnObjects?

https://github.com/vinissimus/next-translate#7-nested-translations

Example:

dictionary:

{
  "dynamic-translations": {
    "example": "Example {{count}}",
    "another-example": "Another example {{count}}" 
  }
}

t function to return all nested:

t('namespace:dynamic-translations', { count: 1 }, { returnObjects: true })
/*
// RESULT:
{
    "example": "Example 1",
    "another-example": "Another example 1" 
}
*/

Other way (recommended)

Is defining in the i18n.json the page as a function to load different namespaces depending the getStaticPaths params.

"/your-page": ({ params }) => params.story

Otherwise you need to put all the stories namespaces... "/…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
3 replies
@vemec
Comment options

@aralroca
Comment options

@Ogenbd
Comment options

Answer selected by vemec
Comment options

You must be logged in to vote
4 replies
@aralroca
Comment options

@aralroca
Comment options

@vemec
Comment options

@aralroca
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants