cozy-ui 134.2.0 → 135.0.0

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 (119) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/package.json +4 -2
  3. package/react/ActionsBar/index.jsx +1 -1
  4. package/react/ActionsBar/locales/withActionsLocales.jsx +2 -1
  5. package/react/ActionsMenu/Actions/locales/withActionsLocales.jsx +2 -2
  6. package/react/ActionsMenu/ActionsItems.jsx +1 -1
  7. package/react/ActionsMenu/ActionsMenuButton.jsx +1 -1
  8. package/react/CozyDialogs/DialogBackButton.jsx +1 -1
  9. package/react/CozyDialogs/DialogCloseButton.jsx +1 -1
  10. package/react/CozyDialogs/SpecificDialogs/AllowLocationDialog.jsx +1 -1
  11. package/react/CozyDialogs/SpecificDialogs/InstallFlagshipAppDialog.jsx +1 -1
  12. package/react/CozyDialogs/SpecificDialogs/ShortcutDialog.jsx +1 -1
  13. package/react/CozyDialogs/SpecificDialogs/withSpecificDialogsLocales.jsx +2 -1
  14. package/react/DateMonthPicker/Readme.md +1 -1
  15. package/react/DateMonthPicker/index.jsx +1 -1
  16. package/react/DateMonthPicker/index.spec.jsx +1 -1
  17. package/react/DatePicker/index.jsx +1 -1
  18. package/react/DatePicker/locales/withOwnLocales.jsx +2 -1
  19. package/react/EditBadge/EditMenu.jsx +1 -1
  20. package/react/Labs/PasswordInput/index.jsx +1 -1
  21. package/react/Nav/index.jsx +1 -1
  22. package/react/Nav/locales/withNavLocales.jsx +2 -1
  23. package/react/PasswordField/index.jsx +1 -2
  24. package/react/SearchBar/index.jsx +1 -1
  25. package/react/SearchBar/locales/withOnlyLocales.jsx +2 -1
  26. package/react/SelectionBar/SelectionBarAction.jsx +1 -1
  27. package/react/SelectionBar/SelectionBarMore.jsx +1 -1
  28. package/react/SelectionBar/index.jsx +1 -1
  29. package/react/Spinner/Readme.md +1 -1
  30. package/react/Spinner/index.jsx +1 -1
  31. package/react/Table/Virtualized/Dnd/TableRow.jsx +1 -2
  32. package/react/Wizard/index.jsx +1 -1
  33. package/react/deprecated/ActionMenu/Actions/ActionsItems.jsx +1 -1
  34. package/react/deprecated/ActionMenu/Actions/call.js +1 -1
  35. package/react/deprecated/ActionMenu/Actions/emailTo.js +1 -1
  36. package/react/deprecated/ActionMenu/Actions/locales/withActionsLocales.jsx +2 -1
  37. package/react/deprecated/ActionMenu/Actions/smsTo.js +1 -1
  38. package/react/hooks/useConfirmExit/index.jsx +1 -1
  39. package/react/index.js +0 -1
  40. package/react/jestLib/I18n.js +1 -1
  41. package/react/providers/DemoProvider.jsx +1 -1
  42. package/transpiled/react/ActionsBar/index.js +1 -1
  43. package/transpiled/react/ActionsBar/locales/withActionsLocales.js +1 -1
  44. package/transpiled/react/ActionsMenu/Actions/locales/withActionsLocales.d.ts +1 -1
  45. package/transpiled/react/ActionsMenu/Actions/locales/withActionsLocales.js +1 -2
  46. package/transpiled/react/ActionsMenu/ActionsItems.js +1 -1
  47. package/transpiled/react/ActionsMenu/ActionsMenuButton.js +1 -1
  48. package/transpiled/react/CozyDialogs/DialogBackButton.js +1 -1
  49. package/transpiled/react/CozyDialogs/DialogCloseButton.js +1 -1
  50. package/transpiled/react/CozyDialogs/SpecificDialogs/AllowLocationDialog.js +1 -1
  51. package/transpiled/react/CozyDialogs/SpecificDialogs/InstallFlagshipAppDialog.js +1 -1
  52. package/transpiled/react/CozyDialogs/SpecificDialogs/ShortcutDialog.js +1 -1
  53. package/transpiled/react/CozyDialogs/SpecificDialogs/withSpecificDialogsLocales.js +1 -1
  54. package/transpiled/react/DateMonthPicker/index.js +1 -1
  55. package/transpiled/react/DatePicker/index.js +1 -1
  56. package/transpiled/react/DatePicker/locales/withOwnLocales.js +1 -1
  57. package/transpiled/react/EditBadge/EditMenu.js +1 -1
  58. package/transpiled/react/Labs/PasswordInput/index.js +1 -1
  59. package/transpiled/react/Nav/index.js +1 -1
  60. package/transpiled/react/Nav/locales/withNavLocales.js +1 -1
  61. package/transpiled/react/PasswordField/index.js +1 -2
  62. package/transpiled/react/SearchBar/index.js +1 -1
  63. package/transpiled/react/SearchBar/locales/withOnlyLocales.js +1 -1
  64. package/transpiled/react/SelectionBar/SelectionBarAction.js +1 -1
  65. package/transpiled/react/SelectionBar/SelectionBarMore.js +1 -1
  66. package/transpiled/react/SelectionBar/index.js +1 -1
  67. package/transpiled/react/Spinner/index.js +1 -1
  68. package/transpiled/react/Table/Virtualized/Dnd/TableRow.js +1 -1
  69. package/transpiled/react/Wizard/index.js +1 -1
  70. package/transpiled/react/deprecated/ActionMenu/Actions/ActionsItems.js +1 -1
  71. package/transpiled/react/deprecated/ActionMenu/Actions/call.js +1 -1
  72. package/transpiled/react/deprecated/ActionMenu/Actions/emailTo.js +1 -1
  73. package/transpiled/react/deprecated/ActionMenu/Actions/locales/withActionsLocales.js +1 -1
  74. package/transpiled/react/deprecated/ActionMenu/Actions/smsTo.js +1 -1
  75. package/transpiled/react/hooks/useConfirmExit/index.js +1 -1
  76. package/transpiled/react/index.d.ts +0 -1
  77. package/transpiled/react/index.js +0 -1
  78. package/transpiled/react/jestLib/I18n.d.ts +1 -1
  79. package/transpiled/react/jestLib/I18n.js +1 -1
  80. package/transpiled/react/providers/DemoProvider.js +1 -1
  81. package/react/I18n/index.js +0 -25
  82. package/react/I18n/withLocales.js +0 -14
  83. package/react/providers/I18n/createUseI18n.jsx +0 -32
  84. package/react/providers/I18n/format.jsx +0 -62
  85. package/react/providers/I18n/format.spec.jsx +0 -73
  86. package/react/providers/I18n/helpers.js +0 -33
  87. package/react/providers/I18n/index.jsx +0 -107
  88. package/react/providers/I18n/index.spec.jsx +0 -135
  89. package/react/providers/I18n/translate.jsx +0 -28
  90. package/react/providers/I18n/translation.jsx +0 -42
  91. package/react/providers/I18n/useExtendI18n.jsx +0 -37
  92. package/react/providers/I18n/withLocales.jsx +0 -47
  93. package/react/providers/I18n/withLocales.spec.jsx +0 -58
  94. package/react/providers/I18n/withOnlyLocales.jsx +0 -38
  95. package/transpiled/react/I18n/index.d.ts +0 -3
  96. package/transpiled/react/I18n/index.js +0 -16
  97. package/transpiled/react/I18n/withLocales.d.ts +0 -2
  98. package/transpiled/react/I18n/withLocales.js +0 -10
  99. package/transpiled/react/providers/I18n/createUseI18n.d.ts +0 -6
  100. package/transpiled/react/providers/I18n/createUseI18n.js +0 -39
  101. package/transpiled/react/providers/I18n/format.d.ts +0 -3
  102. package/transpiled/react/providers/I18n/format.js +0 -72
  103. package/transpiled/react/providers/I18n/format.spec.d.ts +0 -1
  104. package/transpiled/react/providers/I18n/helpers.d.ts +0 -5
  105. package/transpiled/react/providers/I18n/helpers.js +0 -35
  106. package/transpiled/react/providers/I18n/index.d.ts +0 -62
  107. package/transpiled/react/providers/I18n/index.js +0 -132
  108. package/transpiled/react/providers/I18n/index.spec.d.ts +0 -1
  109. package/transpiled/react/providers/I18n/translate.d.ts +0 -3
  110. package/transpiled/react/providers/I18n/translate.js +0 -21
  111. package/transpiled/react/providers/I18n/translation.d.ts +0 -3
  112. package/transpiled/react/providers/I18n/translation.js +0 -40
  113. package/transpiled/react/providers/I18n/useExtendI18n.d.ts +0 -7
  114. package/transpiled/react/providers/I18n/useExtendI18n.js +0 -42
  115. package/transpiled/react/providers/I18n/withLocales.d.ts +0 -8
  116. package/transpiled/react/providers/I18n/withLocales.js +0 -69
  117. package/transpiled/react/providers/I18n/withLocales.spec.d.ts +0 -1
  118. package/transpiled/react/providers/I18n/withOnlyLocales.d.ts +0 -8
  119. package/transpiled/react/providers/I18n/withOnlyLocales.js +0 -39
