Skip to content
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

localePath('/career/my-slug') not returning default locales translation #1055

Closed
katerlouis opened this issue Feb 8, 2021 · 5 comments
Closed

Comments

@katerlouis
Copy link

katerlouis commented Feb 8, 2021

Version

nuxt-i18n: 6.20.0
nuxt: ^2.12.2

Nuxt-i18n configuration

If relevant, please include the configuration you are using for this module.
For example:
export default {
  locales: [
    {
      code: 'de',
      iso: 'de-DE', // https://www.science.co.il/language/Locale-codes.php
      name: 'Deutsch',
      file: 'de-DE.json',
    }, {
      code: 'en',
      iso: 'en-US',
      name: 'English',
      file: 'en-US.json',
    },
  ],

  defaultLocale: 'de',

  // no `~/` necessary – nuxt automatically looks inside folder provided by `srcDir` in `nuxt.config.js`
  langDir: 'locales/',

  // needs to be `true` for language files to work
  lazy: true,

  seo: true,

  vueI18n: {
    // some test messages for nuxt's automatic route generation setup
    // must be in this file and not in locale files
    messages: {
      en: {
        welcome: 'Welcome',
      },
      de: {
        welcome: 'Willkommen',
      },
    },
    fallbackLocale: 'de',
  },
};

Reproduction Link

https://codesandbox.io/s/nuxt-i18n-localepath-test-3d651?file=/pages/career/index.vue

Steps to reproduce

go to /career and read the template and script snippets

What is Expected?

localePath('/career/my-slug') to return the translated url for my default locale DE: /karriere/my-slug

What is actually happening?

It's returning /career/my-slug, although the default locale is DE

@rchl
Copy link
Collaborator

rchl commented Feb 8, 2021

detectBrowserLanguage option is enabled by default so if your browser is not set to prefer the de locale, you might get redirected to English instead.

It should work with detectBrowserLanguage set to false but note that you might have to remove the i18n_redirected cookie because it seems like it will be used even if detectBrowserLanguage is false (which seems to be a bug).

EDIT: Actually i18n_redirected cookie being used even when detectBrowserLanguage is false doesn't look like a bug since one might want to set locale manually with setLocaleCookie even when not detecting locale.

@katerlouis
Copy link
Author

katerlouis commented Feb 9, 2021

Hm. But neither do I get redirected to /en when I open the page, nor is my browser language english. My browser language is German, so if at all "detect browser language" should reinforce localePath('/career') to be /karriere, shouldn't it?

plus: lets say you're right and i18n somewhat assumes my locale is en, why does localePath('career') return the desired /karriere.

In any way: the way I understand the docs localePath('/career') and localePath('career') should return the same value.
But can you confirm this behavior, when you open the sandbox or is it just happening to me?

@rchl
Copy link
Collaborator

rchl commented Feb 9, 2021

  1. That's not what you've asked about but I've noticed that your example using an object parameter to localePath uses the wrong route. Should be career-slug rather than career. You can check the available routes with Vue Dev Tools:
    Screenshot 2021-02-09 at 09 03 57

  2. As for your main issue, yes it's a bug/missing feature. See Can't switch to specific locale *by path* if route path was customized #641.

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 2, 2021
@rchl
Copy link
Collaborator

rchl commented Jun 3, 2021

According to the point "2" in my previous comment, this should be fixed.

@rchl rchl closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants