@jetbrains/ring-ui 5.0.137 → 5.0.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/components/auth/auth__core.d.ts +1 -1
  2. package/components/auth/auth__core.js +21 -26
  3. package/components/auth-dialog/auth-dialog.js +3 -1
  4. package/components/date-picker/date-input.js +3 -1
  5. package/components/editable-heading/editable-heading.css +7 -3
  6. package/components/editable-heading/editable-heading.js +29 -8
  7. package/components/global/react-render-adapter.js +16 -31
  8. package/components/header/profile.d.ts +3 -1
  9. package/components/header/profile.js +15 -11
  10. package/components/i18n/README.md +46 -0
  11. package/components/i18n/i18n-context.d.ts +13 -0
  12. package/components/i18n/i18n-context.js +14 -0
  13. package/components/i18n/i18n.d.ts +59 -0
  14. package/components/i18n/i18n.js +26 -0
  15. package/components/i18n/messages.json +53 -0
  16. package/components/input/input.d.ts +1 -4
  17. package/components/input/input.js +16 -16
  18. package/components/message/message.d.ts +1 -5
  19. package/components/message/message.js +17 -16
  20. package/components/pager/pager.d.ts +3 -8
  21. package/components/pager/pager.js +11 -12
  22. package/components/query-assist/query-assist.d.ts +1 -5
  23. package/components/query-assist/query-assist.js +30 -29
  24. package/components/select/select.d.ts +2 -4
  25. package/components/select/select.js +14 -11
  26. package/components/select/select__filter.d.ts +0 -1
  27. package/components/select/select__filter.js +4 -2
  28. package/components/user-agreement/user-agreement.d.ts +1 -9
  29. package/components/user-agreement/user-agreement.js +31 -30
  30. package/components/user-card/card.d.ts +14 -13
  31. package/components/user-card/card.js +26 -27
  32. package/dist/_helpers/card.js +28 -33
  33. package/dist/_helpers/select__filter.js +17 -10
  34. package/dist/auth/auth.js +1 -0
  35. package/dist/auth/auth__core.d.ts +1 -1
  36. package/dist/auth/auth__core.js +18 -27
  37. package/dist/auth/landing.js +1 -0
  38. package/dist/auth-dialog/auth-dialog.js +1 -1
  39. package/dist/auth-ng/auth-ng.js +1 -0
  40. package/dist/date-picker/date-input.js +3 -1
  41. package/dist/date-picker/date-picker.js +2 -0
  42. package/dist/date-picker/date-popup.js +2 -0
  43. package/dist/editable-heading/editable-heading.js +32 -9
  44. package/dist/global/react-render-adapter.js +0 -2
  45. package/dist/header/header.js +2 -0
  46. package/dist/header/profile.d.ts +3 -1
  47. package/dist/header/profile.js +27 -15
  48. package/dist/header/smart-profile.js +2 -0
  49. package/dist/header/smart-services.js +1 -0
  50. package/dist/i18n/i18n-context.d.ts +13 -0
  51. package/dist/i18n/i18n-context.js +24 -0
  52. package/dist/i18n/i18n.d.ts +59 -0
  53. package/dist/i18n/i18n.js +136 -0
  54. package/dist/input/input.d.ts +1 -4
  55. package/dist/input/input.js +35 -30
  56. package/dist/link/link.js +1 -1
  57. package/dist/message/message.d.ts +1 -5
  58. package/dist/message/message.js +41 -35
  59. package/dist/pager/pager.d.ts +3 -8
  60. package/dist/pager/pager.js +25 -15
  61. package/dist/pager-ng/pager-ng.js +2 -0
  62. package/dist/permissions-ng/permissions-ng.js +1 -0
  63. package/dist/query-assist/query-assist.d.ts +1 -5
  64. package/dist/query-assist/query-assist.js +105 -93
  65. package/dist/query-assist-ng/query-assist-ng.js +2 -0
  66. package/dist/select/select.d.ts +2 -4
  67. package/dist/select/select.js +54 -47
  68. package/dist/select/select__filter.d.ts +0 -1
  69. package/dist/select/select__filter.js +2 -0
  70. package/dist/select/select__popup.js +2 -0
  71. package/dist/select-ng/select-ng.js +2 -0
  72. package/dist/select-ng/select-ng__lazy.js +2 -0
  73. package/dist/style.css +1 -1
  74. package/dist/table-legacy-ng/table-legacy-ng.js +2 -0
  75. package/dist/table-legacy-ng/table-legacy-ng__pager.js +2 -0
  76. package/dist/tags-input/tags-input.js +2 -0
  77. package/dist/tags-input-ng/tags-input-ng.js +2 -0
  78. package/dist/user-agreement/service.js +2 -0
  79. package/dist/user-agreement/user-agreement.d.ts +1 -9
  80. package/dist/user-agreement/user-agreement.js +41 -41
  81. package/dist/user-card/card.d.ts +14 -13
  82. package/dist/user-card/card.js +2 -0
  83. package/dist/user-card/smart-user-card-tooltip.js +2 -0
  84. package/dist/user-card/tooltip.js +2 -0
  85. package/dist/user-card/user-card.js +2 -0
  86. package/dist/user-card-ng/user-card-ng.js +2 -0
  87. package/package.json +32 -32
