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

After updating to next-7, 'missing message ID' for i18n.load() #1600

Closed
ptmkenny opened this issue Apr 18, 2023 · 2 comments · Fixed by #1602
Closed

After updating to next-7, 'missing message ID' for i18n.load() #1600

ptmkenny opened this issue Apr 18, 2023 · 2 comments · Fixed by #1602

Comments

@ptmkenny
Copy link

Describe the bug
After updating to next-7 from next-5 (skipped next-6 due to #1596), I'm getting the following warning:

> lingui extract --clean --overwrite

⠧ Missing message ID, skipping.
> 30 | i18n.load({
     |           ^
  31 |   ja: messagesJa,
  32 | });
  33 |

To Reproduce

The error occurs in my LocalizationProvider component.

import React, { useEffect } from 'react';
import { i18n } from '@lingui/core';
import { I18nProvider } from '@lingui/react';
import { messages as messagesJa } from '../locales/ja/messages';
import AppLanguage from '../i18n/AppLanguage';
import useLocalStoragePreferences from '../queries/auth/useLocalStoragePreferences';

/**
 * https://lingui.js.org/guides/dynamic-loading-catalogs.html
 * We do a dynamic import of just the catalog that we need
 * @param locale any locale string
 */
async function dynamicActivate(locale: string) {
  if (locale === AppLanguage.Japanese) {
    const { messages } = await import('../locales/ja/messages.js');
    i18n.load(locale, messages);
    i18n.activate(locale);
  } else if (locale === AppLanguage.English) {
    const { messages } = await import('../locales/en/messages.js');
    i18n.load(locale, messages);
    i18n.activate(locale);
  }
}

interface MyProps {
  children: JSX.Element;
}

// Loading the English language separately saves about ~30 kb in the app bundle size.
i18n.load({
  ja: messagesJa,
});

const LocalizationProvider: React.FC<MyProps> = ({ children }: MyProps) => {
  // Running in a useEffect() hook results in this message for the first render:
  // I18nProvider did not render.
  // A call to i18n.activate still needs to happen or
  // forceRenderOnLocaleChange must be set to false.
  // useEffect(() => {
  //   i18n.activate('ja');
  // }, []);

  // Default to Japanese.
  i18n.activate(AppLanguage.Japanese);
  const localStoragePreferences = useLocalStoragePreferences();

  useEffect(() => {
    const { language } = localStoragePreferences;
    if (language && i18n.locale !== language) {
      dynamicActivate(language);
    }
  }, [localStoragePreferences]);

  return <I18nProvider i18n={i18n}>{children}</I18nProvider>;
};

export default LocalizationProvider;

Expected behavior

I expect no warning to be emitted.

@timofei-iatsenko
Copy link
Collaborator

Interesting, i will take a look.

@timofei-iatsenko
Copy link
Collaborator

Fixed: #1602

Thanks for reporting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants