~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/system/language/LanguageManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Created on 09-ene-2006
3
 
 *
4
 
 * TODO To change the template for this generated file go to
5
 
 * Window - Preferences - Java - Code Style - Code Templates
6
 
 */
7
 
package org.herac.tuxguitar.gui.system.language;
8
 
 
9
 
import java.io.File;
10
 
import java.io.FilenameFilter;
11
 
import java.util.Locale;
12
 
import java.util.ResourceBundle;
13
 
 
14
 
import org.herac.tuxguitar.gui.util.TuxGuitarFileUtils;
15
 
 
16
 
/**
17
 
 * @author julian
18
 
 * 
19
 
 */
20
 
public class LanguageManager {  
21
 
 
22
 
    private ResourceBundle resources;
23
 
    private String[] languages;
24
 
    
25
 
    public LanguageManager() {
26
 
        this.loadLanguages();
27
 
    }
28
 
    
29
 
    public void setLanguage(String lang) { 
30
 
        try {
31
 
                if(lang == null || lang.length() == 0){
32
 
                        this.resources = ResourceBundle.getBundle("lang.messages");
33
 
                }else{
34
 
                        this.resources = ResourceBundle.getBundle("lang.messages", new Locale(lang));
35
 
                }               
36
 
        } catch (Exception e) {
37
 
                e.printStackTrace();            
38
 
        }
39
 
    }
40
 
    
41
 
    
42
 
    public String getProperty(String key) {
43
 
        String property = null;
44
 
        try {
45
 
                property = resources.getString(key);
46
 
        }catch(Exception e){
47
 
                property = key;
48
 
                System.out.println(property);
49
 
        }       
50
 
        return property;
51
 
    }    
52
 
        
53
 
    public String getLanguage() {
54
 
        if(this.resources != null){
55
 
                return this.resources.getLocale().getLanguage();
56
 
        }
57
 
        return null;
58
 
    }
59
 
    
60
 
    
61
 
    public String[] getLanguages() {
62
 
        return this.languages;
63
 
    }
64
 
    
65
 
    /**
66
 
     * Load language files from lang folder
67
 
     *
68
 
     */
69
 
    private void loadLanguages(){
70
 
        // we need .properties files only
71
 
        final FilenameFilter filter = new FilenameFilter() {
72
 
            public boolean accept(File dir, String name) {
73
 
                return (name.indexOf("messages_") != -1 && name.indexOf(".properties") != -1);
74
 
            }
75
 
        };          
76
 
        // get the files
77
 
        String langFolderPath = TuxGuitarFileUtils.LANGUAGE_PREFIX;
78
 
        if(langFolderPath != null){             
79
 
                File langFolder = new File(langFolderPath);
80
 
                if(langFolder != null){
81
 
                        String[] fileNames = langFolder.list(filter);
82
 
                        this.languages = new String[fileNames.length];        
83
 
                        // now iterate over them
84
 
                        for(int i = 0;i < fileNames.length;i++){                
85
 
                                if (fileNames[i].indexOf("messages_") != -1){
86
 
                                        this.languages[i] = fileNames[i].substring(9,11);
87
 
                                }                       
88
 
                        }
89
 
                }
90
 
        }
91
 
    }    
92
 
 
93
 
}
 
 
b'\\ No newline at end of file'