@@ -77,7 +77,7 @@ export interface AuthConfig extends TokenValidatorConfig {
77
77
  checkBackendIsUp: () => Promise<unknown>;
78
78
  onBackendDown: (params: BackendDownParams) => () => void;
79
79
  defaultExpiresIn: number;
80
- translations: AuthTranslations;
80
+ translations?: AuthTranslations | null | undefined;
81
81
  userParams?: RequestParams | undefined;
82
82
  waitForRedirectTimeout: number;
83
83
  }
@@ -2,6 +2,7 @@ import { fixUrl, getAbsoluteBaseURL } from '../global/url';
2
2
  import Listeners from '../global/listeners';
3
3
  import HTTP from '../http/http';
4
4
  import promiseWithTimeout from '../global/promise-with-timeout';
5
+ import { getTranslations, getTranslationsWithFallback, translate } from '../i18n/i18n';
5
6
  import AuthStorage from './storage';
6
7
  import AuthResponseParser from './response-parser';
7
8
  import AuthRequestBuilder from './request-builder';
@@ -42,19 +43,7 @@ const DEFAULT_CONFIG = {
42
43
  onBackendDown: () => () => { },
43
44
  defaultExpiresIn: DEFAULT_EXPIRES_TIMEOUT,
44
45
  waitForRedirectTimeout: DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT,
45
- translations: {
46
- login: 'Log in',
47
- loginTo: 'Log in to %serviceName%',
48
- cancel: 'Cancel',
49
- tryAgainLabel: 'Try again',
50
- postpone: 'Postpone',
51
- youHaveLoggedInAs: 'You have logged in as another user: %userName%',
52
- applyChange: 'Apply change',
53
- backendIsNotAvailable: 'Connection lost',
54
- checkAgain: 'try again',
55
- nothingHappensLink: 'Click here if nothing happens',
56
- errorMessage: 'There may be a problem with your network connection. Make sure that you are online and'
57
- }
46
+ translations: null
58
47
  };
