-
Hi!👋 First of all, thank you very much for developing this excellent project. I have a dynamic page that expects a "story" parameter. I would like to be able to get all the page translations (similar to when I use Is it possible to do this? File // Core
import getT from 'next-translate/getT'
// Layout
import PublicLayout from '@/layout/public'
const Story = ({ story, section }) => {
const current = { canonical: `/chat-stories/${story}` }
return (
<PublicLayout current={current}>
<p>{story}</p>
<p>{section}</p>
</PublicLayout>
)
}
export async function getStaticPaths({ locales }) {
const paths = []
const stories = ['a', 'b', 'c']
locales.forEach((locale) => {
stories.forEach((story) => {
paths.push({ params: { story }, locale })
});
});
return { paths, fallback: true }
}
export async function getStaticProps({ params, locale }) {
const t = await getT(locale, `${params.story}`)
return {
props: {
story: params.story,
section: t('section'),
},
}
}
export default Story Something like this, but this example doesn't work // Core
import useTranslation from 'next-translate/useTranslation'
// Layout
import PublicLayout from '@/layout/public'
const Story = ({ story }) => {
const { t } = useTranslation(`${story}`)
const current = { canonical: `/chat-stories/${story}` }
return (
<PublicLayout current={current}>
<p>{t('section')}</p>
</PublicLayout>
)
}
export async function getStaticPaths({ locales }) {
const paths = []
const stories = ['a', 'b', 'c']
locales.forEach((locale) => {
stories.forEach((story) => {
paths.push({ params: { story }, locale })
});
});
return { paths, fallback: true }
}
export async function getStaticProps({ params }) {
return { props: { story: params.story } }
}
export default Story Sorry for my basic English :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
@vemec did you tried the 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
Otherwise you need to put all the stories namespaces... |
Beta Was this translation helpful? Give feedback.
-
Hey @aralroca, I hope you are well. I have one more question regarding this scenario... How can I have HTML inside the translations that come from the returnObjects using , like this: Get translations in object form const feature = t('home:features', {}, { returnObjects: true }) I got this {
title: 'the title',
subTitle: 'the subtitle',
description: '<0>some text</0> another text and <1>More more</1>',
} and then when I want to replace the <Trans
i18nKey={`${feature.description}`}
components={[<span />, <strong />]}
/> I get the warning
but replacing Is there any other way? |
Beta Was this translation helpful? Give feedback.
@vemec did you tried the
returnObjects
?https://github.com/vinissimus/next-translate#7-nested-translations
Example:
dictionary:
t function to return all nested:
Other way (recommended)
Is defining in the
i18n.json
the page as a function to load different namespaces depending thegetStaticPaths
params.Otherwise you need to put all the stories namespaces...
"/…