META-INF.resources.js.export_translation.ExportTranslationModal.es.js Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
import ClayButton from '@clayui/button';
import ClayForm, {ClayCheckbox, ClayInput, ClaySelect} from '@clayui/form';
import ClayModal from '@clayui/modal';
import PropTypes from 'prop-types';
import React, {useContext, useState} from 'react';
import ExportTranslationContext from './ExportTranslationContext.es';
const noop = () => {};
const ExportTranslationModal = ({
articleIds,
availableExportFileFormats,
availableSourceLocales,
availableTargetLocales,
defaultSourceLanguageId,
exportTranslationURL,
observer,
onModalClose = noop,
}) => {
const {namespace} = useContext(ExportTranslationContext);
const [exportMimeType, setExportMimeType] = useState(
availableExportFileFormats[0].mimeType
);
const [sourceLanguageId, setSourceLanguageId] = useState(
defaultSourceLanguageId
);
const [selectedTargetLanguageIds, setSelectedTargetLanguageIds] = useState(
[]
);
const exportTranslationPortletURL = Liferay.Util.PortletURL.createPortletURL(
exportTranslationURL,
{
articleId: articleIds[0],
exportMimeType,
sourceLanguageId,
targetLanguageIds: selectedTargetLanguageIds.join(','),
}
);
const onChangeTarget = (checked, selectedLanguageId) => {
if (checked) {
setSelectedTargetLanguageIds(
selectedTargetLanguageIds.concat(selectedLanguageId)
);
}
else {
setSelectedTargetLanguageIds(
selectedTargetLanguageIds.filter(
(languageId) => languageId != selectedLanguageId
)
);
}
};
const SourceLocales = () => {
if (availableSourceLocales.length == 1) {
return (
);
}
else {
return (
{
setSourceLanguageId(e.currentTarget.value);
}}
value={sourceLanguageId}
>
{availableSourceLocales.map((locale) => (
))}
);
}
};
const ExportFileFormats = () => {
if (availableExportFileFormats.length == 1) {
return (
);
}
else {
return (
{
setExportMimeType(e.currentTarget.value);
}}
value={exportMimeType}
>
{availableExportFileFormats.map((exportFileFormat) => (
))}
);
}
};
const TargetLocale = ({locale}) => {
const languageId = locale.languageId;
const checked = selectedTargetLanguageIds.indexOf(languageId) != -1;
return (
{
onChangeTarget(!checked, languageId);
}}
/>
);
};
return (
{Liferay.Language.get('export-for-translation')}
{
e.preventDefault();
onModalClose();
location.href = Liferay.Util.addParams(
'download=true',
exportTranslationPortletURL.toString()
);
}}
>
{Liferay.Language.get('export-file-format')}
{Liferay.Language.get('original-language')}
{Liferay.Language.get('languages-to-translate-to')}
{availableTargetLocales.map((locale) => (
))}
{Liferay.Language.get('cancel')}
{Liferay.Language.get('export')}
}
/>
);
};
ExportTranslationModal.propTypes = {
articleIds: PropTypes.array,
availableExportFileFormats: PropTypes.arrayOf(
PropTypes.shape({
displayName: PropTypes.string,
mimeType: PropTypes.string,
})
).isRequired,
availableSourceLocales: PropTypes.arrayOf(
PropTypes.shape({
displayName: PropTypes.string,
languageId: PropTypes.string,
})
).isRequired,
availableTargetLocales: PropTypes.arrayOf(
PropTypes.shape({
displayName: PropTypes.string,
languageId: PropTypes.string,
})
).isRequired,
defaultSourceLanguageId: PropTypes.string.isRequired,
};
export default ExportTranslationModal;