cozy-ui 134.2.0 → 135.1.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.
- package/CHANGELOG.md +32 -0
- package/assets/icons/ui/send.svg +1 -0
- package/package.json +4 -2
- package/react/ActionsBar/index.jsx +1 -1
- package/react/ActionsBar/locales/withActionsLocales.jsx +2 -1
- package/react/ActionsMenu/Actions/locales/withActionsLocales.jsx +2 -2
- package/react/ActionsMenu/ActionsItems.jsx +1 -1
- package/react/ActionsMenu/ActionsMenuButton.jsx +1 -1
- package/react/CozyDialogs/DialogBackButton.jsx +1 -1
- package/react/CozyDialogs/DialogCloseButton.jsx +1 -1
- package/react/CozyDialogs/SpecificDialogs/AllowLocationDialog.jsx +1 -1
- package/react/CozyDialogs/SpecificDialogs/InstallFlagshipAppDialog.jsx +1 -1
- package/react/CozyDialogs/SpecificDialogs/ShortcutDialog.jsx +1 -1
- package/react/CozyDialogs/SpecificDialogs/withSpecificDialogsLocales.jsx +2 -1
- package/react/DateMonthPicker/Readme.md +1 -1
- package/react/DateMonthPicker/index.jsx +1 -1
- package/react/DateMonthPicker/index.spec.jsx +1 -1
- package/react/DatePicker/index.jsx +1 -1
- package/react/DatePicker/locales/withOwnLocales.jsx +2 -1
- package/react/EditBadge/EditMenu.jsx +1 -1
- package/react/Icon/Readme.md +3 -1
- package/react/Icons/Send.jsx +12 -0
- package/react/Labs/PasswordInput/index.jsx +1 -1
- package/react/Nav/index.jsx +1 -1
- package/react/Nav/locales/withNavLocales.jsx +2 -1
- package/react/PasswordField/index.jsx +1 -2
- package/react/SearchBar/index.jsx +1 -1
- package/react/SearchBar/locales/withOnlyLocales.jsx +2 -1
- package/react/SelectionBar/SelectionBarAction.jsx +1 -1
- package/react/SelectionBar/SelectionBarMore.jsx +1 -1
- package/react/SelectionBar/index.jsx +1 -1
- package/react/Spinner/Readme.md +1 -1
- package/react/Spinner/index.jsx +1 -1
- package/react/Table/Virtualized/Dnd/TableRow.jsx +1 -2
- package/react/Wizard/index.jsx +1 -1
- package/react/deprecated/ActionMenu/Actions/ActionsItems.jsx +1 -1
- package/react/deprecated/ActionMenu/Actions/call.js +1 -1
- package/react/deprecated/ActionMenu/Actions/emailTo.js +1 -1
- package/react/deprecated/ActionMenu/Actions/locales/withActionsLocales.jsx +2 -1
- package/react/deprecated/ActionMenu/Actions/smsTo.js +1 -1
- package/react/hooks/useConfirmExit/index.jsx +1 -1
- package/react/index.js +0 -1
- package/react/jestLib/I18n.js +1 -1
- package/react/providers/DemoProvider.jsx +1 -1
- package/transpiled/react/ActionsBar/index.js +1 -1
- package/transpiled/react/ActionsBar/locales/withActionsLocales.js +1 -1
- package/transpiled/react/ActionsMenu/Actions/locales/withActionsLocales.d.ts +1 -1
- package/transpiled/react/ActionsMenu/Actions/locales/withActionsLocales.js +1 -2
- package/transpiled/react/ActionsMenu/ActionsItems.js +1 -1
- package/transpiled/react/ActionsMenu/ActionsMenuButton.js +1 -1
- package/transpiled/react/CozyDialogs/DialogBackButton.js +1 -1
- package/transpiled/react/CozyDialogs/DialogCloseButton.js +1 -1
- package/transpiled/react/CozyDialogs/SpecificDialogs/AllowLocationDialog.js +1 -1
- package/transpiled/react/CozyDialogs/SpecificDialogs/InstallFlagshipAppDialog.js +1 -1
- package/transpiled/react/CozyDialogs/SpecificDialogs/ShortcutDialog.js +1 -1
- package/transpiled/react/CozyDialogs/SpecificDialogs/withSpecificDialogsLocales.js +1 -1
- package/transpiled/react/DateMonthPicker/index.js +1 -1
- package/transpiled/react/DatePicker/index.js +1 -1
- package/transpiled/react/DatePicker/locales/withOwnLocales.js +1 -1
- package/transpiled/react/EditBadge/EditMenu.js +1 -1
- package/transpiled/react/Icon/icons-sprite.d.ts +1 -1
- package/transpiled/react/Icon/icons-sprite.js +1 -1
- package/transpiled/react/Icons/Send.d.ts +2 -0
- package/transpiled/react/Icons/Send.js +13 -0
- package/transpiled/react/Labs/PasswordInput/index.js +1 -1
- package/transpiled/react/Nav/index.js +1 -1
- package/transpiled/react/Nav/locales/withNavLocales.js +1 -1
- package/transpiled/react/PasswordField/index.js +1 -2
- package/transpiled/react/SearchBar/index.js +1 -1
- package/transpiled/react/SearchBar/locales/withOnlyLocales.js +1 -1
- package/transpiled/react/SelectionBar/SelectionBarAction.js +1 -1
- package/transpiled/react/SelectionBar/SelectionBarMore.js +1 -1
- package/transpiled/react/SelectionBar/index.js +1 -1
- package/transpiled/react/Spinner/index.js +1 -1
- package/transpiled/react/Table/Virtualized/Dnd/TableRow.js +1 -1
- package/transpiled/react/Wizard/index.js +1 -1
- package/transpiled/react/deprecated/ActionMenu/Actions/ActionsItems.js +1 -1
- package/transpiled/react/deprecated/ActionMenu/Actions/call.js +1 -1
- package/transpiled/react/deprecated/ActionMenu/Actions/emailTo.js +1 -1
- package/transpiled/react/deprecated/ActionMenu/Actions/locales/withActionsLocales.js +1 -1
- package/transpiled/react/deprecated/ActionMenu/Actions/smsTo.js +1 -1
- package/transpiled/react/hooks/useConfirmExit/index.js +1 -1
- package/transpiled/react/index.d.ts +0 -1
- package/transpiled/react/index.js +0 -1
- package/transpiled/react/jestLib/I18n.d.ts +1 -1
- package/transpiled/react/jestLib/I18n.js +1 -1
- package/transpiled/react/providers/DemoProvider.js +1 -1
- package/react/I18n/index.js +0 -25
- package/react/I18n/withLocales.js +0 -14
- package/react/providers/I18n/createUseI18n.jsx +0 -32
- package/react/providers/I18n/format.jsx +0 -62
- package/react/providers/I18n/format.spec.jsx +0 -73
- package/react/providers/I18n/helpers.js +0 -33
- package/react/providers/I18n/index.jsx +0 -107
- package/react/providers/I18n/index.spec.jsx +0 -135
- package/react/providers/I18n/translate.jsx +0 -28
- package/react/providers/I18n/translation.jsx +0 -42
- package/react/providers/I18n/useExtendI18n.jsx +0 -37
- package/react/providers/I18n/withLocales.jsx +0 -47
- package/react/providers/I18n/withLocales.spec.jsx +0 -58
- package/react/providers/I18n/withOnlyLocales.jsx +0 -38
- package/transpiled/react/I18n/index.d.ts +0 -3
- package/transpiled/react/I18n/index.js +0 -16
- package/transpiled/react/I18n/withLocales.d.ts +0 -2
- package/transpiled/react/I18n/withLocales.js +0 -10
- package/transpiled/react/providers/I18n/createUseI18n.d.ts +0 -6
- package/transpiled/react/providers/I18n/createUseI18n.js +0 -39
- package/transpiled/react/providers/I18n/format.d.ts +0 -3
- package/transpiled/react/providers/I18n/format.js +0 -72
- package/transpiled/react/providers/I18n/format.spec.d.ts +0 -1
- package/transpiled/react/providers/I18n/helpers.d.ts +0 -5
- package/transpiled/react/providers/I18n/helpers.js +0 -35
- package/transpiled/react/providers/I18n/index.d.ts +0 -62
- package/transpiled/react/providers/I18n/index.js +0 -132
- package/transpiled/react/providers/I18n/index.spec.d.ts +0 -1
- package/transpiled/react/providers/I18n/translate.d.ts +0 -3
- package/transpiled/react/providers/I18n/translate.js +0 -21
- package/transpiled/react/providers/I18n/translation.d.ts +0 -3
- package/transpiled/react/providers/I18n/translation.js +0 -40
- package/transpiled/react/providers/I18n/useExtendI18n.d.ts +0 -7
- package/transpiled/react/providers/I18n/useExtendI18n.js +0 -42
- package/transpiled/react/providers/I18n/withLocales.d.ts +0 -8
- package/transpiled/react/providers/I18n/withLocales.js +0 -69
- package/transpiled/react/providers/I18n/withLocales.spec.d.ts +0 -1
- package/transpiled/react/providers/I18n/withOnlyLocales.d.ts +0 -8
- package/transpiled/react/providers/I18n/withOnlyLocales.js +0 -39
|
@@ -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,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,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,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;
|