From 08563205520b854d6406253ac6de007cc7716a1d Mon Sep 17 00:00:00 2001 From: Jamie Nadeau Date: Thu, 29 Sep 2016 09:20:53 -0400 Subject: [PATCH] Added translation functionality Started to translate application to make it more available to more people --- OSVUploadr/pom.xml | 2 +- .../osmcanada/osvuploadr/FolderCleaner.java | 17 +++++- .../java/ca/osmcanada/osvuploadr/JFMain.java | 7 ++- .../ca/osmcanada/osvuploadr/JPInfoBox.form | 6 +- .../ca/osmcanada/osvuploadr/JPInfoBox.java | 26 +++++++-- .../java/ca/osmcanada/osvuploadr/JPMain.form | 6 +- .../java/ca/osmcanada/osvuploadr/JPMain.java | 58 +++++++++++++++---- .../src/main/resources/Bundle.properties | 19 ++++++ .../src/main/resources/Bundle_es.properties | 19 ++++++ .../src/main/resources/Bundle_fr.properties | 19 ++++++ README.md | 3 + 11 files changed, 154 insertions(+), 28 deletions(-) create mode 100644 OSVUploadr/src/main/resources/Bundle.properties create mode 100644 OSVUploadr/src/main/resources/Bundle_es.properties create mode 100644 OSVUploadr/src/main/resources/Bundle_fr.properties diff --git a/OSVUploadr/pom.xml b/OSVUploadr/pom.xml index 8df8cf2..ddb2fe8 100644 --- a/OSVUploadr/pom.xml +++ b/OSVUploadr/pom.xml @@ -3,7 +3,7 @@ 4.0.0 ca.osmcanada OSVUploadr - 0.1.2.2-ALPHA + 0.1.2.2.1-ALPHA jar diff --git a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/FolderCleaner.java b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/FolderCleaner.java index 675e859..9d4ce18 100644 --- a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/FolderCleaner.java +++ b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/FolderCleaner.java @@ -19,6 +19,8 @@ import java.nio.file.StandardCopyOption; import java.time.Instant; import java.util.HashMap; +import java.util.Locale; +import java.util.ResourceBundle; /** @@ -33,6 +35,8 @@ public class FolderCleaner { int radius_threshold = 20; // Minimum turn radius a photo should move to not be considered a duplicate (degrees) String duplicate_folder="duplicates"; JFMain info=null; + Locale l; + ResourceBundle r; private double calc_distance(double lon1, double lat1, double lon2, double lat2){ //haversine formula @@ -156,7 +160,11 @@ public void RemoveDuplicates(){ } do_science(); if(info!=null){ - info.SetInfoBoxText("Done"); + try{ + info.SetInfoBoxText(new String(r.getString("done").getBytes(),"UTF-8")); + } + catch(Exception ex) + {} } } @@ -164,8 +172,15 @@ public void setInfoBox(JFMain frame){ info=frame; } + public void setLocale(Locale locale){ + l=locale; + r=ResourceBundle.getBundle("Bundle",l); + } + public FolderCleaner(String Folder){ _folder=Folder; + l=Locale.getDefault(); + r=ResourceBundle.getBundle("Bundle",l); } diff --git a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JFMain.java b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JFMain.java index c1fb2db..f9b63d6 100644 --- a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JFMain.java +++ b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JFMain.java @@ -6,13 +6,14 @@ package ca.osmcanada.osvuploadr; import java.awt.BorderLayout; +import java.util.Locale; /** * * @author Jamie Nadeau */ public class JFMain extends javax.swing.JFrame { - static JPInfoBox jib = new JPInfoBox(); + static JPInfoBox jib; /** * Creates new form JFMain */ @@ -91,8 +92,10 @@ public static void main(String args[]) { /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { + Locale l = Locale.getDefault(); JFMain jf =new JFMain(); - JPMain jp = new JPMain(); + JPMain jp = new JPMain(l); + jib=new JPInfoBox(l); jp.setVisible(true); jib.setVisible(false); jf.add(jp,BorderLayout.NORTH); diff --git a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPInfoBox.form b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPInfoBox.form index 348d4e1..270af45 100644 --- a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPInfoBox.form +++ b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPInfoBox.form @@ -23,7 +23,7 @@ - + @@ -35,7 +35,7 @@ - + @@ -44,7 +44,7 @@ - + diff --git a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPInfoBox.java b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPInfoBox.java index 0f1ac45..1942418 100644 --- a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPInfoBox.java +++ b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPInfoBox.java @@ -5,6 +5,8 @@ */ package ca.osmcanada.osvuploadr; +import java.util.Locale; +import java.util.ResourceBundle; import javax.swing.UIManager; /** @@ -13,17 +15,29 @@ */ public class JPInfoBox extends javax.swing.JPanel { + private Locale l; + private ResourceBundle r; /** * Creates new form JPInfoBox */ - public JPInfoBox() { + public JPInfoBox(Locale locale) { + l=locale; try{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception ex){} initComponents(); + r=ResourceBundle.getBundle("Bundle",l); + SetUILang(); } + private void SetUILang(){ + try{ + jlCurrentlyProc.setText(new String(r.getString("currently_processing").getBytes(),"UTF-8")); + } + catch(Exception ex) + {} + } public void SetProcessingText(String str){ jlProcessing.setText(str); } @@ -36,12 +50,12 @@ public void SetProcessingText(String str){ // //GEN-BEGIN:initComponents private void initComponents() { - jLabel1 = new javax.swing.JLabel(); + jlCurrentlyProc = new javax.swing.JLabel(); jlProcessing = new javax.swing.JLabel(); setPreferredSize(new java.awt.Dimension(623, 150)); - jLabel1.setText("Currently Processing:"); + jlCurrentlyProc.setText("Currently Processing:"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); @@ -49,7 +63,7 @@ private void initComponents() { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(jLabel1) + .addComponent(jlCurrentlyProc) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jlProcessing, javax.swing.GroupLayout.DEFAULT_SIZE, 426, Short.MAX_VALUE) .addContainerGap()) @@ -59,7 +73,7 @@ private void initComponents() { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel1) + .addComponent(jlCurrentlyProc) .addComponent(jlProcessing, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(78, Short.MAX_VALUE)) ); @@ -67,7 +81,7 @@ private void initComponents() { // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jlCurrentlyProc; private javax.swing.JLabel jlProcessing; // End of variables declaration//GEN-END:variables } diff --git a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.form b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.form index daddf51..c535ac6 100644 --- a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.form +++ b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.form @@ -19,7 +19,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -96,7 +96,7 @@ - + diff --git a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java index 382d7ed..b6af58a 100644 --- a/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java +++ b/OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java @@ -52,7 +52,10 @@ import java.util.regex.Pattern; import ca.osmcanada.osvuploadr.Utils.*; import ca.osmcanada.osvuploadr.struct.PageContent; +import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; +import java.util.Locale; +import java.util.ResourceBundle; import org.apache.http.client.HttpClient; import org.apache.http.client.CookieStore; import org.apache.http.cookie.Cookie; @@ -74,17 +77,43 @@ public class JPMain extends javax.swing.JPanel { private final String API_KEY = "rBWV8Eaottv44tXfdLofdNvVemHOL62Lsutpb9tw"; private final String API_SECRET = "rpmeZIp49sEjjcz91X9dsY0vD1PpEduixuPy8T6S"; private String last_dir =""; + private Locale l; + private ResourceBundle r; UploadManager um; /** * Creates new form JPMain */ - public JPMain() { + public JPMain(Locale locale) { + l = locale; try{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception ex){} initComponents(); + try{ + r=ResourceBundle.getBundle("Bundle",l); + } + catch(Exception ex){ + System.out.println(ex.toString()); + } + + SetUILang(); + + } + + private void SetUILang(){ + try{ + jlDirectories.setText(new String(r.getString("Directories").getBytes(),"UTF-8")); + jbAdd.setText(new String(r.getString("Add_Folder").getBytes(),"UTF-8")); + jbRemove.setText(new String(r.getString("Remove_Folder").getBytes(),"UTF-8")); + jbRemoveDup.setText(new String(r.getString("Remove_Duplicates").getBytes(),"UTF-8")); + jbUpload.setText(new String(r.getString("Upload").getBytes(),"UTF-8")); + jbExit.setText(new String(r.getString("Exit").getBytes(),"UTF-8")); + } + catch(Exception ex){ + + } } public String GetOSMUser(String usr, String psw)throws IOException{ @@ -208,7 +237,7 @@ public String GetOSMUser() throws IOException{ String url = service.getAuthorizationUrl(requestToken); Helper.OpenBrowser(java.net.URI.create(url)); //java.awt.Desktop.getDesktop().browse(java.net.URI.create(url)); - String pin_code = JOptionPane.showInputDialog(null, "Authorization window has opened, please paste authorization code below once authorized.\nWith out the \".\" at the end", "Authorization Required", JOptionPane.INFORMATION_MESSAGE); + String pin_code = JOptionPane.showInputDialog(null, new String(r.getString("auth_window_opened").getBytes(),"UTF-8"), new String(r.getString("auth_required").getBytes(),"UTF-8"), JOptionPane.INFORMATION_MESSAGE); final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, pin_code); //final OAuthRequest request = new OAuthRequest(Verb.GET, BASE_URL + "api/0.6/user/details", service); //service.signRequest(accessToken, request); @@ -724,7 +753,7 @@ private void initComponents() { jbAdd = new javax.swing.JButton(); listDir = new java.awt.List(); - jLabel1 = new javax.swing.JLabel(); + jlDirectories = new javax.swing.JLabel(); jbRemoveDup = new javax.swing.JButton(); jbUpload = new javax.swing.JButton(); jbExit = new javax.swing.JButton(); @@ -747,7 +776,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); - jLabel1.setText("Directories"); + jlDirectories.setText("Directories"); jbRemoveDup.setText("Remove Duplicates"); jbRemoveDup.addActionListener(new java.awt.event.ActionListener() { @@ -788,7 +817,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jlDirectories, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addComponent(listDir, javax.swing.GroupLayout.PREFERRED_SIZE, 456, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -809,7 +838,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(19, 19, 19) - .addComponent(jLabel1) + .addComponent(jlDirectories) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(listDir, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -837,6 +866,7 @@ private void jbExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST: }//GEN-LAST:event_jbExitActionPerformed private void jbAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddActionPerformed + try{ JFileChooser fc = new JFileChooser(); if(!last_dir.isEmpty()){ fc.setCurrentDirectory(new java.io.File(last_dir)); // start at application current directory @@ -844,7 +874,7 @@ private void jbAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:e fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showSaveDialog(this); if(returnVal == JFileChooser.APPROVE_OPTION) { - int response = JOptionPane.showConfirmDialog(null, "Do you wish to add all immediate subfolders of this folder?", "Add subfolders?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + int response = JOptionPane.showConfirmDialog(null, new String(r.getString("immediate_sub_folders").getBytes(),"UTF-8"), new String(r.getString("add_subfolders").getBytes(),"UTF-8"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(response == JOptionPane.NO_OPTION){ File folder = fc.getSelectedFile(); listDir.add(folder.getPath()); @@ -865,6 +895,9 @@ public boolean accept(File current, String name){ } } } + } + catch(UnsupportedEncodingException ex) + {} }//GEN-LAST:event_jbAddActionPerformed private void jbRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRemoveActionPerformed @@ -894,8 +927,8 @@ private void jbUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS if(!id.exists()) { try{ - String[] buttons={"Automatically","Manually","Cancel"}; - int rc = JOptionPane.showOptionDialog(null,"You must login to OSM to continue the upload. Would you like the automated version or the manual version?","Confirmation",JOptionPane.INFORMATION_MESSAGE,0,null,buttons,buttons[0]); + String[] buttons={new String(r.getString("automatically").getBytes(),"UTF-8"),new String(r.getString("manually").getBytes(),"UTF-8"),new String(r.getString("cancel").getBytes(),"UTF-8")}; + int rc = JOptionPane.showOptionDialog(null,new String(r.getString("login_to_osm").getBytes(),"UTF-8"),new String(r.getString("confirmation").getBytes(),"UTF-8"),JOptionPane.INFORMATION_MESSAGE,0,null,buttons,buttons[0]); String token=""; System.out.println("GetOSMUser"); switch(rc){ @@ -904,7 +937,7 @@ private void jbUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS String psw = ""; JTextField tf = new JTextField(); JPasswordField pf = new JPasswordField(); - rc = JOptionPane.showConfirmDialog(null,tf,"Enter email address or OSM username", JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE); + rc = JOptionPane.showConfirmDialog(null,tf,new String(r.getString("email_osm_usr").getBytes(),"UTF-8"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE); if(rc == JOptionPane.OK_OPTION){ usr = tf.getText(); } @@ -912,7 +945,7 @@ private void jbUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS return; } - rc = JOptionPane.showConfirmDialog(null,pf,"Please enter password", JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE); + rc = JOptionPane.showConfirmDialog(null,pf,new String(r.getString("enter_password").getBytes(),"UTF-8"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE); if(rc == JOptionPane.OK_OPTION){ psw = new String(pf.getPassword()); } @@ -973,6 +1006,7 @@ private void jbRemoveDupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F Thread t = new Thread(){ public void run(){ FolderCleaner fc = new FolderCleaner(item); + fc.setLocale(l); fc.setInfoBox(topframe); fc.RemoveDuplicates(); } @@ -983,12 +1017,12 @@ public void run(){ // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JLabel jLabel1; private javax.swing.JButton jbAdd; private javax.swing.JButton jbExit; private javax.swing.JButton jbRemove; private javax.swing.JButton jbRemoveDup; private javax.swing.JButton jbUpload; + private javax.swing.JLabel jlDirectories; private java.awt.List listDir; // End of variables declaration//GEN-END:variables } diff --git a/OSVUploadr/src/main/resources/Bundle.properties b/OSVUploadr/src/main/resources/Bundle.properties new file mode 100644 index 0000000..a5a1283 --- /dev/null +++ b/OSVUploadr/src/main/resources/Bundle.properties @@ -0,0 +1,19 @@ +Directories=Directories +Add_Folder=Add Folder +Remove_Folder=Remove Folder +Remove_Duplicates=Remove Duplicates +Upload=Upload +Exit=Exit +auth_window_opened=Authorization window has opened, please paste authorization code below once authorized.\nWithout the \".\" at the end +auth_required=Authorization Required +immediate_sub_folders=Do you wish to add all immediate sub-folders of this folder? +add_subfolders=Add sub-folders? +automatically=Automatically +manually=Manually +cancel=Cancel +login_to_osm=You must login to OSM to continue the upload. Would you like the automated version or the manual version? +confirmation=Confirmation +email_osm_usr=Enter email address or OSM username +enter_password=Please enter password +currently_processing=Currently Processing: +done=Done \ No newline at end of file diff --git a/OSVUploadr/src/main/resources/Bundle_es.properties b/OSVUploadr/src/main/resources/Bundle_es.properties new file mode 100644 index 0000000..29e80ba --- /dev/null +++ b/OSVUploadr/src/main/resources/Bundle_es.properties @@ -0,0 +1,19 @@ +Directories=Carpetas +Add_Folder=Añadir carpeta +Remove_Folder=Supprimir carpeta +Remove_Duplicates=Eliminar duplicados +Upload=Subir +Exit=Salida +auth_window_opened=Una ventana de autorización ha abierto, por favor pegar el código de autorización a continuación una vez autorizado.\nSin el \".\" Al final +auth_required=Autorización requerida +immediate_sub_folders=¿Quiere usted añadir todas las subcarpetas inmediatas de esta carpeta? +add_subfolders=Añadir subcarpetas? +automatically=Automáticamente +manually=Manual +cancel=Cancelar +login_to_osm=Usted debe iniciar sesión para OSM para continuar la carga. ¿Quiere usted la versión automatizada o manual de la versión? +confirmation=Confirmación +email_osm_usr=Escriba su correo electrónico o usuario de OSM +enter_password=Introduzca su contraseña +currently_processing=En tratamiento: +done=Acabado \ No newline at end of file diff --git a/OSVUploadr/src/main/resources/Bundle_fr.properties b/OSVUploadr/src/main/resources/Bundle_fr.properties new file mode 100644 index 0000000..dd67d8b --- /dev/null +++ b/OSVUploadr/src/main/resources/Bundle_fr.properties @@ -0,0 +1,19 @@ +Directories=Dossiers +Add_Folder=Ajouter dossier +Remove_Folder=Supprimer dossier +Remove_Duplicates=Enlever dupliquas +Upload=Téléverser +Exit=Quitter +auth_window_opened=Une fenêtre d’autorisation s'est ouvert, veuillez copier le code d’autorisation quand vous êtes connecté.\nSans le \",\" à la fin +auth_required=Autorisation requise +immediate_sub_folders=Voulez-vous ajouter tous les sous dossier immédiats dans ce dossier? +add_subfolders=Ajouter sous dossiers? +automatically=Automatiquement +manually=Manuellement +cancel=Annuler +login_to_osm=Vous devez vous connecter à OSM pour continuer de téléverser. Voulez-vous la version automatisé ou manuelle? +confirmation=Confirmation +email_osm_usr=Entrez votre courriel ou utilisateur OSM +enter_password=Veuillez entrer votre mot de passe +currently_processing=En traitement: +done=Terminé \ No newline at end of file diff --git a/README.md b/README.md index b162efe..302d5cb 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ To start the application you need the java runtime environment(JRE) version 1.8+ Once you have added the folders to be processed, press the "**Remove Duplicates**" button. This is a **non destructive** option, it will simply move the duplicates into a folder called duplicates. If you ever need them again they will be available. This will process every folder in the directory list. +## Contribute ## +If you want to contribute to the translation of this application you may do so [here](https://www.transifex.com/james2432/osvuploadr) +Currently the application is only available in English, French and Spanish. If you need a language added to the project, just open an issue on this github page. ## Known issues ## - Upload process is not threaded, so the upload button will look frozen until it finishes the upload.