-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
with-i18next example #1496
with-i18next example #1496
Conversation
export async function getTranslation (lang, file, baseUrl) { | ||
const response = await fetch(`${baseUrl}${lang}/${file}.json`) | ||
const json = await response.json() | ||
let translations = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about:
return {
[lang]: {
[file]: json
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much better, updating the code now
@@ -0,0 +1,14 @@ | |||
import i18n from 'i18next' | |||
|
|||
const startI18n = file => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const startI18n = file => i18n.init({
fallbackLng: 'pt',
resources: file,
ns: ['common'],
defaultNS: 'common',
debug: false
})
examples/with-i18next/pages/index.js
Outdated
const isServer = !!req | ||
const translations = await getTranslation('pt', 'common', 'http://localhost:3000/static/locales/') | ||
|
||
return { isServer, translations } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using the isServer
prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really. My bad.
Lingering code from some previous tests...
examples/with-i18next/pages/index.js
Outdated
export default class Homepage extends Component { | ||
static async getInitialProps ({ req }) { | ||
const isServer = !!req | ||
const translations = await getTranslation('pt', 'common', 'http://localhost:3000/static/locales/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to express the full url? What happens if we deploy to a non localhost env? for example we suggest you can use zeit to deploy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the server-side the polyfill requires it to be an absolute url. I couldn't figure a way of going around that. That's why url is a parameter. I'm fully open to suggestions though...
this example shows (what I believe to be) the simplest configuration to use i18next with NextJS