question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom localePath is not work when navigate or change language

See original GitHub issue

I use next and express to create server. I use next-i18next to create multilingual web app. I have project structure

├── dist/      # Built files
├── public/    # Static files (locales)
└── src / 
    ├── component/      # Components
    ├── lib/            # Store i18n.js
    ├── pages/          # Pages
    └── server.js

And file i18n.js

const NextI18Next = require('next-i18next')

module.exports = new NextI18Next({
  localeSubpaths: true,
  otherLanguages: ['fr'],
  localePath: 'public/locales/'
})

Everything work fine on page start. But when I navigate to other page with Link provided by this lib or change language with i18n.changeLanguage(i18n.language === 'en' ? 'fr' : 'en')}. The new language is not loaded properly.

I found that the server is still try to download the locale files from /static/locales

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vimutti77commented, Dec 20, 2018

I have found the solution. just use express.static to map static path to target path like

server.use('/static/', express.static(path.join(__dirname, '../public')))

And problem is now gone.

0reactions
kachkaevcommented, Dec 20, 2018

I’ve reflected on this problem in https://github.com/isaachinman/next-i18next/issues/42, which I’d like to discuss first before submitting the PRs with fixes 😉 I refer to localePath as pathToTranslations there. Will get back to you when I’ve got some time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom localePath is not work when navigate or change ...
Everything work fine on page start. But when I navigate to other page with Link provided by this lib or change language with...
Read more >
Language Switcher doesn't apply the new locale
I was looking for this anwer, but I have a problem, his.$router.replace(this.switchLocalePath(language)); only changes URL but does not refresh ...
Read more >
Advanced Features: Internationalized Routing
Generally a Locale Identifier is made up of a language, region, and script separated by a dash: language-region-script . The region and script...
Read more >
Translation | Django documentation
LocaleMiddleware ). If you haven't yet, see How Django discovers language preference. ... Specify a translation string by using the function gettext() ....
Read more >
leancoders/next-i18next
If you want to structure your translations/namespaces in a custom way, you will need to pass modified localePath and localeStructure values ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found