Subversion Repositories linkit

[/] [trunk/] [fileUploadApp/] [src/] [main/] [flex/] [com/] [flashdev/] [utils/] [Localizator.as] - Blame information for rev 1

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 sbahloul
package com.flashdev.utils {
2
 
3
    import mx.resources.ResourceBundle;
4
    import flash.events.Event;
5
 
6
        public class Localizator {
7
 
8
        public static const FRENCH:int = 1;
9
        public static const ENGLISH:int = 2;
10
        protected static var myLocalizator:Localizator;
11
 
12
        [Bindable]
13
        private var cur:ResourceBundle;
14
 
15
        [ResourceBundle("en_US")]
16
        private var rb_eng:ResourceBundle;
17
        [ResourceBundle("fr_FR")]
18
        private var rb_fra:ResourceBundle;
19
 
20
        private var _lang:int;
21
 
22
        public function Localizator (language:int=ENGLISH){
23
 
24
            selectLang( language );
25
 
26
        }
27
 
28
        private function selectLang( language:int ) : void{
29
 
30
            this._lang = language;
31
            switch ( language ) {
32
            case ENGLISH :
33
 
34
                this.cur = rb_eng;
35
                break;
36
 
37
            case FRENCH :
38
 
39
                this.cur = rb_fra;
40
                break;
41
 
42
            default :
43
 
44
                this._lang = Localizator.ENGLISH;
45
                this.cur = rb_eng;
46
                break;
47
 
48
            }
49
 
50
        }
51
 
52
                /*
53
        public static function getInstance (language:int) : Localizator {
54
 
55
            if( Localizator.myLocalizator == null ){
56
 
57
                Localizator.myLocalizator = new Localizator(language);
58
 
59
            }
60
            return Localizator.myLocalizator;
61
 
62
        }
63
                */
64
 
65
        [Bindable(event="langChange")]
66
        public function getText( key:String ) : String {
67
 
68
            return this.cur.getString( key );
69
 
70
        }
71
 
72
                public static function getInstance() : Localizator {
73
                        if (Localizator.myLocalizator == null) {
74
                                Localizator.myLocalizator = new Localizator(ENGLISH);
75
                        }
76
                        return Localizator.myLocalizator;
77
                }
78
 
79
        /**
80
        * Shortcut for getText
81
        */
82
        [Bindable(event="langChange")]
83
        public function gT( key:String ) : String {
84
 
85
            return this.getText(key);
86
 
87
        }
88
 
89
        public function get lang () : int {
90
 
91
            return this._lang;
92
 
93
        }
94
 
95
        public function set lang ( language:int ) : void {
96
 
97
            if( this._lang != language ){
98
 
99
                this.selectLang( language );
100
                var e:Event = new Event("langChange");
101
                this.dispatchEvent(e);
102
 
103
            }
104
 
105
        }
106
 
107
    }
108
 
109
}