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

Add comment hint to explicitly register translation keys #241

Open
crtl opened this issue Oct 18, 2022 · 0 comments
Open

Add comment hint to explicitly register translation keys #241

crtl opened this issue Oct 18, 2022 · 0 comments

Comments

@crtl
Copy link

crtl commented Oct 18, 2022

Is your feature request related to a problem? Please describe.

I am using typescript and enums for some shared error messages so for example for forms I would use:

export enum FormError {
  PasswordInvalid = "passwordInvalid",
  UsernameInvalid = "usernameInvalid",
 // ...
}

And in my component I reference it using:

// ...
return (<FormFieldError>
  {t(FormError.PasswordInvalid)}
</FormFieldError />);

The plugin is not able to extract these keys and tells me to:

babel-plugin-i18next-extract: Extraction error in /src/auth/components/restore-password-form.tsx at line 70. Couldn't evaluate i18next key. You should either make the key evaluable or skip the
 line using a skip comment (/* i18next-extract-disable-line */ or /* i18next-extract-disable-next-line */).

Describe the solution you'd like
It would be nice to have a comment hint to manually register specific phrases unrelated to t calls.
For example the above enum could look something like:

export enum FormError {
  /* i18next-extract-register-key passwordInvalid */
  PasswordInvalid = "passwordInvalid",

  /* i18next-extract-register-key usernameInvalid */
  UsernameInvalid = "usernameInvalid",
}

Describe alternatives you've considered

Workaround is to copy the values and create a component containing only string literals to register the phrases explicitly but then the registration of phrases is separated from their definition which is cumbersome.

const RegisterPhrases: FC = (props) => {
  const {t} = useTranslation();
  
  // Register phrases
  t("passwordInvalid");
  t("usernameInvalid"); 

  return null;
};
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

No branches or pull requests

1 participant