cubanducko / playwright-i18next-fixture

i18next fixture for playwright for multi-language text selectors
MIT License
7 stars 1 forks source link

Trouble using language detector #2

Open jeremieflrnt opened 1 year ago

jeremieflrnt commented 1 year ago

Hi, Great plugin there, thanks! I've used it for only one language at first, so I set lng directly and it's working fine!! But now I want to add a new language (add tests to the same website, but with a different locale / language), and I can't make it work.. Can you help? Did you have to manage this use case?

Thanks!

What is the current behavior? I remove the lng key in options and I added: plugins: [LanguageDetector] with import LanguageDetector from 'i18next-browser-languagedetector';

And now, it can't find the right language of the website (I use a locale on playwright project, and on the website, the html tag as a lang attribute)

Debug mode tells me:

i18next::languageUtils: rejecting language code not found in supportedLngs: dev
i18next::languageUtils: rejecting language code not found in supportedLngs: dev
i18next: languageChanged dev
i18next: initialized {
  debug: true,
  [...]

Steps to reproduce it and if possible a minimal demo of the problem. Paste the link to your JSFiddle or CodeSandbox example below:

What is the expected behavior? I expect to have the correct translations of the website under test A little about versions:

jeremieflrnt commented 1 year ago

The best I'm able to do is to use the getFixedT function to set the correct language according to the locale of the test:

export const testI18n = baseTest.extend(i18nFixture).extend<{ tFixed: TFunction }>({
  tFixed: async ({ i18n, locale }, use) => {
    if (locale === 'fr-FR') await use(i18n.getFixedT('fr'));
    else await use(i18n.getFixedT('es'));
  }
});

It's working, but it does not seems to be ideal...