mirror of
https://github.com/igniterealtime/Spark.git
synced 2026-02-04 19:25:37 +00:00
TranslatorPlugin: extract transcriptWindow variable
This commit is contained in:
committed by
Guus der Kinderen
parent
421b8db512
commit
46da3d6db5
@ -42,20 +42,20 @@ public class TranslatorPlugin implements Plugin {
|
||||
/**
|
||||
* Called after Spark is loaded to initialize the new plugin.
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
TranslatorPreference pref = new TranslatorPreference();
|
||||
SparkManager.getPreferenceManager().addPreference(pref);
|
||||
|
||||
// Retrieve ChatManager from the SparkManager
|
||||
final ChatManager chatManager = SparkManager.getChatManager();
|
||||
|
||||
// Add to a new ChatRoom when the ChatRoom opens.
|
||||
chatManager.addChatRoomListener(new ChatRoomListenerAdapter() {
|
||||
public void chatRoomOpened(ChatRoom room) {
|
||||
// only do the translation for single chat
|
||||
if (room instanceof ChatRoomImpl && TranslatorProperties.getInstance().getEnabledTranslator()) {
|
||||
final ChatRoomImpl roomImpl = (ChatRoomImpl)room;
|
||||
final TranscriptWindow transcriptWindow = roomImpl.getTranscriptWindow();
|
||||
|
||||
//Set server LibreTranslate API
|
||||
if(TranslatorProperties.getInstance().getUseCustomUrl() && !StringUtils.isBlank(TranslatorProperties.getInstance().getUrl())){
|
||||
@ -76,12 +76,12 @@ public class TranslatorPlugin implements Plugin {
|
||||
|
||||
// do the translation for outgoing messages.
|
||||
final MessageEventListener messageListener = new MessageEventListener() {
|
||||
@Override
|
||||
public void sendingMessage(Message message) {
|
||||
String currentBody = message.getBody();
|
||||
Language lang = (Language) translatorBox.getSelectedItem();
|
||||
if (lang != null && lang != Language.NONE) {
|
||||
message.setBody(null);
|
||||
TranscriptWindow transcriptWindow = chatManager.getChatRoom( message.getTo().asEntityBareJidOrThrow() ).getTranscriptWindow();
|
||||
try {
|
||||
currentBody = TranslatorUtil.translate(currentBody, lang);
|
||||
transcriptWindow.insertNotificationMessage("-> "+currentBody, Color.gray);
|
||||
@ -91,8 +91,8 @@ public class TranslatorPlugin implements Plugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receivingMessage(Message message) {
|
||||
// do nothing
|
||||
}
|
||||
@ -107,6 +107,7 @@ public class TranslatorPlugin implements Plugin {
|
||||
* Called when Spark is shutting down to allow for persistence of information
|
||||
* or releasing of resources.
|
||||
*/
|
||||
@Override
|
||||
public void shutdown() {
|
||||
|
||||
}
|
||||
@ -116,6 +117,7 @@ public class TranslatorPlugin implements Plugin {
|
||||
*
|
||||
* @return true if Spark can shutdown on users request.
|
||||
*/
|
||||
@Override
|
||||
public boolean canShutDown() {
|
||||
return true;
|
||||
}
|
||||
@ -125,6 +127,7 @@ public class TranslatorPlugin implements Plugin {
|
||||
* The plugin owner is responsible to clean up any resources and
|
||||
* remove any components install in Spark.
|
||||
*/
|
||||
@Override
|
||||
public void uninstall() {
|
||||
// Remove all resources belonging to this plugin.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user