1 |
iliev |
596 |
/* |
2 |
|
|
* jlscp - a java LinuxSampler control protocol API |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005 Grigor Kirilov Iliev |
5 |
|
|
* |
6 |
|
|
* This file is part of jlscp. |
7 |
|
|
* |
8 |
|
|
* jlscp is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License version 2 |
10 |
|
|
* as published by the Free Software Foundation. |
11 |
|
|
* |
12 |
|
|
* jlscp is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with jlscp; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
|
|
* MA 02111-1307 USA |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
package org.linuxsampler.lscp; |
24 |
|
|
|
25 |
|
|
import java.text.MessageFormat; |
26 |
|
|
import java.util.Locale; |
27 |
|
|
import java.util.ResourceBundle; |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
/** |
31 |
|
|
* |
32 |
|
|
* @author Grigor Iliev |
33 |
|
|
*/ |
34 |
|
|
class LscpI18n { |
35 |
|
|
private static Locale currentLocale = null; |
36 |
|
|
private static Locale[] locales = { new Locale("en", "US"), new Locale("bg", "BG") }; |
37 |
|
|
|
38 |
|
|
private static ResourceBundle errors = null; |
39 |
|
|
|
40 |
|
|
public static Locale[] |
41 |
|
|
getAvailableLocales() { return locales; } |
42 |
|
|
|
43 |
|
|
public static Locale |
44 |
|
|
getCurrentLocale() { |
45 |
|
|
if(currentLocale == null) setLocale("en", "US"); |
46 |
|
|
return currentLocale; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
public static String |
50 |
|
|
getLogMsg(String s) { |
51 |
|
|
// in case that currentLocale is null |
52 |
|
|
getCurrentLocale(); |
53 |
|
|
|
54 |
|
|
return errors.getString(s); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
public static String |
58 |
|
|
getLogMsg(String pattern, Object argument) { |
59 |
|
|
Object[] args = { argument }; |
60 |
|
|
return getLogMsg(pattern, args); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
public static String |
64 |
|
|
getLogMsg(String pattern, Object[] arguments) { |
65 |
|
|
// in case that currentLocale is null |
66 |
|
|
getCurrentLocale(); |
67 |
|
|
|
68 |
|
|
MessageFormat mf = new MessageFormat(""); |
69 |
|
|
mf.setLocale(getCurrentLocale()); |
70 |
|
|
mf.applyPattern(getLogMsg(pattern)); |
71 |
|
|
return mf.format(arguments); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
public static void |
75 |
|
|
setLocale(String language, String country) { |
76 |
|
|
currentLocale = new Locale(language, country); |
77 |
|
|
|
78 |
|
|
errors = ResourceBundle.getBundle ( |
79 |
|
|
"org.linuxsampler.lscp.langprops.LogsBundle", |
80 |
|
|
currentLocale |
81 |
|
|
); |
82 |
|
|
} |
83 |
|
|
} |