translations.tsx 747 B

12345678910111213141516171819202122232425
  1. import * as Sentry from '@sentry/react';
  2. // zh-cn => zh_CN
  3. function convertToDjangoLocaleFormat(language: string) {
  4. const [left, right] = language.split('-');
  5. return left + (right ? '_' + right.toUpperCase() : '');
  6. }
  7. export function getTranslations(language: string) {
  8. language = convertToDjangoLocaleFormat(language);
  9. try {
  10. return require(`sentry-locale/${language}/LC_MESSAGES/django.po`);
  11. } catch (e) {
  12. Sentry.withScope(scope => {
  13. scope.setLevel(Sentry.Severity.Warning);
  14. scope.setFingerprint(['sentry-locale-not-found']);
  15. scope.setExtra('locale', language);
  16. Sentry.captureException(e);
  17. });
  18. // Default locale if not found
  19. return require('sentry-locale/en/LC_MESSAGES/django.po');
  20. }
  21. }