OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73 Rev 177
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.sql;
14
 package org.openconcerto.sql;
15
 
15
 
16
import org.openconcerto.sql.preferences.UserProps;
16
import org.openconcerto.sql.preferences.UserProps;
-
 
17
import org.openconcerto.utils.i18n.TMPool;
17
 
18
 
18
import java.util.Locale;
19
import java.util.Locale;
19
 
20
 
20
/**
21
/**
21
 * Translation manager, listen to locale of {@link UserProps} and apply it to lower translation
22
 * Translation manager, listen to locale of {@link UserProps} and apply it to lower translation
22
 * managers.
23
 * managers.
23
 * 
24
 * 
24
 * @author Sylvain
25
 * @author Sylvain
25
 */
26
 */
26
public class TM extends UserPropsTM {
27
public class TM extends org.openconcerto.utils.i18n.TM {
27
 
28
 
28
    static private TM INSTANCE;
29
    private static final TMPool<TM> POOL = new TMPool<TM>(TM::new);
29
 
30
 
30
    // to be called as soon as UserProps has the correct Locale to initialize other translation
-
 
31
    // managers
-
 
32
    static public TM getInstance() {
31
    static public TM getInstance() {
33
        if (INSTANCE == null)
32
        return getInstance(getDefaultLocale());
-
 
33
    }
-
 
34
 
34
            INSTANCE = new TM();
35
    static public TM getInstance(final Locale l) {
35
        return INSTANCE;
36
        return POOL.get(l);
-
 
37
    }
-
 
38
 
-
 
39
    static public String tr(final Locale l, final String key, final Object... args) {
-
 
40
        return getInstance(l).translate(key, args);
36
    }
41
    }
37
 
42
 
38
    // useful for static import
43
    // useful for static import
39
    static public TM getTM() {
44
    static public TM getTM() {
40
        return getInstance();
45
        return getInstance();
Line 42... Line 47...
42
 
47
 
43
    static public final String tr(final String key, final Object... args) {
48
    static public final String tr(final String key, final Object... args) {
44
        return getInstance().translate(key, args);
49
        return getInstance().translate(key, args);
45
    }
50
    }
46
 
51
 
47
    private TM() {
52
    private TM(final Locale l) {
48
    }
-
 
49
 
-
 
50
    @Override
53
        super(l);
51
    protected void updateLocale(final UserProps userProps) {
-
 
52
        final Locale locale = userProps.getLocale();
-
 
53
        this.setLocale(locale);
-
 
54
        org.openconcerto.utils.i18n.TM.getInstance().setLocale(locale);
-
 
55
        org.openconcerto.ui.TM.getInstance().setLocale(locale);
-
 
56
    }
54
    }
57
}
55
}