1 | package com.jsql.view.swing.util; | |
2 | ||
3 | import com.jsql.util.I18nUtil; | |
4 | ||
5 | import java.util.*; | |
6 | ||
7 | public class I18nViewUtil { | |
8 | ||
9 | /** | |
10 | * A list of graphical components for each i18n keys in the main properties | |
11 | */ | |
12 | private static final Map<String, List<Object>> componentsLocalized = new HashMap<>(); | |
13 | | |
14 | // Initialize the list of graphical components | |
15 | static { | |
16 | for (String keyI18n: I18nUtil.getLocaleRoot().keySet()) { | |
17 | I18nViewUtil.componentsLocalized.put(keyI18n, new ArrayList<>()); | |
18 | } | |
19 | } | |
20 | ||
21 | private I18nViewUtil() { | |
22 | // Utility class | |
23 | } | |
24 | | |
25 | /** | |
26 | * Return the i18n keys of components whose text is replaced | |
27 | * when the translation changes. | |
28 | * @return a set of key names of a i18n key in the properties | |
29 | */ | |
30 | public static Set<String> keys() { | |
31 |
1
1. keys : replaced return value with Collections.emptySet for com/jsql/view/swing/util/I18nViewUtil::keys → NO_COVERAGE |
return I18nViewUtil.componentsLocalized.keySet(); |
32 | } | |
33 | | |
34 | /** | |
35 | * Get a list of graphical components whose text corresponds | |
36 | * to the i18n key in the properties. | |
37 | * @param key name of a i18n key in the properties | |
38 | * @return a list of graphical components | |
39 | */ | |
40 | public static List<Object> componentsByKey(String key) { | |
41 |
1
1. componentsByKey : replaced return value with Collections.emptyList for com/jsql/view/swing/util/I18nViewUtil::componentsByKey → NO_COVERAGE |
return I18nViewUtil.componentsLocalized.get(key); |
42 | } | |
43 | | |
44 | /** | |
45 | * Add a graphical component to those whose text must be changed when | |
46 | * the language changes. | |
47 | * @param key name of a i18n key in the properties | |
48 | * @param component graphical component which will receive the translated text | |
49 | */ | |
50 | public static void addComponentForKey(String key, Object component) { | |
51 | I18nViewUtil.componentsLocalized.get(key).add(component); | |
52 | } | |
53 | | |
54 | /** | |
55 | * Return the text corresponding to a i18n key in the properties. | |
56 | * @param key a i18n key in the properties | |
57 | * @return text corresponding to the key | |
58 | */ | |
59 | public static String valueByKey(String key) { | |
60 | | |
61 | String result; | |
62 | | |
63 |
1
1. valueByKey : negated conditional → NO_COVERAGE |
if (I18nUtil.isAsian(I18nUtil.getLocaleDefault())) { |
64 | result = String.format( | |
65 | "<html><span style=\"font-family:'%s'\">%s</span></html>", | |
66 | UiUtil.FONT_NAME_MONO_ASIAN, | |
67 | I18nUtil.valueByKey(key) | |
68 | ); | |
69 | } else { | |
70 | result = I18nUtil.valueByKey(key); | |
71 | } | |
72 | | |
73 |
1
1. valueByKey : replaced return value with "" for com/jsql/view/swing/util/I18nViewUtil::valueByKey → NO_COVERAGE |
return result; |
74 | } | |
75 | | |
76 | public static String valueByKey(String key, Locale newLocale) { | |
77 |
1
1. valueByKey : negated conditional → NO_COVERAGE |
if (I18nUtil.isAsian(newLocale)) { |
78 |
1
1. valueByKey : replaced return value with "" for com/jsql/view/swing/util/I18nViewUtil::valueByKey → NO_COVERAGE |
return I18nViewUtil.valueByKey(key); |
79 | } else { | |
80 |
1
1. valueByKey : replaced return value with "" for com/jsql/view/swing/util/I18nViewUtil::valueByKey → NO_COVERAGE |
return I18nUtil.valueByKey(key); |
81 | } | |
82 | } | |
83 | } | |
Mutations | ||
31 |
1.1 |
|
41 |
1.1 |
|
63 |
1.1 |
|
73 |
1.1 |
|
77 |
1.1 |
|
78 |
1.1 |
|
80 |
1.1 |