@@ -1,3 +0,0 @@
1
- export function provideDateFnsLocale(userLang: any, defaultLang?: string): Locale | undefined;
2
- export function initFormat(userLang: any, defaultLang?: string): (date: any, formatStr: any, opts?: {}) => string | undefined;
3
- export function formatLocallyDistanceToNow(date: any): string;
@@ -1,72 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
- import format from 'date-fns/format';
8
- import formatDistanceToNow from 'date-fns/formatDistanceToNow';
9
- import { enGB as enLocale, fr as frLocale, es as esLocale } from 'date-fns/locale';
10
- import { DEFAULT_LANG } from "cozy-ui/transpiled/react/providers/I18n";
11
- var currentLocale;
12
-
13
- var getDateFnsLocale = function getDateFnsLocale(lang) {
14
- switch (lang) {
15
- case 'en':
16
- return enLocale;
17
-
18
- case 'fr':
19
- return frLocale;
20
-
21
- case 'es':
22
- return esLocale;
23
-
24
- default:
25
- throw new Error('Locale not found');
26
- }
27
- };
28
-
29
- var getWarningMessage = function getWarningMessage(lang) {
30
- return "The \"".concat(lang, "\" locale isn't supported by date-fns or has not been included in the build. Check if you have configured a ContextReplacementPlugin that is too restrictive.");
31
- };
32
-
33
- export var provideDateFnsLocale = function provideDateFnsLocale(userLang) {
34
- var defaultLang = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LANG;
35
-
36
- try {
37
- var userLocale = getDateFnsLocale(userLang);
38
- currentLocale = userLocale;
39
- return userLocale;
40
- } catch (e) {
41
- console.warn(getWarningMessage(userLang));
42
- }
43
-
44
- try {
45
- var defaultLocale = getDateFnsLocale(defaultLang);
46
- currentLocale = defaultLocale;
47
- return defaultLocale;
48
- } catch (err) {
49
- console.warn(getWarningMessage(defaultLang));
50
- }
51
- };
52
- export var initFormat = function initFormat(userLang) {
53
- var defaultLang = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LANG;
54
- return function (date, formatStr) {
55
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
56
- var locale = provideDateFnsLocale(userLang, defaultLang);
57
- var ensureDate = date && typeof date === 'string' ? new Date(date) : date;
58
-
59
- try {
60
- return format(ensureDate, formatStr, _objectSpread({
61
- locale: locale
62
- }, opts));
63
- } catch (error) {
64
- console.error('Error in initFormat', error);
65
- }
66
- };
67
- };
68
- export var formatLocallyDistanceToNow = function formatLocallyDistanceToNow(date) {
69
- return formatDistanceToNow(date, {
70
- locale: currentLocale
71
- });
72
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- export function getI18n(lang: any, dictRequire: any, context: any, defaultLang?: string): {
2
- t: any;
3
- f: (date: any, formatStr: any, opts?: {}) => string | undefined;
4
- lang: any;
5
- };
@@ -1,35 +0,0 @@
1
- import { DEFAULT_LANG } from "cozy-ui/transpiled/react/providers/I18n";
2
- import { initFormat } from "cozy-ui/transpiled/react/providers/I18n/format";
3
- import { initTranslation } from "cozy-ui/transpiled/react/providers/I18n/translation";
4
-
5
- var getAppOrUiLang = function getAppOrUiLang(defaultLang) {
6
- var appContainer = document.querySelector('[role=application]');
7
- var cozyUiContainer = {
8
- dataset: {
9
- cozy: JSON.stringify({
10
- locale: localStorage.getItem('lang') || defaultLang
11
- })
12
- }
13
- };
14
- var container = appContainer || cozyUiContainer;
15
-
16
- var _JSON$parse = JSON.parse(container.dataset.cozy),
17
- locale = _JSON$parse.locale;
18
-
19
- return /^\{\{\..*\}\}$/.test(locale) ? defaultLang : locale;
20
- };
21
-
22
- export var getI18n = function getI18n(lang, dictRequire, context) {
23
- var defaultLang = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_LANG;
24
-
25
- var _lang = lang || getAppOrUiLang(defaultLang);
26
-
27
- var polyglot = initTranslation(_lang, dictRequire, context, defaultLang);
28
- var f = initFormat(_lang);
29
- var t = polyglot.t.bind(polyglot);
30
- return {
31
- t: t,
32
- f: f,
33
- lang: _lang
34
- };
35
- };
@@ -1,62 +0,0 @@
1
- export const DEFAULT_LANG: "en";
2
- export const I18nContext: React.Context<any>;
3
- export function useI18n(): useI18nReturnTypes;
4
- export class I18n extends React.Component<any, any, any> {
5
- constructor(props: any);
6
- init(props: any): void;
7
- translator: any;
8
- format: ((date: any, formatStr: any, opts?: {}) => string | undefined) | undefined;
9
- t: any;
10
- contextValue: {
11
- t: any;
12
- f: ((date: any, formatStr: any, opts?: {}) => string | undefined) | undefined;
13
- polyglot: any;
14
- lang: any;
15
- } | undefined;
16
- getContextValue(props: any): {
17
- t: any;
18
- f: ((date: any, formatStr: any, opts?: {}) => string | undefined) | undefined;
19
- polyglot: any;
20
- lang: any;
21
- };
22
- getChildContext(): {
23
- t: any;
24
- f: ((date: any, formatStr: any, opts?: {}) => string | undefined) | undefined;
25
- polyglot: any;
26
- lang: any;
27
- } | undefined;
28
- UNSAFE_componentWillReceiveProps: (nextProps: any) => void;
29
- render(): JSX.Element;
30
- }
31
- export namespace I18n {
32
- namespace propTypes {
33
- const lang: PropTypes.Validator<string>;
34
- const polyglot: PropTypes.Requireable<object>;
35
- const dictRequire: PropTypes.Requireable<(...args: any[]) => any>;
36
- const context: PropTypes.Requireable<string>;
37
- const defaultLang: PropTypes.Requireable<string>;
38
- }
39
- namespace defaultProps {
40
- export { DEFAULT_LANG as defaultLang };
41
- }
42
- namespace childContextTypes {
43
- export const t: PropTypes.Requireable<(...args: any[]) => any>;
44
- export const f: PropTypes.Requireable<(...args: any[]) => any>;
45
- const polyglot_1: PropTypes.Requireable<object>;
46
- export { polyglot_1 as polyglot };
47
- const lang_1: PropTypes.Requireable<string>;
48
- export { lang_1 as lang };
49
- }
50
- }
51
- export { default as translate } from "./translate";
52
- export { default as createUseI18n } from "./createUseI18n";
53
- export { default as useExtendI18n } from "./useExtendI18n";
54
- export default I18n;
55
- export type useI18nReturnTypes = {
56
- t: (key: string) => string;
57
- f: (date: string, format: string) => string;
58
- lang: string;
59
- };
60
- import React from "react";
61
- import PropTypes from "prop-types";
62
- export { initTranslation, extend } from "./translation";
@@ -1,132 +0,0 @@
1
- /**
2
- * Provides an I18n helper using a Higher Order Component.
3
- */
4
- 'use strict';
5
-
6
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
7
- import _createClass from "@babel/runtime/helpers/createClass";
8
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
9
- import _inherits from "@babel/runtime/helpers/inherits";
10
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
11
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
12
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
13
-
14
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
15
-
16
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
17
-
18
- import PropTypes from 'prop-types';
19
- import React, { Component, useContext } from 'react';
20
- import { initFormat } from "cozy-ui/transpiled/react/providers/I18n/format";
21
- import { initTranslation } from "cozy-ui/transpiled/react/providers/I18n/translation";
22
- export var DEFAULT_LANG = 'en';
23
- export var I18nContext = /*#__PURE__*/React.createContext();
24
- /**
25
- * @typedef useI18nReturnTypes
26
- * @property {(key: string) => string} t
27
- * @property {(date: string, format: string) => string} f
28
- * @property {string} lang
29
- */
30
-
31
- /**
32
- * @returns {useI18nReturnTypes}
33
- */
34
-
35
- export var useI18n = function useI18n() {
36
- var context = useContext(I18nContext);
37
-
38
- if (!context) {
39
- throw new Error('`I18nContext` is missing. `useI18n()` must be used within a `<I18n>`');
40
- }
41
-
42
- return context;
43
- }; // Provider root component
44
-
45
- export var I18n = /*#__PURE__*/function (_Component) {
46
- _inherits(I18n, _Component);
47
-
48
- var _super = _createSuper(I18n);
49
-
50
- function I18n(props) {
51
- var _this;
52
-
53
- _classCallCheck(this, I18n);
54
-
55
- _this = _super.call(this, props);
56
-
57
- _defineProperty(_assertThisInitialized(_this), "UNSAFE_componentWillReceiveProps", function (nextProps) {
58
- if (nextProps.lang !== _this.props.lang) {
59
- _this.init(nextProps);
60
- }
61
- });
62
-
63
- _this.init(_this.props);
64
-
65
- return _this;
66
- }
67
-
68
- _createClass(I18n, [{
69
- key: "init",
70
- value: function init(props) {
71
- var polyglot = props.polyglot,
72
- lang = props.lang,
73
- dictRequire = props.dictRequire,
74
- context = props.context,
75
- defaultLang = props.defaultLang;
76
- this.translator = polyglot || initTranslation(lang, dictRequire, context, defaultLang);
77
- this.format = initFormat(lang, defaultLang);
78
- this.t = this.translator.t.bind(this.translator);
79
- this.contextValue = this.getContextValue(props);
80
- }
81
- }, {
82
- key: "getContextValue",
83
- value: function getContextValue(props) {
84
- return {
85
- t: this.t,
86
- f: this.format,
87
- polyglot: (props || this.props).polyglot || this.translator,
88
- lang: (props || this.props).lang
89
- };
90
- }
91
- }, {
92
- key: "getChildContext",
93
- value: function getChildContext() {
94
- return this.contextValue;
95
- }
96
- }, {
97
- key: "render",
98
- value: function render() {
99
- return /*#__PURE__*/React.createElement(I18nContext.Provider, {
100
- value: this.contextValue
101
- }, this.props.children);
102
- }
103
- }]);
104
-
105
- return I18n;
106
- }(Component);
107
- I18n.propTypes = {
108
- lang: PropTypes.string.isRequired,
109
- // current language.
110
- polyglot: PropTypes.object,
111
- // A polyglot instance.
112
- dictRequire: PropTypes.func,
113
- // A callback to load locales.
114
- context: PropTypes.string,
115
- // current context.
116
- defaultLang: PropTypes.string // default language. By default is 'en'
117
-
118
- };
119
- I18n.defaultProps = {
120
- defaultLang: DEFAULT_LANG
121
- };
122
- I18n.childContextTypes = {
123
- t: PropTypes.func,
124
- f: PropTypes.func,
125
- polyglot: PropTypes.object,
126
- lang: PropTypes.string
127
- };
128
- export { initTranslation, extend } from './translation';
129
- export { default as translate } from './translate';
130
- export { default as createUseI18n } from './createUseI18n';
131
- export { default as useExtendI18n } from './useExtendI18n';
132
- export default I18n;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export default translate;
2
- declare function translate(): (WrappedComponent: any) => React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import React from "react";
@@ -1,21 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import React, { useContext, forwardRef } from 'react';
3
- import { I18nContext } from "cozy-ui/transpiled/react/providers/I18n"; // higher order decorator for components that need `t` and/or `f`
4
-
5
- var translate = function translate() {
6
- return function (WrappedComponent) {
7
- var Wrapper = /*#__PURE__*/forwardRef(function (props, ref) {
8
- var i18nContext = useContext(I18nContext);
9
- return /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, {
10
- ref: ref,
11
- t: i18nContext && i18nContext.t,
12
- f: i18nContext && i18nContext.f,
13
- lang: i18nContext && i18nContext.lang
14
- }));
15
- });
16
- Wrapper.displayName = "withI18n(".concat(WrappedComponent.displayName || WrappedComponent.name, ")");
17
- return Wrapper;
18
- };
19
- };
20
-
21
- export default translate;
@@ -1,3 +0,0 @@
1
- export let _polyglot: any;
2
- export function initTranslation(lang: any, dictRequire: any, context: any, defaultLang?: string): any;
3
- export function extend(dict: any, polyglot: any): any;
@@ -1,40 +0,0 @@
1
- import Polyglot from 'node-polyglot';
2
- import { DEFAULT_LANG } from "cozy-ui/transpiled/react/providers/I18n";
3
- export var _polyglot;
4
- export var initTranslation = function initTranslation(lang, dictRequire, context) {
5
- var defaultLang = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_LANG;
6
- _polyglot = new Polyglot({
7
- phrases: dictRequire(defaultLang),
8
- locale: defaultLang
9
- }); // Load global locales
10
-
11
- if (lang && lang !== defaultLang) {
12
- try {
13
- var dict = dictRequire(lang);
14
-
15
- _polyglot.extend(dict);
16
-
17
- _polyglot.locale(lang);
18
- } catch (e) {
19
- console.warn("The dict phrases for \"".concat(lang, "\" can't be loaded"));
20
- }
21
- } // Load context locales
22
-
23
-
24
- if (context) {
25
- try {
26
- var _dict = dictRequire(lang, context);
27
-
28
- _polyglot.extend(_dict);
29
- } catch (e) {
30
- console.warn("The context ".concat(context, " cannot be loaded for lang ").concat(lang));
31
- }
32
- }
33
-
34
- return _polyglot;
35
- };
36
- export var extend = function extend(dict, polyglot) {
37
- var _ref;
38
-
39
- return (_ref = polyglot || _polyglot) === null || _ref === void 0 ? void 0 : _ref.extend(dict);
40
- };
@@ -1,7 +0,0 @@
1
- export default useExtendI18n;
2
- /**
3
- * Hook to merge app locales with cozy-ui locales
4
- * @param {object} locales - Locales sorted by lang `{ fr: {...}, en: {...} }`
5
- * @returns {void}
6
- */
7
- declare function useExtendI18n(locales: object): void;
@@ -1,42 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import Polyglot from 'node-polyglot';
3
- import { useState } from 'react';
4
- import { useI18n } from "cozy-ui/transpiled/react/providers/I18n";
5
- import { extend } from "cozy-ui/transpiled/react/providers/I18n/translation";
6
- /**
7
- * Hook to merge app locales with cozy-ui locales
8
- * @param {object} locales - Locales sorted by lang `{ fr: {...}, en: {...} }`
9
- * @returns {void}
10
- */
11
-
12
- var useExtendI18n = function useExtendI18n(locales) {
13
- var _useI18n = useI18n(),
14
- lang = _useI18n.lang,
15
- polyglot = _useI18n.polyglot; // Use to determine if we need to merge locales again, and to avoid useless calls
16
-
17
-
18
- var _useState = useState(''),
19
- _useState2 = _slicedToArray(_useState, 2),
20
- useExtendI18nLang = _useState2[0],
21
- setUseExtendI18nLang = _useState2[1];
22
-
23
- if (!locales || !lang || !polyglot) return; // To simplify code we use Polyglot.extend to merge
24
- // locales from object and from polyglot.phrases
25
- // rather than native JS or lodash. this is why we have two extend.
26
-
27
- if (useExtendI18nLang !== lang) {
28
- var _polyglot = new Polyglot({
29
- phrases: locales[lang],
30
- locale: lang
31
- }); // merge locales from app and cozy-ui, without replacing existing one in app
32
-
33
-
34
- extend(polyglot.phrases, _polyglot); // use merged locales in app
35
-
36
- extend(_polyglot.phrases, polyglot); // set the switch to avoid useless merge
37
-
38
- setUseExtendI18nLang(lang);
39
- }
40
- };
41
-
42
- export default useExtendI18n;
@@ -1,8 +0,0 @@
1
- export default withLocales;
2
- /**
3
- *
4
- * @param {Function|Object} localesOrRequire - Either a function returning the locale for a lang,
5
- * or an object containing all the locales
6
- * @return {Component}
7
- */
8
- declare function withLocales(localesOrRequire: Function | Object): Component;
@@ -1,69 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
-
8
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
-
10
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
-
12
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
-
14
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
-
16
- import omit from 'lodash/omit';
17
- import React from 'react';
18
- import { I18n, translate } from "cozy-ui/transpiled/react/providers/I18n";
19
- /**
20
- *
21
- * @param {Function|Object} localesOrRequire - Either a function returning the locale for a lang,
22
- * or an object containing all the locales
23
- * @return {Component}
24
- */
25
-
26
- var withLocales = function withLocales(localesOrRequire) {
27
- return function (Component) {
28
- // The inner components needs to receive t
29
- var Translated = translate()(Component);
30
- var requireLocale = typeof localesOrRequire === 'function' ? localesOrRequire : function (localeCode) {
31
- return localesOrRequire[localeCode];
32
- };
33
-
34
- var Wrapped = /*#__PURE__*/function (_React$Component) {
35
- _inherits(Wrapped, _React$Component);
36
-
37
- var _super = _createSuper(Wrapped);
38
-
39
- function Wrapped() {
40
- _classCallCheck(this, Wrapped);
41
-
42
- return _super.apply(this, arguments);
43
- }
44
-
45
- _createClass(Wrapped, [{
46
- key: "render",
47
- value: function render() {
48
- var lang = this.props.lang; // Do not pass translate props downwards
49
- // since the component is already augmented with translate()
50
-
51
- var wrappedProps = omit(this.props, Object.keys(I18n.childContextTypes));
52
- return /*#__PURE__*/React.createElement(I18n, {
53
- dictRequire: requireLocale,
54
- lang: lang
55
- }, /*#__PURE__*/React.createElement(Translated, wrappedProps));
56
- }
57
- }]);
58
-
59
- return Wrapped;
60
- }(React.Component);
61
-
62
- Wrapped.propTypes = _objectSpread(_objectSpread({}, Component.propTypes || {}), I18n.childContextTypes);
63
- Wrapped.displayName = "withLocales(".concat(Component.displayName || Component.name, ")"); // The outer component needs to receive lang
64
-
65
- return translate()(Wrapped);
66
- };
67
- };
68
-
69
- export default withLocales;
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- export default withOnlyLocales;
2
- /**
3
- *
4
- * @param {Function|Object} localesOrRequire - Either a function returning the locale,
5
- * or an object containing all the locales
6
- * @return {Component}
7
- */
8
- declare function withOnlyLocales(localesOrRequire: Function | Object): Component;
@@ -1,39 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _extends from "@babel/runtime/helpers/extends";
3
-
4
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
-
6
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
-
8
- import React, { forwardRef } from 'react';
9
- import { I18n, useI18n } from "cozy-ui/transpiled/react/providers/I18n";
10
- /**
11
- *
12
- * @param {Function|Object} localesOrRequire - Either a function returning the locale,
13
- * or an object containing all the locales
14
- * @return {Component}
15
- */
16
-
17
- var withOnlyLocales = function withOnlyLocales(localesOrRequire) {
18
- return function (Component) {
19
- var requireLocale = typeof localesOrRequire === 'function' ? localesOrRequire : function (localeCode) {
20
- return localesOrRequire[localeCode];
21
- };
22
- var Wrapped = /*#__PURE__*/forwardRef(function (props, ref) {
23
- var _useI18n = useI18n(),
24
- lang = _useI18n.lang;
25
-
26
- return /*#__PURE__*/React.createElement(I18n, {
27
- dictRequire: requireLocale,
28
- lang: lang
29
- }, /*#__PURE__*/React.createElement(Component, _extends({}, props, {
30
- ref: ref
31
- })));
32
- });
33
- Wrapped.propTypes = _objectSpread({}, Component.propTypes || {});
34
- Wrapped.displayName = "withOnlyLocales(".concat(Component.displayName || Component.name, ")");
35
- return Wrapped;
36
- };
37
- };
38
-
39
- export default withOnlyLocales;