59
48
  class Auth {
60
49
  static DEFAULT_CONFIG = DEFAULT_CONFIG;
@@ -131,7 +120,7 @@ class Auth {
131
120
  }
132
121
  this._backgroundFlow = new BackgroundFlow(this._requestBuilder, this._storage, backgroundRefreshTimeout);
133
122
  if (this.config.EmbeddedLoginFlow) {
134
- this._embeddedFlow = new this.config.EmbeddedLoginFlow(this._requestBuilder, this._storage, this.config.translations);
123
+ this._embeddedFlow = new this.config.EmbeddedLoginFlow(this._requestBuilder, this._storage, this.config.translations ?? getTranslationsWithFallback());
135
124
  }
136
125
  const API_BASE = this.config.serverUri + Auth.API_PATH;
137
126
  const fetchConfig = config.fetchCredentials
@@ -491,6 +480,7 @@ class Auth {
491
480
  _showAuthDialog({ nonInteractive, error, canCancel, onTryAgain } = {}) {
492
481
  const { embeddedLogin, onPostponeLogout, translations } = this.config;
493
482
  const cancelable = this.user?.guest || canCancel;
483
+ const actualTranslations = translations ?? getTranslations();
494
484
  this._createInitDeferred();
495
485
  const closeDialog = () => {
496
486
  /* eslint-disable @typescript-eslint/no-use-before-define */
@@ -530,11 +520,11 @@ class Auth {
530
520
  };
531
521
  const hide = this._authDialogService?.({
532
522
  ...this._service,
533
- loginCaption: translations.login,
534
- loginToCaption: translations.loginTo,
535
- confirmLabel: translations.login,
536
- tryAgainLabel: translations.tryAgainLabel,
537
- cancelLabel: cancelable ? translations.cancel : translations.postpone,
523
+ loginCaption: actualTranslations.login,
524
+ loginToCaption: actualTranslations.loginTo,
525
+ confirmLabel: actualTranslations.login,
526
+ tryAgainLabel: actualTranslations.tryAgainLabel,
527
+ cancelLabel: cancelable ? actualTranslations.cancel : actualTranslations.postpone,
538
528
  errorMessage: this._extractErrorMessage(error, true),
539
529
  onConfirm,
540
530
  onCancel,
@@ -558,12 +548,14 @@ class Auth {
558
548
  };
559
549
  const hide = this._authDialogService?.({
560
550
  ...this._service,
561
- title: translations.youHaveLoggedInAs.replace('%userName%', newUser.name ?? ''),
562
- loginCaption: translations.login,
563
- loginToCaption: translations.loginTo,
564
- confirmLabel: translations.applyChange,
565
- tryAgainLabel: translations.tryAgainLabel,
566
- cancelLabel: translations.postpone,
551
+ title: translations?.youHaveLoggedInAs ?? translate('youHaveLoggedInAs').
552
+ replace('%userName%', newUser.name ?? '').
553
+ replace('{{userName}}', newUser.name ?? ''),
554
+ loginCaption: translations?.login ?? translate('login'),
555
+ loginToCaption: translations?.loginTo ?? translate('loginTo'),
556
+ confirmLabel: translations?.applyChange ?? translate('applyChange'),
557
+ tryAgainLabel: translations?.tryAgainLabel ?? translate('tryAgainLabel'),
558
+ cancelLabel: translations?.postpone ?? translate('postpone'),
567
559
  onConfirm: () => {
568
560
  done();
569
561
  onApply();
@@ -623,7 +615,10 @@ class Auth {
623
615
  done();
624
616
  reject(new Error('Auth(@jetbrains/ring-ui): postponed by user'));
625
617
  };
626
- const hide = onBackendDown({ onCheckAgain, onPostpone, backendError, translations });
618
+ const hide = onBackendDown({
619
+ onCheckAgain, onPostpone, backendError,
620
+ translations: translations ?? getTranslationsWithFallback()
621
+ });
627
622
  window.addEventListener('online', onCheckAgain);
628
623
  function networkWatchdog() {
629
624
  if (navigator && navigator.onLine) {
@@ -68,7 +68,9 @@ class AuthDialog extends Component {
68
68
  const { show, className, errorMessage, serviceImage, serviceName, loginCaption, loginToCaption, confirmLabel, cancelLabel, tryAgainLabel, onConfirm, onCancel, onTryAgain } = this.props;
69
69
  const { retrying } = this.state;
70
70
  const defaultTitle = serviceName ? loginToCaption : loginCaption;
71
- const title = (this.props.title || defaultTitle).replace('%serviceName%', serviceName ?? '');
71
+ const title = (this.props.title || defaultTitle).
72
+ replace('%serviceName%', serviceName ?? '').
73
+ replace('{{serviceName}}', serviceName ?? '');
72
74
  return (<Dialog label={title} data-test="ring-auth-dialog" className={className} contentClassName={classNames(className, styles.dialog)} onEscPress={this.onEscPress} show={show} trapFocus>
73
75
  <Content>
74
76
  <div className={styles.content}>
@@ -89,7 +89,9 @@ class DateInput extends React.PureComponent {
89
89
  case 'time':
90
90
  return timePlaceholder || translations.addTime;
91
91
  default:
92
- return translations.selectName.replace('%name%', name);
92
+ return translations.selectName.
93
+ replace('%name%', name).
94
+ replace('{{name}}', name);
93
95
  }
94
96
  })();
95
97
  const classes = classNames(styles.filter, styles[`${name}Input`], divider && styles[`${name}InputWithDivider`], 'ring-js-shortcuts');
@@ -22,6 +22,7 @@
22
22
  padding: 0;
23
23
 
24
24
  cursor: pointer;
25
+ user-select: text;
25
26
 
26
27
  text-align: inherit;
27
28
 
@@ -33,7 +34,8 @@
33
34
 
34
35
  font-size: inherit;
35
36
 
36
- @nest .disabled & {
37
+ @nest .disabled &,
38
+ .selectionMode & {
37
39
  user-select: text;
38
40
 
39
41
  border-radius: 0;
@@ -43,7 +45,8 @@
43
45
  outline: 1px solid var(--ring-border-hover-color);
44
46
  }
45
47
 
46
- @nest .disabled &:focus {
48
+ @nest .disabled &:focus,
49
+ .selectionMode &:focus {
47
50
  outline: none;
48
51
  }
49
52
 
@@ -51,7 +54,8 @@
51
54
  background-color: var(--ring-hover-background-color);
52
55
  }
53
56
 
54
- @nest .disabled &:hover {
57
+ @nest .disabled &:hover,
58
+ .selectionMode &:hover {
55
59
  cursor: initial;
56
60
 
57
61
  background-color: initial;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import Heading, { Levels } from '../heading/heading';
4
4
  import Button from '../button/button';
@@ -17,6 +17,8 @@ export const EditableHeading = (props) => {
17
17
  }, ...restProps } = props;
18
18
  const [shortcutsScope] = React.useState(getUID('ring-editable-heading-'));
19
19
  const [isInFocus, setIsInFocus] = React.useState(false);
20
+ const [isMouseDown, setIsMouseDown] = React.useState(false);
21
+ const [isInSelectionMode, setIsInSelectionMode] = React.useState(false);
20
22
  const hasError = error !== undefined;
21
23
  const isSaveDisabled = !isSavingPossible || !children || children.trim() === '' || hasError || isSaving;
22
24
  const isCancelDisabled = isSaving;
@@ -36,16 +38,27 @@ export const EditableHeading = (props) => {
36
38
  [styles.isEditing]: isEditing,
37
39
  [styles.error]: hasError,
38
40
  [styles.disabled]: disabled,
39
- [styles.multiline]: multiline
41
+ [styles.multiline]: multiline,
42
+ [styles.selectionMode]: isInSelectionMode
40
43
  });
41
44
  const headingClasses = classNames(styles.heading, headingClassName, styles[`size${size}`]);
42
45
  const inputClasses = classNames('ring-js-shortcuts', styles.input, inputStyles[`size${size}`], styles[`level${level}`], inputClassName);
43
- const onHeadingClick = React.useCallback(() => {
44
- if (disabled) {
45
- return undefined;
46
+ const onHeadingMouseDown = React.useCallback(() => {
47
+ setIsMouseDown(true);
48
+ }, []);
49
+ const onMouseMove = React.useCallback(() => {
50
+ if (!isMouseDown) {
51
+ return;
46
52
  }
47
- return onEdit();
48
- }, [disabled, onEdit]);
53
+ setIsInSelectionMode(true);
54
+ }, [isMouseDown]);
55
+ const onMouseUp = React.useCallback(() => {
56
+ if (isMouseDown && !isInSelectionMode && !disabled) {
57
+ onEdit();
58
+ }
59
+ setIsMouseDown(false);
60
+ setIsInSelectionMode(false);
61
+ }, [isMouseDown, isInSelectionMode, disabled, onEdit]);
49
62
  const onInputFocus = React.useCallback((e) => {
50
63
  setIsInFocus(true);
51
64
  onFocus?.(e);
@@ -54,6 +67,14 @@ export const EditableHeading = (props) => {
54
67
  setIsInFocus(false);
55
68
  onBlur?.(e);
56
69
  }, [onBlur]);
70
+ useEffect(() => {
71
+ window.addEventListener('mousemove', onMouseMove);
72
+ window.addEventListener('mouseup', onMouseUp);
73
+ return () => {
74
+ window.removeEventListener('mousemove', onMouseMove);
75
+ window.removeEventListener('mouseup', onMouseUp);
76
+ };
77
+ });
57
78
  return (<>
58
79
  <div className={classes}>
59
80
  {!disabled && isEditing
@@ -62,7 +83,7 @@ export const EditableHeading = (props) => {
62
83
 
63
84
  <input className={inputClasses} value={children} autoFocus={autoFocus} data-test={dataTest} disabled={isSaving} {...restProps} onFocus={onInputFocus} onBlur={onInputBlur}/>
64
85
  </>)
65
- : (<button type="button" className={styles.headingWrapperButton} onClick={onHeadingClick}>
86
+ : (<button type="button" className={styles.headingWrapperButton} onMouseDown={onHeadingMouseDown}>
66
87
  <Heading className={headingClasses} level={level} data-test={dataTest}>{children}</Heading>
67
88
  </button>)}
68
89
 
@@ -1,36 +1,21 @@
1
- // Allows overriding ReactDOM.render when using React 18:
2
- // import * as client from 'react-dom/client'
3
- // import {setClient} from '@jetbrains/ring-ui/components/global/react-render-adapter'
4
- //
5
- // setClient(client)
6
- import {
7
- render as legacyRender,
8
- unmountComponentAtNode as legacyUnmountComponentAtNode,
9
- hydrate as legacyHydrate
10
- } from 'react-dom';
11
-
1
+ import { render as legacyRender, unmountComponentAtNode as legacyUnmountComponentAtNode, hydrate as legacyHydrate } from 'react-dom';
12
2
  /* eslint-disable import/no-mutable-exports */
13
3
  export let render = legacyRender;
14
4
  export let unmountComponentAtNode = legacyUnmountComponentAtNode;
15
5
  export let hydrate = legacyHydrate;
16
- /* eslint-enable */
17
-
18
- export function setClient({createRoot, hydrateRoot}) {
19
- const roots = new WeakMap();
20
-
21
- render = (element, container) => {
22
- let root = roots.get(container);
23
- if (root == null) {
24
- root = createRoot(container);
25
- roots.set(container, root);
26
- }
27
- root.render(element);
28
- };
29
-
30
- unmountComponentAtNode = container => roots.get(container)?.unmount();
31
-
32
- hydrate = (element, container) => {
33
- const root = hydrateRoot(container, element);
34
- roots.set(container, root);
35
- };
6
+ export function setClient({ createRoot, hydrateRoot }) {
7
+ const roots = new WeakMap();
8
+ render = (element, container) => {
9
+ let root = roots.get(container);
10
+ if (root == null) {
11
+ root = createRoot(container);
12
+ roots.set(container, root);
13
+ }
14
+ root.render(element);
15
+ };
16
+ unmountComponentAtNode = container => roots.get(container)?.unmount();
17
+ hydrate = (element, container) => {
18
+ const root = hydrateRoot(container, element);
19
+ roots.set(container, root);
20
+ };
36
21
  }
@@ -15,7 +15,7 @@ export interface ProfileTranslations {
15
15
  export interface ProfileProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onSelect'> {
16
16
  closeOnSelect: boolean;
17
17
  renderPopupItems: (items: ListDataItem[]) => readonly ListDataItem[];
18
- translations: ProfileTranslations;
18
+ translations?: ProfileTranslations | null | undefined;
19
19
  size: Size;
20
20
  renderGuest: (props: ProfileProps) => ReactNode;
21
21
  hasUpdates?: boolean | null | undefined;
@@ -67,6 +67,8 @@ export default class Profile extends PureComponent<ProfileProps> {
67
67
  renderGuest: PropTypes.Requireable<(...args: any[]) => any>;
68
68
  };
69
69
  static defaultProps: ProfileProps;
70
+ static contextType: React.Context<import("../i18n/i18n-context").I18nContextProps>;
71
+ context: React.ContextType<typeof Profile.contextType>;
70
72
  static Size: typeof Size;
71
73
  render(): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
72
74
  }
@@ -5,6 +5,7 @@ import Avatar, { Size } from '../avatar/avatar';
5
5
  import Button from '../button/button';
6
6
  import DropdownMenu from '../dropdown-menu/dropdown-menu';
7
7
  import PopupMenu from '../popup-menu/popup-menu';
8
+ import { I18nContext } from '../i18n/i18n-context';
8
9
  import { isTruthy } from '../global/typescript-utils';
9
10
  import styles from './header.css';
10
11
  const rgItemType = PopupMenu.ListProps.Type.LINK;
@@ -48,17 +49,20 @@ class Profile extends PureComponent {
48
49
  static defaultProps = {
49
50
  closeOnSelect: true,
50
51
  renderPopupItems: items => items,
51
- translations: {},
52
52
  size: Size.Size32,
53
- renderGuest: ({ loading, onLogin, className, translations }) => (<div className={classNames(styles.profileEmpty, className)}>
54
- <Button primary data-test="ring-header-login-button" disabled={loading} loader={loading} onClick={onLogin}>
55
- {translations.login || 'Log in...'}
56
- </Button>
57
- </div>)
53
+ renderGuest: ({ loading, onLogin, className, translations }) => (<I18nContext.Consumer>
54
+ {({ translate }) => (<div className={classNames(styles.profileEmpty, className)}>
55
+ <Button primary data-test="ring-header-login-button" disabled={loading} loader={loading} onClick={onLogin}>
56
+ {translations?.login ?? translate('login')}
57
+ </Button>
58
+ </div>)}
59
+ </I18nContext.Consumer>)
58
60
  };
61
+ static contextType = I18nContext;
59
62
  static Size = Size;
60
63
  render() {
61
64
  const { className, closeOnSelect, hasUpdates, onLogout, user, profileUrl, LinkComponent, onSwitchUser, renderPopupItems, onRevertPostponement, showApplyChangedUser, showLogIn, showLogOut, showSwitchUser, renderGuest, translations, size, round, loading, onLogin, ...props } = this.props;
65
+ const { translate } = this.context;
62
66
  if (!user) {
63
67
  return (<div {...props} className={classNames(styles.profileEmpty, className)}>
64
68
  <Avatar size={size} round={round}/>
@@ -76,32 +80,32 @@ class Profile extends PureComponent {
76
80
  const items = [
77
81
  showApplyChangedUser && {
78
82
  rgItemType,
79
- label: translations.applyChangedUser || 'Apply changed user',
83
+ label: translations?.applyChangedUser ?? translate('applyChangedUser'),
80
84
  className: styles.profileMenuItem,
81
85
  onClick: onRevertPostponement
82
86
  },
83
87
  showLogIn && {
84
88
  rgItemType,
85
- label: translations.login || 'Log in',
89
+ label: translations?.login ?? translate('login'),
86
90
  className: styles.profileMenuItem,
87
91
  onClick: onRevertPostponement
88
92
  },
89
93
  {
90
94
  rgItemType: PopupMenu.ListProps.Type.LINK,
91
- label: translations.profile || 'Profile',
95
+ label: translations?.profile ?? translate('profile'),
92
96
  target: '_self',
93
97
  href: profileUrl,
94
98
  LinkComponent
95
99
  },
96
100
  showSwitchUser && {
97
101
  rgItemType,
98
- label: translations.switchUser || 'Switch user',
102
+ label: translations?.switchUser ?? translate('switchUser'),
99
103
  className: styles.profileMenuItem,
100
104
  onClick: onSwitchUser
101
105
  },
102
106
  showLogOut && {
103
107
  rgItemType,
104
- label: translations.logout || 'Log out',
108
+ label: translations?.logout ?? translate('logout'),
105
109
  onClick: onLogout
106
110
  }
107
111
  ].filter(isTruthy);
@@ -0,0 +1,46 @@
1
+ This is localisation layer, that allows to translate the app into different languages.
2
+
3
+ All messages should be stored in a messages.json, using that format https://www.i18next.com/misc/json-format#i18next-json-v4
4
+
5
+ ### How to use
6
+
7
+ 1. Using your project i18n tooling, construct an object with localised messages, like:
8
+ ```
9
+ // You can use https://ttag.js.org/ for example:
10
+ const localised = {
11
+ login: t`Log in`,
12
+ ...
13
+ }
14
+ ```
15
+
16
+ 2. Pass it to i18n singleton, using `setTranslations`. That would provide localisation to non-react components, like Auth.
17
+
18
+ ```
19
+ // Your messages object should have localised strings at that moment
20
+ const localised = {
21
+ login: 'Inloggen',
22
+ ...
23
+ }
24
+
25
+ setTranslations(localised);
26
+ ```
27
+
28
+ 3. Add I18nContextHolder into your root React tree. If you replace "localised" object with another one, consumers would be updated automatically.
29
+
30
+ ```
31
+ <I18nContextHolder messages={localised}>
32
+ <App />
33
+ </I18nContextHolder>
34
+ ```
35
+
36
+
37
+
38
+ ### Utilities
39
+
40
+ There is some ways to automate strings extraction from messages.json. You can do:
41
+
42
+ ```
43
+ npx i18next-conv -s messages.json -t messages.pot -l en --ctxSeparator "|" --compatibilityJSON v4
44
+ ```
45
+
46
+ And get a .pot file, which you can merge with your other sources
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { type Messages } from './i18n';
3
+ export interface I18nContextProps {
4
+ translate(key: keyof Messages): string;
5
+ messages: Messages;
6
+ }
7
+ export declare const I18nContext: React.Context<I18nContextProps>;
8
+ interface I18nContextHolderProps {
9
+ messages: Messages;
10
+ children?: React.ReactNode;
11
+ }
12
+ export declare const I18nContextHolder: React.FC<I18nContextHolderProps>;
13
+ export {};
@@ -0,0 +1,14 @@
1
+ import React, { useEffect } from 'react';
2
+ import { getTranslations, setTranslations, translate } from './i18n';
3
+ export const I18nContext = React.createContext({
4
+ messages: getTranslations(),
5
+ translate
6
+ });
7
+ export const I18nContextHolder = ({ children, messages }) => {
8
+ useEffect(() => {
9
+ setTranslations(messages);
10
+ }, [messages]);
11
+ return (<I18nContext.Provider value={{ messages, translate }}>
12
+ {children}
13
+ </I18nContext.Provider>);
14
+ };
@@ -0,0 +1,59 @@
1
+ import defaultMessages from './messages.json';
2
+ export type MessagesStrict = typeof defaultMessages;
3
+ export type Messages = Partial<MessagesStrict>;
4
+ export declare function setTranslations(newMessages: Messages): void;
5
+ export declare function getTranslations(): Partial<{
6
+ login: string;
7
+ logout: string;
8
+ loginTo: string;
9
+ ok: string;
10
+ cancel: string;
11
+ tryAgainLabel: string;
12
+ postpone: string;
13
+ youHaveLoggedInAs: string;
14
+ applyChange: string;
15
+ backendIsNotAvailable: string;
16
+ checkAgain: string;
17
+ nothingHappensLink: string;
18
+ errorMessage: string;
19
+ applyChangedUser: string;
20
+ profile: string;
21
+ switchUser: string;
22
+ addFirstDate: string;
23
+ addSecondDate: string;
24
+ addTime: string;
25
+ selectName: string;
26
+ setDate: string;
27
+ setDateTime: string;
28
+ setPeriod: string;
29
+ clear: string;
30
+ gotIt: string;
31
+ dismiss: string;
32
+ perPage: string;
33
+ firstPage: string;
34
+ lastPage: string;
35
+ nextPage: string;
36
+ previousPage: string;
37
+ searchTitle: string;
38
+ clearTitle: string;
39
+ userAgreement: string;
40
+ accept: string;
41
+ decline: string;
42
+ close: string;
43
+ scrollToAccept: string;
44
+ remindLater: string;
45
+ filterItems: string;
46
+ selectOption: string;
47
+ progress: string;
48
+ loading: string;
49
+ noOptionsFound: string;
50
+ banned: string;
51
+ online: string;
52
+ offline: string;
53
+ copyToClipboard: string;
54
+ copiedToClipboard: string;
55
+ copingToClipboardError: string;
56
+ unverified: string;
57
+ }>;
58
+ export declare function getTranslationsWithFallback(): MessagesStrict;
59
+ export declare function translate(key: keyof MessagesStrict): string;
@@ -0,0 +1,26 @@
1
+ import defaultMessages from './messages.json';
2
+ let messages = defaultMessages;
3
+ const warned = new Set();
4
+ function warnMissedKeyOnce(key) {
5
+ if (warned.has(key)) {
6
+ return;
7
+ }
8
+ warned.add(key);
9
+ // eslint-disable-next-line no-console
10
+ console.warn(`Missing localisation for key "${key}"`);
11
+ }
12
+ export function setTranslations(newMessages) {
13
+ messages = newMessages;
14
+ }
15
+ export function getTranslations() {
16
+ return messages;
17
+ }
18
+ export function getTranslationsWithFallback() {
19
+ return { ...defaultMessages, ...messages };
20
+ }
21
+ export function translate(key) {
22
+ if (!(key in messages)) {
23
+ warnMissedKeyOnce(key);
24
+ }
25
+ return messages[key] ?? defaultMessages[key];
26
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "login": "Log in",
3
+ "logout": "Log out",
4
+ "loginTo": "Log in to {{serviceName}}",
5
+ "ok": "OK",
6
+ "cancel": "Cancel",
7
+ "tryAgainLabel": "Try again",
8
+ "postpone": "Postpone",
9
+ "youHaveLoggedInAs": "You have logged in as another user: {{userName}}",
10
+ "applyChange": "Apply change",
11
+ "backendIsNotAvailable": "Connection lost",
12
+ "checkAgain": "try again",
13
+ "nothingHappensLink": "Click here if nothing happens",
14
+ "errorMessage": "There may be a problem with your network connection. Make sure that you are online and",
15
+ "applyChangedUser": "Apply changed user",
16
+ "profile": "Profile",
17
+ "switchUser": "Switch user",
18
+ "addFirstDate": "Add first date",
19
+ "addSecondDate": "Add second date",
20
+ "addTime": "Add time",
21
+ "selectName": "Select {{name}}",
22
+ "setDate": "Set a date",
23
+ "setDateTime": "Set date and time",
24
+ "setPeriod": "Set a period",
25
+ "clear": "Clear input",
26
+ "gotIt": "Got it",
27
+ "dismiss": "Dismiss",
28
+ "perPage": "per page",
29
+ "firstPage": "First page",
30
+ "lastPage": "Last page",
31
+ "nextPage": "Next page",
32
+ "previousPage": "Previous",
33
+ "searchTitle": "Search",
34
+ "clearTitle": "Clear search input",
35
+ "userAgreement": "User Agreement",
36
+ "accept": "Accept",
37
+ "decline": "Decline",
38
+ "close": "Close",
39
+ "scrollToAccept": "View the entire agreement to continue",
40
+ "remindLater": "Remind me later",
41
+ "filterItems": "Filter items",
42
+ "selectOption": "Select an option",
43
+ "progress": "Progress",
44
+ "loading": "Loading...",
45
+ "noOptionsFound": "No options found",
46
+ "banned": "banned",
47
+ "online": "online",
48
+ "offline": "offline",
49
+ "copyToClipboard": "Copy email to clipboard",
50
+ "copiedToClipboard": "Email was copied to clipboard",
51
+ "copingToClipboardError": "Failed to copy to clipboard",
52
+ "unverified": "Unverified"
53
+ }
@@ -28,7 +28,7 @@ export interface InputBaseProps {
28
28
  icon?: string | ComponentType | null | undefined;
29
29
  height?: ControlsHeight | undefined;
30
30
  afterInput?: ReactNode;
31
- translations: InputTranslations;
31
+ translations?: InputTranslations | null | undefined;
32
32
  }
33
33
  type Override<D, S> = Omit<D, keyof S> & S;
34
34
  export type InputSpecificProps = Override<InputHTMLAttributes<HTMLInputElement>, InputBaseProps> & {
@@ -46,9 +46,6 @@ export declare class Input extends PureComponent<InputProps> {
46
46
  onChange: typeof noop;
47
47
  inputRef: typeof noop;
48
48
  enableShortcuts: string[];
49
- translations: {
50
- clear: string;
51
- };
52
49
  };
53
50
  state: {
54
51
  empty: boolean;