mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-11 23:46:15 +00:00
5063 address some codacy complaints
This commit is contained in:
parent
58e2a4953e
commit
a02319ba6f
@ -1,4 +1,4 @@
|
||||
GoogleTranslatorSettingsPanel.browseButton.text=Browse
|
||||
GoogleTranslatorSettingsPanel.credentialsLabel.text=Credentials:
|
||||
GoogleTranslatorSettingsPanel.jLabel1.text=Target Language:
|
||||
GoogleTranslatorSettingsPanel.warningLabel.text=
|
||||
GoogleTranslatorSettingsPanel.targetLanguageLabel.text=Target Language:
|
||||
|
@ -8,6 +8,6 @@ GoogleTranslatorSettingsPanel.errorMessage.unableToReadCredentials=Unable to rea
|
||||
GoogleTranslatorSettingsPanel.errorMessage.unknownFailureGetting=Failure getting list of supported languages with current credentials file.
|
||||
GoogleTranslatorSettingsPanel.errorMessage.unknownFailurePopulating=Failure populating list of supported languages with current credentials file.
|
||||
GoogleTranslatorSettingsPanel.fileChooser.confirmButton=Select
|
||||
GoogleTranslatorSettingsPanel.jLabel1.text=Target Language:
|
||||
GoogleTranslatorSettingsPanel.json.description=JSON Files
|
||||
GoogleTranslatorSettingsPanel.warningLabel.text=
|
||||
GoogleTranslatorSettingsPanel.targetLanguageLabel.text=Target Language:
|
||||
|
@ -46,7 +46,7 @@ public final class GoogleTranslator implements TextTranslator {
|
||||
private static final int MAX_STRING_LENGTH = 15000;
|
||||
private final GoogleTranslatorSettingsPanel settingsPanel;
|
||||
private final GoogleTranslatorSettings settings = new GoogleTranslatorSettings();
|
||||
private Translate translate;
|
||||
private Translate googleTranslate;
|
||||
|
||||
/**
|
||||
* Constructs a new GoogleTranslator
|
||||
@ -59,7 +59,7 @@ public final class GoogleTranslator implements TextTranslator {
|
||||
|
||||
@Override
|
||||
public String translate(String string) throws TranslationException {
|
||||
if (translate != null) {
|
||||
if (googleTranslate != null) {
|
||||
try {
|
||||
// Translates some text into English, without specifying the source language.
|
||||
|
||||
@ -72,21 +72,22 @@ public final class GoogleTranslator implements TextTranslator {
|
||||
|
||||
// The API complains if the "Payload" is over 204800 bytes. I'm assuming that
|
||||
// deals with the full request. At some point, we get different errors about too
|
||||
// much text. Officially, Google says they will translate only 5k chars,
|
||||
// much text. Officially, Google says they will googleTranslate only 5k chars,
|
||||
// but we have seen more than that working.
|
||||
// there could be a value betwen 15k and 25k that works. I (BC) didn't test further
|
||||
if (substring.length() > MAX_STRING_LENGTH) {
|
||||
substring = substring.substring(0, MAX_STRING_LENGTH);
|
||||
}
|
||||
Translation translation
|
||||
= translate.translate(substring);
|
||||
= googleTranslate.translate(substring);
|
||||
String translatedString = translation.getTranslatedText();
|
||||
|
||||
// put back the newlines
|
||||
translatedString = translatedString.replaceAll("<br />", "\n");
|
||||
return translatedString;
|
||||
} catch (Throwable e) {
|
||||
throw new TranslationException(e.getMessage());
|
||||
} catch (Throwable ex) {
|
||||
//Catching throwables because some of this Google Translate code throws throwables
|
||||
throw new TranslationException("Failure translating using GoogleTranslator", ex);
|
||||
}
|
||||
} else {
|
||||
throw new TranslationException("Google Translator has not been configured, credentials need to be specified");
|
||||
@ -125,12 +126,12 @@ public final class GoogleTranslator implements TextTranslator {
|
||||
}
|
||||
if (creds == null) {
|
||||
logger.log(Level.WARNING, "Credentials were not successfully made, no translations will be available from the GoogleTranslator");
|
||||
translate = null;
|
||||
googleTranslate = null;
|
||||
} else {
|
||||
TranslateOptions.Builder builder = TranslateOptions.newBuilder();
|
||||
builder.setCredentials(creds);
|
||||
builder.setTargetLanguage(settings.getTargetLanguageCode());
|
||||
translate = builder.build().getService();
|
||||
googleTranslate = builder.build().getService();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="credentialsLabel" max="32767" attributes="0"/>
|
||||
<Component id="jLabel1" max="32767" attributes="0"/>
|
||||
<Component id="targetLanguageLabel" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
@ -57,7 +57,7 @@
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="targetLanguageLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="targetLanguageComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
@ -101,10 +101,10 @@
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<org.sleuthkit.autopsy.texttranslation.translators.GoogleLanguageWrapper>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||
<Component class="javax.swing.JLabel" name="targetLanguageLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
|
||||
<ResourceString bundle="org/sleuthkit/autopsy/texttranslation/translators/Bundle.properties" key="GoogleTranslatorSettingsPanel.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
|
||||
<ResourceString bundle="org/sleuthkit/autopsy/texttranslation/translators/Bundle.properties" key="GoogleTranslatorSettingsPanel.targetLanguageLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
|
@ -73,13 +73,13 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
//This method also has the side effect of more or less validating the JSON file which was selected as it is necessary to get the list of target languages
|
||||
try {
|
||||
InputStream credentialStream;
|
||||
Credentials creds;
|
||||
try {
|
||||
credentialStream = new FileInputStream(credentialsPathField.getText());
|
||||
} catch (FileNotFoundException ignored) {
|
||||
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_fileNotFound());
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Credentials creds;
|
||||
try {
|
||||
creds = ServiceAccountCredentials.fromStream(credentialStream);
|
||||
} catch (IOException ignored) {
|
||||
@ -98,6 +98,7 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
return builder.build().getService().listSupportedLanguages();
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
//Catching throwables because some of this Google Translate code throws throwables
|
||||
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unknownFailureGetting());
|
||||
logger.log(Level.WARNING, "Throwable caught while getting list of supported languages", throwable);
|
||||
return new ArrayList<>();
|
||||
@ -164,7 +165,7 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
credentialsPathField = new javax.swing.JTextField();
|
||||
browseButton = new javax.swing.JButton();
|
||||
targetLanguageComboBox = new javax.swing.JComboBox<>();
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
targetLanguageLabel = new javax.swing.JLabel();
|
||||
warningLabel = new javax.swing.JLabel();
|
||||
|
||||
org.openide.awt.Mnemonics.setLocalizedText(credentialsLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.credentialsLabel.text")); // NOI18N
|
||||
@ -180,7 +181,7 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
|
||||
targetLanguageComboBox.setEnabled(false);
|
||||
|
||||
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.jLabel1.text")); // NOI18N
|
||||
org.openide.awt.Mnemonics.setLocalizedText(targetLanguageLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.targetLanguageLabel.text")); // NOI18N
|
||||
|
||||
warningLabel.setForeground(new java.awt.Color(255, 0, 0));
|
||||
org.openide.awt.Mnemonics.setLocalizedText(warningLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.warningLabel.text")); // NOI18N
|
||||
@ -198,7 +199,7 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(credentialsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addComponent(targetLanguageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
@ -220,7 +221,7 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
.addComponent(browseButton))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel1)
|
||||
.addComponent(targetLanguageLabel)
|
||||
.addComponent(targetLanguageComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(warningLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
@ -252,8 +253,8 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
private javax.swing.JButton browseButton;
|
||||
private javax.swing.JLabel credentialsLabel;
|
||||
private javax.swing.JTextField credentialsPathField;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JComboBox<org.sleuthkit.autopsy.texttranslation.translators.GoogleLanguageWrapper> targetLanguageComboBox;
|
||||
private javax.swing.JLabel targetLanguageLabel;
|
||||
private javax.swing.JLabel warningLabel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
|
@ -20,6 +20,9 @@ package org.sleuthkit.autopsy.texttranslation.translators;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for the GoogleTranslator
|
||||
*/
|
||||
public class GoogleTranslatorTest {
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user