Changeset 1064


Ignore:
Timestamp:
06/30/09 18:05:35 (15 years ago)
Author:
alexandrecorreia
Message:

Ticket #474 - Arquivos modificados para a tradução do Applet.

Location:
trunk/jabberit_messenger/java_source/src/nu/fw/jeti
Files:
3 added
4 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/jabberit_messenger/java_source/src/nu/fw/jeti/applet/Jeti.java

    r1014 r1064  
    6666{ 
    6767        private Start start; 
    68         public static JLabel from; 
    6968        private static Jeti applet; 
    7069        private URL exitURL; 
    7170        private static String groupchatRoom; 
    7271        private static String groupchatServer; 
    73         public static LoginInfo loginInfo; 
    7472        private Backend backend; 
    7573        private boolean started = false; 
    7674        private SecureMethodRunner secureMethodInvoker; 
     75        public static JLabel from; 
     76        public static LoginInfo loginInfo; 
    7777        public static String SERVEREXPRESSO; 
    7878        public static String NAMECOMPANY; 
     
    8282        public static List GROUPSUSER; 
    8383        public static String SERVERJABBER; 
     84        public static String COUNTRY; 
     85        public static String LANGUAGE; 
     86         
    8487        /** 
    8588         * @Author      : Alexandre Correia - alexandrecorreia@celepar.pr.gov.br 
     
    109112                                String nameCompany = new String(applet.getParameter("NAMECOMPANY")); 
    110113                                String cnName = new String(applet.getParameter("CNNAME")); 
    111                                  
     114                                String country = new String(applet.getParameter("COUNTRY")); 
     115                                String language = new String(applet.getParameter("LANGUAGE")); 
     116 
    112117                                /** 
    113118                                 * @Author : Alexandre Correia - alexandrecorreia@celepar.pr.gov.br 
     
    125130                                USEHTTPS = useHttps; 
    126131                                CNNAME = cnName; 
     132                                LANGUAGE = language; 
     133                                COUNTRY = country; 
     134 
     135                                // Reinit languages incase they changed 
     136                                I18N.init(language, country); 
    127137                                 
    128138                                groupchatRoom = getParameter("GROUPCHATROOM"); 
     
    144154                                                loginInfo = new LoginInfo(server,host,user,password,resource,port,ssl,0,false); 
    145155                                } 
    146                                  
     156 
    147157                                Start.programURL = getCodeBase(); 
    148158                                Start.applet = true; 
     
    150160                                start = new Start(getCodeBase().toString(),panel); 
    151161                                 
    152                                 // Reinit languages incase they changed 
    153                                 I18N.init(); 
    154  
    155162                                backend = start.getBackend(); 
    156163                                backend.getMain().translate(); 
  • trunk/jabberit_messenger/java_source/src/nu/fw/jeti/backend/Start.java

    r1014 r1064  
    5656{ 
    5757        public static final String VERSION = "0.7.7"; 
    58         //public final static String OS2 = "/2"; 
    5958        public final static String OS2 = ""; 
    6059        public static String BUILD_DATE; 
     
    8988                        ex.printStackTrace(); 
    9089                } 
    91                 if(!applet && System.getProperty("jnlpx.home")!=null)webstart = true; 
    92                  
    93                 if (urlString == null) urlString = getPath(); 
     90                 
     91                if ( urlString == null)  
     92                        urlString = getPath(); 
    9493                 
    9594                if (System.getProperty("file.separator").equals("/")) 
     
    9796                        pluginPath = urlString.substring(5); 
    9897                } 
    99                 else pluginPath = urlString.substring(6); 
     98                else  
     99                        pluginPath = urlString.substring(6); 
     100                 
    100101                pluginPath = pluginPath.replace('/', File.separatorChar); 
    101102                 
    102                  
    103                  
    104                 if(programURL==null) 
    105                 { 
    106                         try 
    107                         { 
    108                                 programURL = new URL(urlString); 
    109                                  
    110                                 if(webstart || (path!=null&&path.equals("home"))) 
    111                                 { 
    112                                         path = System.getProperty("user.home")+ File.separatorChar 
    113                                                                                                 + ".jeti" +File.separatorChar; 
    114                                         File dir =new File(path); 
    115                                         if(!dir.exists()) 
    116                                         { 
    117                                                 if(!dir.mkdir()) 
    118                                                 { 
    119                                                         JOptionPane.showMessageDialog(null, "Directory " + dir + " could not be created, Jeti will close"); 
    120                                                         System.exit(1); 
    121                                                 } 
    122                                         } 
    123                                         dataURL = new URL("file:/"+path); 
    124                                 } 
    125                                 else if(path!=null) 
    126                                 { 
    127                                         File dir =new File(path); 
    128                                         if(!dir.exists()) 
    129                                         { 
    130                                                 if(!dir.mkdir()) 
    131                                                 { 
    132                                                         JOptionPane.showMessageDialog(null, "Directory " + dir + " could not be created, Jeti will close"); 
    133                                                         System.exit(1); 
    134                                                 } 
    135                                         } 
    136                                         dataURL = new URL("file:/"+path); 
    137                                 } 
    138                                 else 
    139                                 { 
    140                                         dataURL = programURL; 
    141                                         path = pluginPath; 
    142                                 } 
    143                                 System.out.println(programURL); 
    144                                 System.out.println(dataURL); 
    145                         } 
    146                         catch (MalformedURLException ex) 
    147                         { 
    148                                 ex.printStackTrace(); 
    149                         } 
    150                 } 
    151                 else  
    152                 { 
    153                         //if programurl null applet or network so use program path as data path  
    154                         dataURL = programURL; 
    155                         path = pluginPath; 
    156                 } 
    157                                                  
     103                /** 
     104                 * Se o programurl for null, applet ou network tb usa program path como data path 
     105                 */ 
     106                 
     107                dataURL = programURL; 
     108                path = pluginPath; 
     109 
    158110                try 
    159111                { 
     
    162114                        BUILD_DATE = p.getProperty("buildDate"); 
    163115                        BUILD_NUM = p.getProperty("buildNum"); 
    164                 } catch (Exception e) 
     116                }  
     117                catch (Exception e) 
    165118                { 
    166119                        System.out.println("Can't find the version.properties file"); 
     
    170123                backend = new Backend(this); 
    171124                new Preferences(backend, parser); 
    172                 I18N.init(); 
    173                 //Preferences.initMessages(); 
    174125                JFrame.setDefaultLookAndFeelDecorated(Preferences.getBoolean("jeti","javadecorations",false)); 
    175126                 
    176                 if(Preferences.getBoolean("jeti", "nativeLnF", false)) 
    177                 { 
    178                         try 
    179                         { 
    180                                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
    181                         } catch (ClassNotFoundException e) 
    182                         { 
    183                                 e.printStackTrace(); 
    184                         } catch (InstantiationException e) 
    185                         { 
    186                                 e.printStackTrace(); 
    187                         } catch (IllegalAccessException e) 
    188                         { 
    189                                 e.printStackTrace(); 
    190                         } catch (UnsupportedLookAndFeelException e) 
    191                         { 
    192                                 e.printStackTrace(); 
    193                         } 
    194                 } 
    195127                //parse plugins? make better or make comments 
    196128                new StatusIcons(parser); 
  • trunk/jabberit_messenger/java_source/src/nu/fw/jeti/ui/Jeti.java

    r1014 r1064  
    455455                } 
    456456         
    457                 if(Preferences.getBoolean("jeti","jetimenuShowOptions",true)) 
    458         { 
    459                         menuItem = new JMenuItem(I18N.gettext("main.main.jetimenu.Options")+"..."); 
    460                         I18N.setMnemonic("main.main.jetimenu.Options",menuItem); 
    461                         menuItem.addActionListener(new java.awt.event.ActionListener() 
    462                         { 
    463                                 public void actionPerformed(ActionEvent e) 
    464                                 { 
    465                                         new OptionsWindow(backend).setVisible(true); 
    466                                 } 
    467                         }); 
    468                     addMenuItem(menuItem); 
    469         } 
    470          
    471457        menuItem = new JMenuItem(); 
    472458                I18N.setTextAndMnemonic("main.main.jetimenu.About",menuItem,true); 
  • trunk/jabberit_messenger/java_source/src/nu/fw/jeti/util/FindAction.java

    r1014 r1064  
    4545         
    4646        public FindAction(){ 
    47                 //super("find", EditorUtilities.loadIcon("icons/Find16.gif")); 
    4847                super(I18N.gettext("main.popup.Find")); 
    4948                putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_F)); 
     
    6059                                JTextComponent text = (JTextComponent) o; 
    6160                                if(e.getModifiers() == 0 ) 
    62                                 {//find Next 
     61                                {  
     62                                        //find Next 
    6363                                        if (searchString==null) askSearchString(text); 
    6464                                        if (searchString!=null)search(text,text.getCaretPosition()); 
     
    8383                String fulltext = text.getText(); 
    8484 
    85 //              //      strip out the surplus \r characters 
    86 //              StringTokenizer tokenizer = new StringTokenizer(fulltext, "\r"); 
    87 //              StringBuffer buffer = new StringBuffer(); 
    88 //              while( tokenizer.hasMoreTokens() ){ 
    89 //                      buffer.append( tokenizer.nextToken() ); 
    90 //              } 
    91  
    9285                //get the substring based on the requested start position 
    9386                fulltext = ( fulltext ).substring(startPositionIn); 
     
    9689                // so long as we can find the text in the file, go ahead and highlight it 
    9790                // if we can't show the dialog 
    98                 if(fulltext.indexOf(searchString) > -1){ 
     91                if(fulltext.indexOf(searchString) > -1) 
     92                { 
    9993                        startPoint = (fulltext.indexOf(searchString) ) + startPositionIn; 
    100  
    10194                        endPoint = startPoint + searchStringLength; 
    10295                        text.requestFocus(); 
    10396                        text.setCaretPosition(startPoint); 
    104                 //move caret to endPoint - thus highlighting the selected text 
    10597                        text.moveCaretPosition(endPoint); 
    106                 //make the selection visible 
    107                         //text.getCaret().setSelectionVisible(true); 
    10898                } 
    109                 else if (startPositionIn!=0){ 
     99                else if (startPositionIn!=0) 
     100                { 
    110101                        if(JOptionPane.showConfirmDialog(text.getTopLevelAncestor(),MessageFormat.format(I18N.gettext("main.popup.{0}_not_found_until_the_end_of_this_file,_start_again_from_the_beginning?"),new Object[]{searchString})) == JOptionPane.OK_OPTION) 
    111102                        { 
  • trunk/jabberit_messenger/java_source/src/nu/fw/jeti/util/I18N.java

    r1014 r1064  
    11/* 
    2  * Creado el 30/06/2004 por Rodolfo Gonzalez Gonzalez <rodolfo@equinoxe.g-networks.net> 
     2 * @Author(s) - Alexndre Correia 
    33 * 
    4  * This class is a wrapper for easier i18n of Jeti. It uses the standard i18n  
    5  * mechanisms given by Java.  
     4 * This class is a wrapper for easier i18n of Jeti.  
     5 * It uses the standard i18n mechanisms given by Java.  
    66 *  
     7 * Created on - 30/06/2009 
    78 */ 
     9 
    810package nu.fw.jeti.util; 
    911 
    10 import java.io.*; 
    11 import java.io.BufferedReader; 
    12 import java.io.File; 
    13 import java.io.IOException; 
    14 import java.io.InputStreamReader; 
    15 import java.net.MalformedURLException; 
    16 import java.net.URL; 
    1712import java.util.*; 
    1813 
    1914import javax.swing.AbstractButton; 
    20 import javax.swing.JComponent; 
    2115import javax.swing.JLabel; 
    22 import javax.swing.UIManager; 
     16import nu.fw.jeti.languages.*; 
    2317 
    24 import nu.fw.jeti.backend.Start; 
    25 import nu.fw.jeti.backend.URLClassloader; 
    26  
    27 /** 
    28  * @author Rodolfo Gonzalez <rodolfo@equinoxe.g-networks.net> 
    29  */ 
    30 public class I18N 
     18public class I18N implements languages, languagesPlugins 
    3119{ 
    32         private static ResourceBundle jetiBundle; 
    33         private static Map pluginsBundle; 
    34         private Language[] languages; 
    35         private Map countries; 
    36  
    37         public I18N() 
     20        private static HashMap messagesLang; 
     21        private static HashMap messagesLangPlugins; 
     22         
     23        public static String getText(String type, String messageID) 
    3824        { 
    39                 countries = new HashMap(); 
    40                 if ( Start.applet || Start.webstart ) 
    41                 { 
    42                         try 
    43                         { 
    44                                 BufferedReader data = null; 
    45                                 InputStream is  = getClass().getResourceAsStream("/languages/list.txt"); 
    46                                 if(is==null)return;//no languages 
    47                                 data =new BufferedReader(new InputStreamReader(is)); 
    48                                 //data =new BufferedReader(new InputStreamReader(new URL(Start.programURL + "languages/list.txt").openStream())); 
    49                                 List locales = new LinkedList(); 
    50                                 while (true) 
    51                                 { 
    52                                         String file = data.readLine(); 
    53                                         if (file ==null) break;//end of stream 
    54                                         locales.add(new Locale(file)); 
    55                                 } 
    56                                 data.close(); 
    57                                 extractLanguages(locales); 
    58                                 extractCountries(); 
    59                         } 
    60                         catch (IOException ex){ex.printStackTrace();} 
    61                 } 
    62                 else 
    63                 { 
    64                         extractLanguages(searchTranslations()); 
    65                         extractCountries(); 
    66                 } 
    67         } 
    68  
    69         private List searchTranslations() 
    70         { 
    71                 String urlString = Start.path + "languages" + File.separator; 
    72                 File path = new File(urlString); 
    73                 File file[] = path.listFiles(); 
    74                 List locales = new LinkedList(); 
    75                 //locales.add(new Locale("en"));//english is available, but java always selects default locale before base locale 
    76                 if (file == null) return locales; 
    77                 for (int i = 0; i < file.length; i++) 
    78                 { 
    79                         Locale locale = getLocale(file[i].getName()); 
    80                         if (locale != null) locales.add(locale); 
    81                 } 
    82                 return locales; 
    83         } 
    84  
    85         private Locale getLocale(String filename) 
    86         { 
    87                 if (!filename.startsWith("jeti") || !filename.endsWith(".properties")) return null; 
    88                 int nlen = "jeti".length(); 
    89                 String language, country = ""; 
    90                 switch (filename.length() - nlen - 11) 
    91                 { 
    92                         case 6: 
    93                                 // E.g. name+"_en_US"+".properties" 
    94                                 if (filename.charAt(3 + nlen) != '_') return null; 
    95                                 country = filename.substring(nlen + 4, nlen + 6); 
    96                         // no break; here! 
    97                         case 3: 
    98                                 if (filename.charAt(nlen) != '_') return null; 
    99                                 language = filename.substring(nlen + 1, nlen + 3); 
    100                                 Locale locale = new Locale(language, country); 
    101                                 return locale; 
    102                 } 
    103                 return null; 
    104         } 
    105  
    106         private void extractLanguages(List availableLocales) 
    107         { 
    108                 Set lang = new HashSet(); 
    109                 for (Iterator i = availableLocales.iterator(); i.hasNext();) 
    110                 { 
    111                         Locale l = (Locale) i.next(); 
    112                         String language = l.getLanguage(); 
    113                         List langLocs = (List) countries.get(language); 
    114                         if (langLocs == null) 
    115                         { 
    116                                 langLocs = new ArrayList(); 
    117                                 countries.put(language, langLocs); 
    118                         } 
    119                         langLocs.add(new Country(l)); 
    120                         lang.add(new Language(l)); 
    121                 } 
    122                 //add default locale: 
    123                 Locale l = Locale.getDefault(); 
    124                 String language = l.getLanguage(); 
    125                 List langLocs = (List) countries.get(language); 
    126                 if (langLocs == null) 
    127                 { 
    128                         langLocs = new ArrayList(); 
    129                         countries.put(language, langLocs); 
    130                 } 
    131                 lang.add(new Language(l)); 
    132                 languages = (Language[]) lang.toArray(new Language[0]); 
    133         } 
    134  
    135         private void extractCountries() 
    136         { 
    137                 Locale[] allLocales = Locale.getAvailableLocales(); 
    138                 for (int i = 0; i < allLocales.length; i++) 
    139                 { 
    140                         String language = allLocales[i].getLanguage(); 
    141                         for (int j = 0; j < languages.length; j++) 
    142                         { 
    143                                 if (language.equals(languages[j].getLanguageCode())) 
    144                                 { 
    145                                         List langLocs = (List) countries.get(language); 
    146                                         Country country = new Country(allLocales[i]); 
    147                                         if (!langLocs.contains(country)) langLocs.add(country); 
    148                                         //System.out.println(allLocales[i].getDisplayCountry()); 
    149                                 } 
    150                         } 
    151                 } 
    152         } 
    153  
    154         /** 
    155          * @return The available languages 
    156          */ 
    157         public Language[] getLanguages() 
    158         { 
    159                 return languages; 
    160         } 
    161  
    162         /** 
    163          * @return The countries that are possible with the available languages 
    164          */ 
    165         public Map getCountries() 
    166         { 
    167                 return countries; 
    168         } 
    169  
    170          
    171         public static String getText(String type, String messageID) { 
    172                 ResourceBundle bundle = (ResourceBundle)pluginsBundle.get(type); 
    173                 if(bundle == null) bundle = jetiBundle; 
    174                 return getText(bundle,messageID); 
     25                return getText(messageID); 
    17526        } 
    17627         
    177         /** 
    178          * Gives back a translation of the input key without '&' (which is used for mnemonics) 
    179          *  
    180          * @param messageID is the English phrase used as key, following the GNU gettext style 
    181          * @param bundle is the name of the base resource bundle file 
    182          * @return result (or messageID in case of error) 
    183          */ 
    18428        public static String gettext(String messageID) 
    18529        { 
    186                 return getText(jetiBundle, messageID); 
     30                return getText(messageID); 
    18731        } 
    18832         
    189         private static String getText(ResourceBundle bundle, String messageID) 
     33        private static String getText( String messageID ) 
    19034        { 
    191                 if (messageID==null)return null; 
    192                 String translation = getTextWithAmp(bundle,messageID); 
     35                if ( messageID == null ) 
     36                        return null; 
     37                 
     38                String translation = getTextWithAmp(messageID); 
    19339                //remove & 
    19440                int i = translation.indexOf("&"); 
     
    19642                { 
    19743                        translation = translation.substring(0, i) + translation.substring(i + 1, translation.length()); 
    198                         //i = translation.indexOf("&",i); 
    19944                } 
     45 
    20046                return translation; 
    20147        } 
    20248 
    203         /** 
    204          * Gives back a translation of the input key 
    205          *  
    206          * @param messageID is the English phrase used as key, following the GNU gettext style 
    207          * @param bundle is the name of the base resource bundle file 
    208          * @return result (or messageID in case of error) 
    209          */ 
    21049        public static String getTextWithAmp(String messageID) 
    211         {//TODO change back to private when string prep is implemented 
    212                 return getTextWithAmp(jetiBundle, messageID); 
     50        {  
     51                return I18N.getText_WithAmp(messageID); 
    21352        } 
    21453         
    215         private static String getTextWithAmp(ResourceBundle bundle, String messageID) 
     54        private static String getText_WithAmp( String messageID ) 
    21655        { 
    217                 if (messageID==null)return null; 
    218                 if(bundle!=null) 
     56                String translation = (String)messagesLang.get(messageID); 
     57                 
     58                if( translation == null ) 
    21959                { 
    220                         try 
    221                         { 
    222                                 return (String) bundle.getObject(messageID); 
    223                         } catch (MissingResourceException e) 
    224                         { 
    225                                 System.out.println(messageID + " is not translated"); 
    226                         } 
     60                        int dotPos = messageID.lastIndexOf('.'); 
     61                         
     62                        if ( dotPos > 0 ) 
     63                                messageID = messageID.substring(dotPos+1); 
     64                         
     65                        return messageID.replace('_',' ');                       
    22766                } 
    228                 int dotPos = messageID.lastIndexOf('.'); 
    229                 if (dotPos>0) messageID = messageID.substring(dotPos+1); 
    230                 //return messageID.replaceAll("_"," ");  
    231                 return messageID.replace('_',' ');  
     67 
     68                return translation;  
    23269        } 
    23370 
    234         public static void setTextAndMnemonic(String messageID,JLabel label) { 
     71        public static void setTextAndMnemonic(String messageID,JLabel label) 
     72        { 
    23573        setTextAndMnemonic(messageID, label, false); 
    23674    } 
    23775 
    238         public static void setTextAndMnemonic(String messageID,JLabel label, boolean addDots) 
     76        public static void setTextAndMnemonic(String messageID, JLabel label, boolean addDots ) 
    23977        { 
    240                 String mnemonicText = getTextWithAmp(messageID); 
     78                String mnemonicText = I18N.getTextWithAmp(messageID); 
    24179                String translation=mnemonicText; 
    24280                int pos = mnemonicText.indexOf("&"); 
     81                 
    24382                if (pos > -1) 
    244                 { 
    24583                        translation = mnemonicText.substring(0, pos) + mnemonicText.substring(pos + 1, mnemonicText.length()); 
    246                 } 
    247         if (addDots) { 
     84         
     85                if (addDots) 
    24886            translation += "..."; 
    249         } 
     87                 
    25088                label.setText(translation); 
    251                 pos = getMnemonicPosition(mnemonicText); 
    252                 if(pos>-1) label.setDisplayedMnemonic(mnemonicText.charAt(pos)); 
    253                 if(pos>0) label.setDisplayedMnemonicIndex(pos-1); 
     89                pos = ( (int)mnemonicText.indexOf("&") >= 0 ) ? ((int)mnemonicText.indexOf("&")) + 1 : -1; 
     90                 
     91                if ( pos > -1) 
     92                        label.setDisplayedMnemonic(mnemonicText.charAt(pos)); 
     93                 
     94                if ( pos > 0 ) 
     95                        label.setDisplayedMnemonicIndex(pos-1); 
    25496        } 
    25597         
    25698        public static void setMnemonic(String messageID, JLabel label) 
    25799        { 
    258                 String translation = getTextWithAmp(messageID); 
    259                 int pos = getMnemonicPosition(translation); 
    260                 if(pos>-1)label.setDisplayedMnemonic(translation.charAt(pos)); 
    261                 if(pos>1)label.setDisplayedMnemonicIndex(pos-1); 
     100                String translation = I18N.getTextWithAmp(messageID); 
     101                int pos = ( (int)translation.indexOf("&") >= 0 ) ? ((int)translation.indexOf("&")) + 1 : -1; 
     102                 
     103                if ( pos > -1) 
     104                        label.setDisplayedMnemonic(translation.charAt(pos)); 
     105                 
     106                if ( pos > 1) 
     107                        label.setDisplayedMnemonicIndex(pos-1); 
    262108        } 
    263109         
    264110        public static void setMnemonic(String messageID, AbstractButton button) 
    265111        { 
    266                 String translation = getTextWithAmp(messageID); 
    267                 int pos = getMnemonicPosition(translation); 
    268                 if(pos>-1)button.setMnemonic(translation.charAt(pos)); 
    269                 if(pos>1)button.setDisplayedMnemonicIndex(pos-1); 
     112                String translation = I18N.getTextWithAmp(messageID); 
     113                int pos = ( (int)translation.indexOf("&") >= 0 ) ? ((int)translation.indexOf("&")) + 1 : -1; 
     114                 
     115                if ( pos >- 1)  
     116                        button.setMnemonic(translation.charAt(pos)); 
     117                if ( pos > 1) 
     118                        button.setDisplayedMnemonicIndex(pos-1); 
    270119        } 
    271120 
    272         /** 
    273          * @param messageID is the English phrase used as key, following the 
    274      *              GNU gettext style 
    275          * @param bundle is the name of the base resource bundle file 
    276          * @param button The button to set the mnemonic on 
    277          */ 
    278121        public static void setTextAndMnemonic(String messageID,AbstractButton button) 
    279122        { 
     
    281124    } 
    282125 
    283         /** 
    284          * @param messageID is the English phrase used as key, following the 
    285      *              GNU gettext style 
    286          * @param bundle is the name of the base resource bundle file 
    287          * @param button The button to set the mnemonic on 
    288          * @param addDots If true add '...' to the translated text 
    289          */ 
    290         public static void setTextAndMnemonic(String messageID,AbstractButton button, 
    291                                           boolean addDots) 
     126        public static void setTextAndMnemonic(String messageID,AbstractButton button, boolean addDots) 
    292127        { 
    293128                String mnemonicText = getTextWithAmp(messageID); 
     129                String translation=mnemonicText; 
    294130                 
    295                 String translation=mnemonicText; 
    296131                int pos = mnemonicText.indexOf("&"); 
     132                 
    297133                if (pos > -1) 
    298                 { 
    299134                        translation = mnemonicText.substring(0, pos) + mnemonicText.substring(pos + 1, mnemonicText.length()); 
    300                 } 
    301         if (addDots) { 
     135         
     136                if (addDots) 
    302137            translation += "..."; 
    303         } 
    304                 button.setText(translation); 
    305                 pos = getMnemonicPosition(mnemonicText); 
    306                 if(pos>-1)button.setMnemonic(mnemonicText.charAt(pos)); 
    307                 if(pos>0) button.setDisplayedMnemonicIndex(pos-1); 
     138                 
     139        button.setText(translation); 
     140         
     141                pos = ( (int)mnemonicText.indexOf("&") >= 0 ) ? ((int)mnemonicText.indexOf("&")) + 1 : -1; 
     142 
     143                if( pos > -1) 
     144                        button.setMnemonic(mnemonicText.charAt(pos)); 
     145 
     146                if( pos > 0 ) 
     147                        button.setDisplayedMnemonicIndex(pos-1); 
    308148                 
    309149        } 
    310150 
    311         private static int getMnemonicPosition(String translation) 
     151        private static void loadLanguages(Locale myLocale) 
    312152        { 
    313                 int index = translation.indexOf("&"); 
    314                 if (index >= 0) return index+1; 
    315                 return -1; 
     153                if ( myLocale.toString().equals("pt_BR")) 
     154                { 
     155                        for( int i = 0; i < language_pt_BR.length; i++ ) 
     156                                messagesLang.put(language_pt_BR[i][0].toString(), language_pt_BR[i][1].toString()); 
     157                         
     158                        for( int i = 0 ; i < languagePlugins_pt_BR.length; i++) 
     159                                messagesLangPlugins.put(languagePlugins_pt_BR[i][0].toString(), languagePlugins_pt_BR[i][1].toString()); 
     160                } 
    316161        } 
     162         
     163        public static void init(String myLanguage, String myCountry) 
     164        { 
     165                messagesLang = new HashMap(); 
     166                messagesLangPlugins = new HashMap(); 
    317167 
    318         static public void init() 
    319         { 
    320                 ClassLoader classLoader=null; 
    321         if (!Start.applet && !Start.webstart) { 
    322             try { 
    323                                 URL url = new URL(Start.programURL, "languages/"); 
    324                 classLoader = new URLClassloader( 
    325                     new URL[] { url}, I18N.class.getClassLoader()); 
    326             } catch (MalformedURLException e) { 
    327                                 e.printStackTrace(); 
    328                         } 
    329                 } else classLoader = I18N.class.getClassLoader(); 
    330                 //               see if the user has some preferences 
    331                 String myLanguage = Preferences.getString("jeti", "language", ""); 
    332                 String myCountry = Preferences.getString("jeti", "country", ""); 
    333                 Locale myLocale=null; 
    334         if (myLanguage != "") { 
    335             myLocale = new Locale(myLanguage, myCountry); 
    336         } else { 
    337             myLocale = Locale.getDefault(); 
    338         } 
    339         jetiBundle = loadLanguage("jeti",classLoader,myLocale); 
    340         if(jetiBundle==null || jetiBundle.getLocale().getLanguage().equals("")) 
    341         { 
    342                 // Make it fall back to English, this way we always get at least 
    343                 // the english texts (which contains the menu mnemonic markings) 
    344                 myLocale= new Locale(Locale.ENGLISH.getLanguage(),myCountry); 
    345                 System.out.println("lang not found, default: " + myLocale); 
    346                 jetiBundle = loadLanguage("jeti",classLoader,myLocale); 
    347         } 
    348         pluginsBundle = new HashMap(); 
    349         pluginsBundle.put("drawing",loadLanguage("drawing",classLoader,myLocale)); 
    350         JComponent.setDefaultLocale(myLocale); 
    351                     
    352         //loadLanguage(classLoader, myLocale); 
    353                 UIManager.put("OptionPane.okButtonText", gettext("OK")); 
    354                 UIManager.put("OptionPane.cancelButtonText", gettext("Cancel")); 
     168                // Preferences 
     169                Locale myLocale   = null; 
     170 
     171                if( myLanguage != "" ) 
     172                        myLocale = new Locale(myLanguage, myCountry); 
     173                else 
     174                        myLocale = new Locale("en", "US"); 
     175 
     176                System.out.println("Valor de myLocale : " + myLocale); 
    355177                 
    356         } 
    357  
    358         private static ResourceBundle loadLanguage(String type, ClassLoader classLoader, Locale myLocale) 
    359         { 
    360                 try { 
    361             return ResourceBundle.getBundle("languages/" +type, myLocale); 
    362         } catch (MissingResourceException e) { 
    363             try { 
    364                 return ResourceBundle.getBundle(type, 
    365                                                       myLocale, classLoader); 
    366             } catch (MissingResourceException e2) { 
    367                 System.out.println(e2.getMessage()); 
    368                 return null; 
    369             } 
    370         } 
    371         } 
    372  
    373         public static class Country 
    374         { 
    375                 private String country; 
    376                 private String countryCode; 
    377  
    378                 public Country(Locale locale) 
    379                 { 
    380                         country = locale.getDisplayCountry(); 
    381                         if (country.equals("")) country = gettext("main.options.standard.Other"); 
    382                         countryCode = locale.getCountry(); 
    383                 } 
    384  
    385                 public String getCountryCode() 
    386                 { 
    387                         return countryCode; 
    388                 } 
    389  
    390                 public String toString() 
    391                 { 
    392                         return country; 
    393                 } 
    394  
    395         } 
    396  
    397         public static class Language 
    398         { 
    399                 private String language; 
    400                 private String languageCode; 
    401  
    402                 public Language(Locale locale) 
    403                 { 
    404                         language = locale.getDisplayLanguage(); 
    405                         languageCode = locale.getLanguage(); 
    406                 } 
    407  
    408                 public String getLanguageCode() 
    409                 { 
    410                         return languageCode; 
    411                 } 
    412  
    413                 public String toString() 
    414                 { 
    415                         return language; 
    416                 } 
    417                  
    418                 public boolean equals(Object obj) 
    419                 { 
    420                         return language.equals(((Language)obj).language); 
    421                 } 
    422                  
    423                 public int hashCode() 
    424                 { 
    425                         return language.hashCode(); 
    426                 } 
    427                  
    428                  
     178                I18N.loadLanguages(myLocale); 
    429179        } 
    430180} 
    431  
    432181 
    433182/* 
  • trunk/jabberit_messenger/java_source/src/nu/fw/jeti/util/Preferences.java

    r1014 r1064  
    6565        { 
    6666                Preferences.backend = backend; 
    67  
    6867                InputStream data = null; 
    6968 
     
    7776                        addPreferences(parser, data, defaults); 
    7877                } 
    79                 catch(IOException ex) 
    80                 { 
    81                         // Do Nothing 
    82                         //javax.swing.JOptionPane.showMessageDialog(null,  
    83                         //              "Comentar esta linha em Preferences.java\n" + "\nERRO : \n" + ex.getMessage() + "\n" + ex + "\n" ); 
    84                 } 
     78                catch(IOException ex){} 
    8579 
    8680                // Initialize presence messages if none have been specified 
     
    9185        } 
    9286 
    93     private void addPreferences(SAXParser parser, InputStream data,Map store) { 
    94         try { 
     87    private void addPreferences(SAXParser parser, InputStream data,Map store) 
     88    { 
     89        try 
     90        { 
    9591            parser.parse(data,new PreferencesHandler(store)); 
    96         } catch (SAXException ex) { 
     92        } 
     93        catch (SAXException ex) 
     94        { 
    9795            ex.printStackTrace(); 
    98         } catch (IOException ex) { 
     96        } 
     97        catch (IOException ex) 
     98        { 
    9999            ex.printStackTrace(); 
    100100        } 
     
    109109                 
    110110                List tempList = new ArrayList(10); 
    111                 tempList.add("Disponível"); 
    112                 tempList.add("Livre p/ Chat"); 
    113                 mapMessages.put("chat", tempList); 
    114                 mapMessages.put("available", tempList); 
    115                 tempList = new ArrayList(10); 
    116                 tempList.add("Em reunião"); 
    117                 tempList.add("Ocupado"); 
    118                 tempList.add("Trabalhando"); 
    119                 mapMessages.put("dnd", tempList); 
    120                 tempList = new ArrayList(10); 
    121                 tempList.add("No telefone"); 
    122                 tempList.add("Volto Logo"); 
    123                 mapMessages.put("away", tempList); 
    124                 tempList = new ArrayList(10); 
    125                 tempList.add("Férias"); 
    126                 tempList.add("Em casa"); 
    127                 tempList.add("Ausente"); 
    128                 mapMessages.put("xa", tempList); 
     111                        tempList.add("Disponível"); 
     112                        tempList.add("Livre p/ Chat"); 
     113                        mapMessages.put("chat", tempList); 
     114                        mapMessages.put("available", tempList); 
     115                        tempList = new ArrayList(10); 
     116                        tempList.add("Em reunião"); 
     117                        tempList.add("Ocupado"); 
     118                        tempList.add("Trabalhando"); 
     119                        mapMessages.put("dnd", tempList); 
     120                        tempList = new ArrayList(10); 
     121                        tempList.add("No telefone"); 
     122                        tempList.add("Volto Logo"); 
     123                        mapMessages.put("away", tempList); 
     124                        tempList = new ArrayList(10); 
     125                        tempList.add("Férias"); 
     126                        tempList.add("Em casa"); 
     127                        tempList.add("Ausente"); 
     128                        mapMessages.put("xa", tempList); 
     129                 
    129130                return mapMessages; 
    130131        } 
Note: See TracChangeset for help on using the changeset viewer.