-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from DivanteLtd/feature/deepl
DeepL Formality
- Loading branch information
Showing
4 changed files
with
120 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/DivanteTranslationBundle/Controller/ProviderController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace DivanteTranslationBundle\Controller; | ||
|
||
use DivanteTranslationBundle\Provider\ProviderFactory; | ||
use Pimcore\Bundle\AdminBundle\Controller\AdminController; | ||
use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
/** | ||
* @Route("/admin") | ||
*/ | ||
final class ProviderController extends AdminController | ||
{ | ||
private string $sourceLanguage; | ||
private string $provider; | ||
|
||
public function __construct(string $sourceLanguage, string $provider) | ||
{ | ||
$this->sourceLanguage = $sourceLanguage; | ||
$this->provider = $provider; | ||
} | ||
|
||
/** | ||
* @Route("/translate-provider", methods={"GET"}) | ||
*/ | ||
public function translationProviderInfoAction(): JsonResponse | ||
{ | ||
return $this->adminJson([ | ||
'provider' => $this->provider | ||
]); | ||
} | ||
} |
120 changes: 73 additions & 47 deletions
120
src/DivanteTranslationBundle/Resources/public/js/pimcore/object/elementservice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,80 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Enterprise License (PEL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PEL | ||
*/ | ||
|
||
pimcore.registerNS("pimcore.object.elementservice.x"); | ||
|
||
pimcore.object.elementservice.translateButton = function (id, fieldName, component, type, lang) { | ||
return new Ext.Button({ | ||
iconCls: "pimcore_icon_translations", | ||
cls: 'pimcore_button_transparent', | ||
tooltip: t("translate_field"), | ||
handler: function () { | ||
Ext.Ajax.request({ | ||
url: "/admin/object/translate-field", | ||
method: "GET", | ||
params: { | ||
sourceId: id, | ||
fieldName: fieldName, | ||
lang: lang, | ||
type: type | ||
var provider = pimcore.globalmanager.get('translationBundle_provider'); | ||
|
||
if (provider === 'deepl' || provider === 'deepl_free') { | ||
return new Ext.Button({ | ||
iconCls: "pimcore_icon_translations", | ||
cls: 'pimcore_button_transparent', | ||
tooltip: t("translate_field"), | ||
menu: [ | ||
{ | ||
text: 'Formality Default', | ||
handler: function () { | ||
handleTranslationRequest(id, fieldName, component, type, lang, 'default') | ||
}.bind(this), | ||
iconCls: "pimcore_icon_more", | ||
}, | ||
{ | ||
text: 'Formality More', | ||
handler: function () { | ||
handleTranslationRequest(id, fieldName, component, type, lang, 'more') | ||
}.bind(this), | ||
iconCls: 'pimcore_icon_up' | ||
}, | ||
{ | ||
text: 'Formality Less', | ||
handler: function () { | ||
handleTranslationRequest(id, fieldName, component, type, lang, 'less') | ||
}.bind(this), | ||
iconCls: 'pimcore_icon_down' | ||
}, | ||
success: function (response) { | ||
var res = Ext.decode(response.responseText); | ||
], | ||
style: "margin-left: 10px; filter:grayscale(100%);", | ||
}); | ||
} else { | ||
return new Ext.Button({ | ||
iconCls: "pimcore_icon_translations", | ||
cls: 'pimcore_button_transparent', | ||
tooltip: t("translate_field"), | ||
handler: function () { | ||
handleTranslationRequest(id, fieldName, component, type, lang, '') | ||
}.bind(this), | ||
style: "margin-left: 10px; filter:grayscale(100%);", | ||
}); | ||
} | ||
}; | ||
|
||
function handleTranslationRequest(id, fieldName, component, type, lang, formality) { | ||
Ext.Ajax.request({ | ||
url: "/admin/object/translate-field", | ||
method: "GET", | ||
params: { | ||
sourceId: id, | ||
fieldName: fieldName, | ||
lang: lang, | ||
type: type, | ||
formality: formality | ||
}, | ||
success: function (response) { | ||
var res = Ext.decode(response.responseText); | ||
|
||
if (res.success) { | ||
switch (type) { | ||
case 'wysiwyg': | ||
CKEDITOR.instances[component.editableDivId].setData(res.data); | ||
break; | ||
case 'input': | ||
component.setRawValue(res.data); | ||
break; | ||
case 'textarea': | ||
component.component.setValue(res.data); | ||
break; | ||
} | ||
} else { | ||
pimcore.helpers.showPrettyError('object', t("error"), t("saving_failed"), res.message); | ||
} | ||
if (res.success) { | ||
switch (type) { | ||
case 'wysiwyg': | ||
CKEDITOR.instances[component.editableDivId].setData(res.data); | ||
break; | ||
case 'input': | ||
component.setRawValue(res.data); | ||
break; | ||
case 'textarea': | ||
component.component.setValue(res.data); | ||
break; | ||
} | ||
}); | ||
}.bind(this), | ||
style: "margin-left: 10px; filter:grayscale(100%);", | ||
} else { | ||
pimcore.helpers.showPrettyError('object', t("error"), t("saving_failed"), res.message); | ||
} | ||
} | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters