Hello Ana,
Your comment looks positive. If you have some more information it will be helpful for me.
Here how to get the "element" here ? (especially for the content creator side for all sections used in the page and user clicks the sections dynamically to change the content in the sections in the page)
translationOperation.setSourceLanguage(element.getProject().getMasterLanguage());
I would like to add the translation feature for all sections in the templates of content creator.
1) First Step to add the translation button icon in all the section.
2) Implementing the plugin for translation with third party plugin to translate the text in content creator section where the user click the button to open for the translation.
Do we required any scriptcontext and interface Executable here?
public class TranslationInlineSection implements Executable {
private static Class<TranslationInlineSection> LOGGER = TranslationInlineSection.class;
private BaseContext baseContext = null;
private Language currentLanguage = null;
private LanguageAgent languageAgent = null;
private PageRef currentPageRef = null;
private Map<String, Language> projectLanguages = null;
// Assuming we have a BaseContext object named 'context' and
// a store element object of type DataProvider named 'element' available...
public TranslationInlineSection() {
super();
}
public void translationInlineSection(BaseContext context) {
baseContext = context;
if (baseContext.is(BaseContext.Env.WEBEDIT)) {
WebeditUiAgent webeditUiAgent = baseContext.requireSpecialist(WebeditUiAgent.TYPE);
currentLanguage = webeditUiAgent.getPreviewLanguage();
// Obtain a LanguageAgent to get a map of project languages.
languageAgent = context.requireSpecialist(LanguageAgent.TYPE);
projectLanguages = languageAgent.getProjectLanguages(false);
if(webeditUiAgent.getPreviewElement() instanceof PageRef) {
currentPageRef = (PageRef) webeditUiAgent.getPreviewElement();
}
translationOperation(baseContext);
}
}
private void translationOperation(BaseContext context) {
final OperationAgent operationAgent = context.requireSpecialist(OperationAgent.TYPE);
final TranslationOperation translationOperation = operationAgent.getOperation(TranslationOperation.TYPE);
if (translationOperation != null) {
translationOperation.setElement(element);
translationOperation.setSourceLanguage(element.getProject().getMasterLanguage());
translationOperation.setTargetLanguage(currentLanguage);
// According to the above configuration: open a translation help dialog for the
// element
// indicated by 'element', and translate from English to Welsh.
translationOperation.perform();
}
}
@Override
public Object execute(Map<String, Object> params, Writer out, Writer err) throws ExecutionException {
final BaseContext context = (BaseContext) params.get("context");
translationOperation(context);
return true;
}
}
Thank you.
Siva