@akemona-org/strapi-plugin-i18n 3.7.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/LICENSE +22 -0
- package/README.md +19 -0
- package/admin/src/assets/images/logo.svg +1 -0
- package/admin/src/components/CMEditViewCopyLocale/index.js +183 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/cleanData.js +36 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/generateOptions.js +22 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/index.js +2 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/removePasswordAndRelationsFieldFromData.js +54 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/tests/cleanData.test.js +83 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/tests/data.js +219 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/tests/generateOptions.test.js +79 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/tests/removePasswordAndRelationsFieldFromData.test.js +40 -0
- package/admin/src/components/CMEditViewInjectedComponents/index.js +58 -0
- package/admin/src/components/CMEditViewLocalePicker/Option.js +66 -0
- package/admin/src/components/CMEditViewLocalePicker/Wrapper.js +8 -0
- package/admin/src/components/CMEditViewLocalePicker/index.js +160 -0
- package/admin/src/components/CMEditViewLocalePicker/utils/addStatusColorToLocale.js +24 -0
- package/admin/src/components/CMEditViewLocalePicker/utils/createLocalesOption.js +20 -0
- package/admin/src/components/CMEditViewLocalePicker/utils/index.js +2 -0
- package/admin/src/components/CheckboxConfirmation/Wrapper.js +12 -0
- package/admin/src/components/CheckboxConfirmation/index.js +70 -0
- package/admin/src/components/DeleteModalAdditionalInfos/index.js +25 -0
- package/admin/src/components/LocaleList/index.js +101 -0
- package/admin/src/components/LocaleListCell/LocaleListCell.js +90 -0
- package/admin/src/components/LocaleListCell/tests/LocaleListCell.test.js +128 -0
- package/admin/src/components/LocalePicker/index.js +126 -0
- package/admin/src/components/LocaleRow/index.js +77 -0
- package/admin/src/components/ModalCreate/AdvancedForm.js +45 -0
- package/admin/src/components/ModalCreate/BaseForm.js +103 -0
- package/admin/src/components/ModalCreate/index.js +136 -0
- package/admin/src/components/ModalDelete/index.js +49 -0
- package/admin/src/components/ModalEdit/AdvancedForm.js +51 -0
- package/admin/src/components/ModalEdit/BaseForm.js +91 -0
- package/admin/src/components/ModalEdit/index.js +122 -0
- package/admin/src/components/SettingsModal.js +66 -0
- package/admin/src/components/index.js +2 -0
- package/admin/src/containers/Initializer.js +31 -0
- package/admin/src/containers/SettingsPage/LocaleSettingsPage.js +69 -0
- package/admin/src/containers/SettingsPage/index.js +33 -0
- package/admin/src/containers/SettingsPage/tests/SettingsPage.test.js +744 -0
- package/admin/src/containers/SettingsPage/tests/__snapshots__/SettingsPage.test.js.snap +241 -0
- package/admin/src/hooks/constants.js +6 -0
- package/admin/src/hooks/reducers.js +63 -0
- package/admin/src/hooks/tests/reducers.test.js +203 -0
- package/admin/src/hooks/useAddLocale/index.js +60 -0
- package/admin/src/hooks/useContentTypePermissions/index.js +16 -0
- package/admin/src/hooks/useDefaultLocales/index.js +27 -0
- package/admin/src/hooks/useDeleteLocale/index.js +45 -0
- package/admin/src/hooks/useEditLocale/index.js +46 -0
- package/admin/src/hooks/useHasI18n/index.js +13 -0
- package/admin/src/hooks/useLocales/index.js +35 -0
- package/admin/src/index.js +169 -0
- package/admin/src/middlewares/addCommonFieldsToInitialDataMiddleware.js +83 -0
- package/admin/src/middlewares/addLocaleColumnToListViewMiddleware.js +32 -0
- package/admin/src/middlewares/addLocaleToCollectionTypesMiddleware.js +25 -0
- package/admin/src/middlewares/addLocaleToSingleTypesMiddleware.js +25 -0
- package/admin/src/middlewares/extendCMEditViewLayoutMiddleware.js +159 -0
- package/admin/src/middlewares/extendCTBAttributeInitialDataMiddleware.js +58 -0
- package/admin/src/middlewares/extendCTBInitialDataMiddleware.js +33 -0
- package/admin/src/middlewares/index.js +21 -0
- package/admin/src/middlewares/localePermissionMiddleware.js +39 -0
- package/admin/src/middlewares/tests/addCommonFieldsToInitialDataMiddleware.test.js +97 -0
- package/admin/src/middlewares/tests/addLocaleColumnToListViewMiddleware.test.js +68 -0
- package/admin/src/middlewares/tests/addLocaleToCollectionTypesMiddleware.test.js +200 -0
- package/admin/src/middlewares/tests/addLocaleToSingleTypesMiddleware.test.js +193 -0
- package/admin/src/middlewares/tests/extendCMEditViewLayoutMiddleware.test.js +556 -0
- package/admin/src/middlewares/tests/extendCTBAttrributeInitialDataMiddleware.test.js +124 -0
- package/admin/src/middlewares/tests/extendCTBInitialDataMiddleware.test.js +92 -0
- package/admin/src/middlewares/tests/localePermissionMiddleware.test.js +150 -0
- package/admin/src/middlewares/utils/addLocaleToLinksSearch.js +56 -0
- package/admin/src/middlewares/utils/tests/addLocaleToLinksSearch.test.js +137 -0
- package/admin/src/permissions.js +9 -0
- package/admin/src/pluginId.js +5 -0
- package/admin/src/schemas.js +7 -0
- package/admin/src/selectors/selectCollectionTypesRelatedPermissions.js +4 -0
- package/admin/src/selectors/selectI18nLocales.js +3 -0
- package/admin/src/translations/en.json +60 -0
- package/admin/src/translations/fr.json +9 -0
- package/admin/src/translations/index.js +11 -0
- package/admin/src/translations/zh-Hans.json +60 -0
- package/admin/src/utils/getDefaultLocale.js +60 -0
- package/admin/src/utils/getInitialLocale.js +14 -0
- package/admin/src/utils/getLocaleFromQuery.js +7 -0
- package/admin/src/utils/getTrad.js +5 -0
- package/admin/src/utils/index.js +2 -0
- package/admin/src/utils/localizedFields.js +23 -0
- package/admin/src/utils/mutateCTBContentTypeSchema.js +66 -0
- package/admin/src/utils/tests/getDefaultLocale.test.js +337 -0
- package/admin/src/utils/tests/getInitialLocale.test.js +106 -0
- package/admin/src/utils/tests/mutateCTBContentTypeSchema.test.js +205 -0
- package/config/functions/bootstrap.js +57 -0
- package/config/functions/migrations/__tests__/content-type.test.js +255 -0
- package/config/functions/migrations/__tests__/field.test.js +150 -0
- package/config/functions/migrations/content-type/disable/index.js +34 -0
- package/config/functions/migrations/content-type/disable/migrate-for-bookshelf.js +58 -0
- package/config/functions/migrations/content-type/disable/migrate-for-mongoose.js +39 -0
- package/config/functions/migrations/content-type/enable/index.js +40 -0
- package/config/functions/migrations/content-type/utils/index.js +27 -0
- package/config/functions/migrations/field/__tests__/utils.test.js +53 -0
- package/config/functions/migrations/field/index.js +37 -0
- package/config/functions/migrations/field/migrate-for-bookshelf.js +72 -0
- package/config/functions/migrations/field/migrate-for-mongoose.js +24 -0
- package/config/functions/migrations/field/migrate.js +55 -0
- package/config/functions/migrations/field/utils.js +58 -0
- package/config/functions/register.js +46 -0
- package/config/policies/validateLocaleCreation.js +68 -0
- package/config/routes.json +64 -0
- package/constants/__tests__/index.test.js +27 -0
- package/constants/index.js +36 -0
- package/constants/iso-locales.json +2002 -0
- package/controllers/__tests__/content-types.test.js +113 -0
- package/controllers/__tests__/iso-locales.test.js +26 -0
- package/controllers/__tests__/locales.test.js +308 -0
- package/controllers/content-types.js +64 -0
- package/controllers/iso-locales.js +11 -0
- package/controllers/locales.js +104 -0
- package/domain/locale.js +10 -0
- package/middlewares/i18n/defaults.json +5 -0
- package/middlewares/i18n/index.js +28 -0
- package/models/Locale.settings.json +31 -0
- package/oas.yml +195 -0
- package/package.json +31 -0
- package/services/__tests__/__snapshots__/iso-locales.test.js.snap +2006 -0
- package/services/__tests__/content-types.test.js +545 -0
- package/services/__tests__/core-api.test.js +106 -0
- package/services/__tests__/entity-service-decorator.test.js +280 -0
- package/services/__tests__/iso-locales.test.js +11 -0
- package/services/__tests__/locales.test.js +237 -0
- package/services/__tests__/localizations.test.js +187 -0
- package/services/__tests__/metrics.test.js +90 -0
- package/services/content-types.js +200 -0
- package/services/core-api.js +296 -0
- package/services/entity-service-decorator.js +155 -0
- package/services/iso-locales.js +9 -0
- package/services/locales.js +97 -0
- package/services/localizations.js +65 -0
- package/services/metrics.js +24 -0
- package/services/permissions/actions.js +124 -0
- package/services/permissions/engine.js +63 -0
- package/services/permissions/sections-builder.js +48 -0
- package/services/permissions.js +11 -0
- package/tests/content-manager/list-relation.test.e2e.js +122 -0
- package/tests/graphql.test.e2e.js +120 -0
- package/tests/locales.test.e2e.js +414 -0
- package/utils/index.js +20 -0
- package/validation/content-types.js +30 -0
- package/validation/locales.js +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015-present Strapi Solutions SAS
|
|
2
|
+
|
|
3
|
+
Portions of the Strapi software are licensed as follows:
|
|
4
|
+
|
|
5
|
+
* All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE".
|
|
6
|
+
|
|
7
|
+
* All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
|
|
8
|
+
|
|
9
|
+
MIT Expat License
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# strapi-plugin-i18n
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Deprecation Warning :warning:
|
|
6
|
+
|
|
7
|
+
Hello! We have some news to share,
|
|
8
|
+
|
|
9
|
+
We’ve decided it’ll soon be time to end the support for `strapi-plugin-i18n`.
|
|
10
|
+
|
|
11
|
+
After years of iterations, Strapi is going to V4 and we won’t maintain V3 packages when it’ll reach its end-of-support milestone (~end of Q3 2022).
|
|
12
|
+
|
|
13
|
+
If you’ve been using `strapi-plugin-i18n` and have migrated to V4 (or if you want to), you can find the equivalent and updated version of this package at this [URL](https://github.com/strapi/strapi/tree/master/packages/plugins/i18n) and with the following name on NPM: `@strapi/plugin-i18n`.
|
|
14
|
+
|
|
15
|
+
If you’ve contributed to the development of this package, thank you again for that! We hope to see you on the V4 soon.
|
|
16
|
+
|
|
17
|
+
The Akemona team
|
|
18
|
+
|
|
19
|
+
---
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg width="22" height="22" xmlns="http://www.w3.org/2000/svg"><text transform="translate(-23 -7)" fill="#333740" fill-rule="evenodd" font-family="AppleColorEmoji, Apple Color Emoji" font-size="20" letter-spacing=".769"><tspan x="23" y="26">🌍</tspan></text></svg>
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { Duplicate } from '@buffetjs/icons';
|
|
4
|
+
import { Label, Padded, Text } from '@buffetjs/core';
|
|
5
|
+
import Select from 'react-select';
|
|
6
|
+
import { useDispatch } from 'react-redux';
|
|
7
|
+
import { useTheme } from 'styled-components';
|
|
8
|
+
import { useIntl } from 'react-intl';
|
|
9
|
+
import {
|
|
10
|
+
BaselineAlignment,
|
|
11
|
+
DropdownIndicator,
|
|
12
|
+
ModalConfirm,
|
|
13
|
+
selectStyles,
|
|
14
|
+
useContentManagerEditViewDataManager,
|
|
15
|
+
request,
|
|
16
|
+
} from 'strapi-helper-plugin';
|
|
17
|
+
import { getTrad } from '../../utils';
|
|
18
|
+
import { cleanData, generateOptions } from './utils';
|
|
19
|
+
|
|
20
|
+
const CMEditViewCopyLocale = props => {
|
|
21
|
+
if (!props.localizations.length) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return <Content {...props} />;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const Content = ({ appLocales, currentLocale, localizations, readPermissions }) => {
|
|
29
|
+
const options = generateOptions(appLocales, currentLocale, localizations, readPermissions);
|
|
30
|
+
|
|
31
|
+
const { formatMessage } = useIntl();
|
|
32
|
+
const dispatch = useDispatch();
|
|
33
|
+
const { allLayoutData, slug } = useContentManagerEditViewDataManager();
|
|
34
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
35
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
36
|
+
const [value, setValue] = useState(options[0]);
|
|
37
|
+
const theme = useTheme();
|
|
38
|
+
|
|
39
|
+
const handleConfirmCopyLocale = async () => {
|
|
40
|
+
if (!value) {
|
|
41
|
+
handleToggle();
|
|
42
|
+
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const requestURL = `/content-manager/collection-types/${slug}/${value.value}`;
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
setIsLoading(true);
|
|
50
|
+
const response = await request(requestURL, { method: 'GET' });
|
|
51
|
+
const cleanedData = cleanData(response, allLayoutData, localizations);
|
|
52
|
+
|
|
53
|
+
dispatch({ type: 'ContentManager/CrudReducer/GET_DATA_SUCCEEDED', data: cleanedData });
|
|
54
|
+
|
|
55
|
+
strapi.notification.toggle({
|
|
56
|
+
type: 'success',
|
|
57
|
+
message: {
|
|
58
|
+
id: getTrad('CMEditViewCopyLocale.copy-success'),
|
|
59
|
+
defaultMessage: 'Locale copied!',
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error(err);
|
|
64
|
+
|
|
65
|
+
strapi.notification.toggle({
|
|
66
|
+
type: 'warning',
|
|
67
|
+
message: {
|
|
68
|
+
id: getTrad('CMEditViewCopyLocale.copy-failure'),
|
|
69
|
+
defaultMessage: 'Failed to copy locale',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
} finally {
|
|
73
|
+
setIsLoading(false);
|
|
74
|
+
handleToggle();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const handleChange = value => {
|
|
79
|
+
setValue(value);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const handleToggle = () => {
|
|
83
|
+
setIsOpen(prev => !prev);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const styles = selectStyles(theme);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<>
|
|
90
|
+
<BaselineAlignment top size="12px" />
|
|
91
|
+
<Text
|
|
92
|
+
color="mediumBlue"
|
|
93
|
+
fontWeight="semiBold"
|
|
94
|
+
style={{ cursor: 'pointer' }}
|
|
95
|
+
onClick={handleToggle}
|
|
96
|
+
>
|
|
97
|
+
<span style={{ marginRight: 10 }}>
|
|
98
|
+
<Duplicate fill="#007EFF" />
|
|
99
|
+
</span>
|
|
100
|
+
{formatMessage({
|
|
101
|
+
id: getTrad('CMEditViewCopyLocale.copy-text'),
|
|
102
|
+
defaultMessage: 'Fill in from another locale',
|
|
103
|
+
})}
|
|
104
|
+
</Text>
|
|
105
|
+
<ModalConfirm
|
|
106
|
+
showButtonLoader={isLoading}
|
|
107
|
+
confirmButtonLabel={{
|
|
108
|
+
id: getTrad('CMEditViewCopyLocale.submit-text'),
|
|
109
|
+
defaultMessage: 'Yes, fill in',
|
|
110
|
+
}}
|
|
111
|
+
content={{
|
|
112
|
+
id: getTrad('CMEditViewCopyLocale.ModalConfirm.content'),
|
|
113
|
+
defaultMessage:
|
|
114
|
+
'Your current content will be erased and filled by the content of the selected locale:',
|
|
115
|
+
}}
|
|
116
|
+
isOpen={isOpen}
|
|
117
|
+
onConfirm={handleConfirmCopyLocale}
|
|
118
|
+
title={{
|
|
119
|
+
id: getTrad('CMEditViewCopyLocale.ModalConfirm.title'),
|
|
120
|
+
defaultMessage: 'Select Locale',
|
|
121
|
+
}}
|
|
122
|
+
toggle={handleToggle}
|
|
123
|
+
type="success"
|
|
124
|
+
>
|
|
125
|
+
<Padded style={{ marginTop: -3 }} bottom size="sm">
|
|
126
|
+
<span id="select-locale" style={{ textAlign: 'left' }}>
|
|
127
|
+
<Label htmlFor="">
|
|
128
|
+
{formatMessage({
|
|
129
|
+
id: getTrad('Settings.locales.modal.locales.label'),
|
|
130
|
+
})}
|
|
131
|
+
</Label>
|
|
132
|
+
<BaselineAlignment top size="3px" />
|
|
133
|
+
<Select
|
|
134
|
+
aria-labelledby="select-locale"
|
|
135
|
+
components={{ DropdownIndicator }}
|
|
136
|
+
isSearchable={false}
|
|
137
|
+
defaultValue={options[0]}
|
|
138
|
+
onChange={handleChange}
|
|
139
|
+
options={options}
|
|
140
|
+
styles={{
|
|
141
|
+
...styles,
|
|
142
|
+
control: (base, state) => ({
|
|
143
|
+
...base,
|
|
144
|
+
...styles.control(base, state),
|
|
145
|
+
height: '34px',
|
|
146
|
+
}),
|
|
147
|
+
indicatorsContainer: (base, state) => ({
|
|
148
|
+
...base,
|
|
149
|
+
...styles.indicatorsContainer(base, state),
|
|
150
|
+
height: '32px',
|
|
151
|
+
}),
|
|
152
|
+
valueContainer: base => ({
|
|
153
|
+
...base,
|
|
154
|
+
padding: '2px 0px 4px 10px',
|
|
155
|
+
lineHeight: '18px',
|
|
156
|
+
}),
|
|
157
|
+
}}
|
|
158
|
+
value={value}
|
|
159
|
+
/>
|
|
160
|
+
</span>
|
|
161
|
+
</Padded>
|
|
162
|
+
</ModalConfirm>
|
|
163
|
+
</>
|
|
164
|
+
);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
CMEditViewCopyLocale.propTypes = {
|
|
168
|
+
localizations: PropTypes.array.isRequired,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
Content.propTypes = {
|
|
172
|
+
appLocales: PropTypes.arrayOf(
|
|
173
|
+
PropTypes.shape({
|
|
174
|
+
code: PropTypes.string.isRequired,
|
|
175
|
+
name: PropTypes.string,
|
|
176
|
+
})
|
|
177
|
+
).isRequired,
|
|
178
|
+
currentLocale: PropTypes.string.isRequired,
|
|
179
|
+
localizations: PropTypes.array.isRequired,
|
|
180
|
+
readPermissions: PropTypes.array.isRequired,
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export default CMEditViewCopyLocale;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
contentManagementUtilRemoveFieldsFromData,
|
|
3
|
+
formatComponentData,
|
|
4
|
+
} from 'strapi-helper-plugin';
|
|
5
|
+
import removePasswordAndRelationsFieldFromData from './removePasswordAndRelationsFieldFromData';
|
|
6
|
+
|
|
7
|
+
const cleanData = (data, { contentType, components }, initialLocalizations) => {
|
|
8
|
+
const dataWithoutPasswordsAndRelations = removePasswordAndRelationsFieldFromData(
|
|
9
|
+
data,
|
|
10
|
+
contentType,
|
|
11
|
+
components
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
dataWithoutPasswordsAndRelations.localizations = initialLocalizations;
|
|
15
|
+
|
|
16
|
+
const fieldsToRemove = [
|
|
17
|
+
'created_by',
|
|
18
|
+
'updated_by',
|
|
19
|
+
'published_at',
|
|
20
|
+
'id',
|
|
21
|
+
'_id',
|
|
22
|
+
'updated_at',
|
|
23
|
+
'created_at',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const cleanedClonedData = contentManagementUtilRemoveFieldsFromData(
|
|
27
|
+
dataWithoutPasswordsAndRelations,
|
|
28
|
+
contentType,
|
|
29
|
+
components,
|
|
30
|
+
fieldsToRemove
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return formatComponentData(cleanedClonedData, contentType, components);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default cleanData;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import get from 'lodash/get';
|
|
2
|
+
|
|
3
|
+
const generateOptions = (appLocales, currentLocale, localizations, permissions) => {
|
|
4
|
+
return appLocales
|
|
5
|
+
.filter(({ code }) => {
|
|
6
|
+
return (
|
|
7
|
+
code !== currentLocale &&
|
|
8
|
+
(localizations || []).findIndex(({ locale }) => locale === code) !== -1
|
|
9
|
+
);
|
|
10
|
+
})
|
|
11
|
+
.filter(({ code }) => {
|
|
12
|
+
return permissions.some(({ properties }) => get(properties, 'locales', []).includes(code));
|
|
13
|
+
})
|
|
14
|
+
.map(locale => {
|
|
15
|
+
return {
|
|
16
|
+
label: locale.name,
|
|
17
|
+
value: localizations.find(loc => locale.code === loc.locale).id,
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default generateOptions;
|
package/admin/src/components/CMEditViewCopyLocale/utils/removePasswordAndRelationsFieldFromData.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { get } from 'lodash';
|
|
2
|
+
import { getType, getOtherInfos } from 'strapi-helper-plugin';
|
|
3
|
+
|
|
4
|
+
const removePasswordAndRelationsFieldFromData = (data, contentTypeSchema, componentSchema) => {
|
|
5
|
+
const recursiveCleanData = (data, schema) => {
|
|
6
|
+
return Object.keys(data).reduce((acc, current) => {
|
|
7
|
+
const attrType = getType(schema, current);
|
|
8
|
+
const value = get(data, current);
|
|
9
|
+
const component = getOtherInfos(schema, [current, 'component']);
|
|
10
|
+
const isRepeatable = getOtherInfos(schema, [current, 'repeatable']);
|
|
11
|
+
|
|
12
|
+
if (attrType === 'dynamiczone') {
|
|
13
|
+
acc[current] = value.map(componentValue => {
|
|
14
|
+
const subCleanedData = recursiveCleanData(
|
|
15
|
+
componentValue,
|
|
16
|
+
componentSchema[componentValue.__component]
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return subCleanedData;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return acc;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (attrType === 'component') {
|
|
26
|
+
if (isRepeatable) {
|
|
27
|
+
/* eslint-disable indent */
|
|
28
|
+
acc[current] = value
|
|
29
|
+
? value.map(compoData => {
|
|
30
|
+
const subCleanedData = recursiveCleanData(compoData, componentSchema[component]);
|
|
31
|
+
|
|
32
|
+
return subCleanedData;
|
|
33
|
+
})
|
|
34
|
+
: value;
|
|
35
|
+
/* eslint-enable indent */
|
|
36
|
+
} else {
|
|
37
|
+
acc[current] = value ? recursiveCleanData(value, componentSchema[component]) : value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return acc;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (attrType !== 'password' && attrType !== 'relation') {
|
|
44
|
+
acc[current] = value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return acc;
|
|
48
|
+
}, {});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return recursiveCleanData(data, contentTypeSchema);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default removePasswordAndRelationsFieldFromData;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import cleanData from '../cleanData';
|
|
2
|
+
|
|
3
|
+
describe('i18n | Components | CMEditViewCopyLocale | utils', () => {
|
|
4
|
+
describe('cleanData', () => {
|
|
5
|
+
it('should change the localization key with the one passed in the argument', () => {
|
|
6
|
+
const data = {
|
|
7
|
+
address: 'test',
|
|
8
|
+
addresseses: [],
|
|
9
|
+
common: 'common',
|
|
10
|
+
created_at: '2021-03-17T15:34:05.866Z',
|
|
11
|
+
created_by: {
|
|
12
|
+
blocked: null,
|
|
13
|
+
email: 'cyril@strapi.io',
|
|
14
|
+
firstname: 'cyril',
|
|
15
|
+
id: 1,
|
|
16
|
+
isActive: true,
|
|
17
|
+
lastname: 'lopez',
|
|
18
|
+
preferedLanguage: null,
|
|
19
|
+
registrationToken: null,
|
|
20
|
+
resetPasswordToken: null,
|
|
21
|
+
username: null,
|
|
22
|
+
},
|
|
23
|
+
id: 14,
|
|
24
|
+
locale: 'fr-FR',
|
|
25
|
+
localizations: [
|
|
26
|
+
{
|
|
27
|
+
id: 13,
|
|
28
|
+
locale: 'en',
|
|
29
|
+
published_at: null,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
name: 'name',
|
|
33
|
+
published_at: null,
|
|
34
|
+
updated_at: '2021-03-17T15:34:18.958Z',
|
|
35
|
+
updated_by: {
|
|
36
|
+
blocked: null,
|
|
37
|
+
email: 'cyril@strapi.io',
|
|
38
|
+
firstname: 'cyril',
|
|
39
|
+
id: 1,
|
|
40
|
+
isActive: true,
|
|
41
|
+
lastname: 'lopez',
|
|
42
|
+
preferedLanguage: null,
|
|
43
|
+
registrationToken: null,
|
|
44
|
+
resetPasswordToken: null,
|
|
45
|
+
username: null,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const contentType = {
|
|
49
|
+
attributes: {
|
|
50
|
+
address: { type: 'relation' },
|
|
51
|
+
addresseses: { type: 'relation' },
|
|
52
|
+
common: { pluginOptions: { i18n: { localized: true } }, type: 'text' },
|
|
53
|
+
created_at: { type: 'timestamp' },
|
|
54
|
+
id: { type: 'integer' },
|
|
55
|
+
name: { pluginOptions: { i18n: { localized: true } } },
|
|
56
|
+
updated_at: { type: 'timestamp' },
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const initLocalizations = [
|
|
60
|
+
{
|
|
61
|
+
id: 14,
|
|
62
|
+
locale: 'fr-FR',
|
|
63
|
+
published_at: null,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const expected = {
|
|
68
|
+
common: 'common',
|
|
69
|
+
locale: 'fr-FR',
|
|
70
|
+
localizations: [
|
|
71
|
+
{
|
|
72
|
+
id: 14,
|
|
73
|
+
locale: 'fr-FR',
|
|
74
|
+
published_at: null,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
name: 'name',
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
expect(cleanData(data, { contentType, components: {} }, initLocalizations)).toEqual(expected);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
const testData = {
|
|
2
|
+
contentType: {
|
|
3
|
+
uid: 'application::test.test',
|
|
4
|
+
apiID: 'test',
|
|
5
|
+
attributes: {
|
|
6
|
+
created_at: { type: 'timestamp' },
|
|
7
|
+
dz: { type: 'dynamiczone', components: ['compos.test-compo', 'compos.sub-compo'] },
|
|
8
|
+
id: { type: 'integer' },
|
|
9
|
+
name: { type: 'string' },
|
|
10
|
+
notrepeatable: {
|
|
11
|
+
type: 'component',
|
|
12
|
+
repeatable: false,
|
|
13
|
+
component: 'compos.test-compo',
|
|
14
|
+
},
|
|
15
|
+
password: { type: 'password' },
|
|
16
|
+
repeatable: { type: 'component', repeatable: true, component: 'compos.test-compo' },
|
|
17
|
+
updated_at: { type: 'timestamp' },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
components: {
|
|
21
|
+
'compos.sub-compo': {
|
|
22
|
+
uid: 'compos.sub-compo',
|
|
23
|
+
category: 'compos',
|
|
24
|
+
attributes: {
|
|
25
|
+
id: { type: 'integer' },
|
|
26
|
+
name: { type: 'string' },
|
|
27
|
+
password: { type: 'password' },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
'compos.test-compo': {
|
|
31
|
+
uid: 'compos.test-compo',
|
|
32
|
+
category: 'compos',
|
|
33
|
+
attributes: {
|
|
34
|
+
id: { type: 'integer' },
|
|
35
|
+
name: { type: 'string' },
|
|
36
|
+
password: { type: 'password' },
|
|
37
|
+
subcomponotrepeatable: {
|
|
38
|
+
type: 'component',
|
|
39
|
+
repeatable: false,
|
|
40
|
+
component: 'compos.sub-compo',
|
|
41
|
+
},
|
|
42
|
+
subrepeatable: {
|
|
43
|
+
type: 'component',
|
|
44
|
+
repeatable: true,
|
|
45
|
+
component: 'compos.sub-compo',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
modifiedData: {
|
|
51
|
+
created_at: '2020-04-28T13:22:13.033Z',
|
|
52
|
+
dz: [
|
|
53
|
+
{ __component: 'compos.sub-compo', id: 7, name: 'name', password: 'password' },
|
|
54
|
+
{
|
|
55
|
+
id: 4,
|
|
56
|
+
name: 'name',
|
|
57
|
+
password: 'password',
|
|
58
|
+
subcomponotrepeatable: null,
|
|
59
|
+
subrepeatable: [],
|
|
60
|
+
__component: 'compos.test-compo',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 5,
|
|
64
|
+
name: 'name',
|
|
65
|
+
password: 'password',
|
|
66
|
+
subcomponotrepeatable: { id: 9, name: 'name', password: 'password' },
|
|
67
|
+
subrepeatable: [{ id: 8, name: 'name', password: 'password' }],
|
|
68
|
+
__component: 'compos.test-compo',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 6,
|
|
72
|
+
name: null,
|
|
73
|
+
password: null,
|
|
74
|
+
subcomponotrepeatable: null,
|
|
75
|
+
subrepeatable: [],
|
|
76
|
+
__component: 'compos.test-compo',
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
id: 1,
|
|
80
|
+
name: 'name',
|
|
81
|
+
notrepeatable: {
|
|
82
|
+
id: 1,
|
|
83
|
+
name: 'name',
|
|
84
|
+
password: 'password',
|
|
85
|
+
subcomponotrepeatable: { id: 4, name: 'name', password: 'password' },
|
|
86
|
+
subrepeatable: [
|
|
87
|
+
{ id: 1, name: 'name', password: 'password' },
|
|
88
|
+
{ id: 2, name: 'name', password: 'password' },
|
|
89
|
+
{ id: 3, name: 'name', password: 'password' },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
password: 'password',
|
|
93
|
+
repeatable: [
|
|
94
|
+
{
|
|
95
|
+
id: 2,
|
|
96
|
+
name: 'name',
|
|
97
|
+
password: 'password',
|
|
98
|
+
subrepeatable: [{ id: 5, name: 'name', password: 'password' }],
|
|
99
|
+
subcomponotrepeatable: { id: 6, name: 'name', password: 'password' },
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: 3,
|
|
103
|
+
name: 'name',
|
|
104
|
+
password: 'password',
|
|
105
|
+
subrepeatable: [],
|
|
106
|
+
subcomponotrepeatable: null,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
updated_at: '2020-04-28T13:22:13.033Z',
|
|
110
|
+
},
|
|
111
|
+
expectedModifiedData: {
|
|
112
|
+
created_at: '2020-04-28T13:22:13.033Z',
|
|
113
|
+
dz: [
|
|
114
|
+
{ __component: 'compos.sub-compo', id: 7, name: 'name' },
|
|
115
|
+
{
|
|
116
|
+
id: 4,
|
|
117
|
+
name: 'name',
|
|
118
|
+
subcomponotrepeatable: null,
|
|
119
|
+
subrepeatable: [],
|
|
120
|
+
__component: 'compos.test-compo',
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: 5,
|
|
124
|
+
name: 'name',
|
|
125
|
+
subcomponotrepeatable: { id: 9, name: 'name' },
|
|
126
|
+
subrepeatable: [{ id: 8, name: 'name' }],
|
|
127
|
+
__component: 'compos.test-compo',
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: 6,
|
|
131
|
+
name: null,
|
|
132
|
+
subcomponotrepeatable: null,
|
|
133
|
+
subrepeatable: [],
|
|
134
|
+
__component: 'compos.test-compo',
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
id: 1,
|
|
138
|
+
name: 'name',
|
|
139
|
+
notrepeatable: {
|
|
140
|
+
id: 1,
|
|
141
|
+
name: 'name',
|
|
142
|
+
subcomponotrepeatable: { id: 4, name: 'name' },
|
|
143
|
+
subrepeatable: [
|
|
144
|
+
{ id: 1, name: 'name' },
|
|
145
|
+
{ id: 2, name: 'name' },
|
|
146
|
+
{ id: 3, name: 'name' },
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
repeatable: [
|
|
150
|
+
{
|
|
151
|
+
id: 2,
|
|
152
|
+
name: 'name',
|
|
153
|
+
subrepeatable: [{ id: 5, name: 'name' }],
|
|
154
|
+
subcomponotrepeatable: { id: 6, name: 'name' },
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
id: 3,
|
|
158
|
+
name: 'name',
|
|
159
|
+
subrepeatable: [],
|
|
160
|
+
subcomponotrepeatable: null,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
updated_at: '2020-04-28T13:22:13.033Z',
|
|
164
|
+
},
|
|
165
|
+
expectedNoFieldsModifiedData: {
|
|
166
|
+
dz: [
|
|
167
|
+
{ __component: 'compos.sub-compo', name: 'name', password: 'password' },
|
|
168
|
+
{
|
|
169
|
+
name: 'name',
|
|
170
|
+
password: 'password',
|
|
171
|
+
subcomponotrepeatable: null,
|
|
172
|
+
subrepeatable: [],
|
|
173
|
+
__component: 'compos.test-compo',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: 'name',
|
|
177
|
+
password: 'password',
|
|
178
|
+
subcomponotrepeatable: { name: 'name', password: 'password' },
|
|
179
|
+
subrepeatable: [{ name: 'name', password: 'password' }],
|
|
180
|
+
__component: 'compos.test-compo',
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: null,
|
|
184
|
+
password: null,
|
|
185
|
+
subcomponotrepeatable: null,
|
|
186
|
+
subrepeatable: [],
|
|
187
|
+
__component: 'compos.test-compo',
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
name: 'name',
|
|
191
|
+
notrepeatable: {
|
|
192
|
+
name: 'name',
|
|
193
|
+
password: 'password',
|
|
194
|
+
subcomponotrepeatable: { name: 'name', password: 'password' },
|
|
195
|
+
subrepeatable: [
|
|
196
|
+
{ name: 'name', password: 'password' },
|
|
197
|
+
{ name: 'name', password: 'password' },
|
|
198
|
+
{ name: 'name', password: 'password' },
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
password: 'password',
|
|
202
|
+
repeatable: [
|
|
203
|
+
{
|
|
204
|
+
name: 'name',
|
|
205
|
+
password: 'password',
|
|
206
|
+
subrepeatable: [{ name: 'name', password: 'password' }],
|
|
207
|
+
subcomponotrepeatable: { name: 'name', password: 'password' },
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: 'name',
|
|
211
|
+
password: 'password',
|
|
212
|
+
subrepeatable: [],
|
|
213
|
+
subcomponotrepeatable: null,
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export default testData;
|