/
Localizable.java
226 lines (193 loc) · 7.51 KB
/
Localizable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// Import List - http://my-flow.github.io/importlist/
// Copyright (C) 2011-2015 Florian J. Breunig
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package com.moneydance.modules.features.importlist.util;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.apache.commons.lang3.text.WordUtils;
/**
* This i18n class provides language-dependent strings such as labels and
* messages.
*
* @author Florian J. Breunig
*/
public final class Localizable {
private final ResourceBundle resourceBundle;
Localizable(final String localizableResource, final Locale locale) {
this.resourceBundle = ResourceBundle.getBundle(
localizableResource,
locale);
}
/**
* @return The title of the dialog that is displayed to choose the base
* directory.
*/
public String getDirectoryChooserTitle() {
return this.resourceBundle.getString("directory_chooser_title");
}
/**
* @return Header of the "name" column.
*/
public String getHeaderValueName() {
final String headerValueName =
this.resourceBundle.getString("header_value_name");
return Helper.INSTANCE.getSettings().getIndentationPrefix()
+ headerValueName;
}
/**
* @return Header of the "modified" column.
*/
public String getHeaderValueModified() {
final String headerValueModified =
this.resourceBundle.getString("header_value_modified");
return String.format("%s%s",
Helper.INSTANCE.getSettings().getIndentationPrefix(),
headerValueModified);
}
/**
* @return Header of the "import" column.
*/
public String getHeaderValueImport() {
final String headerValueImport =
this.resourceBundle.getString("header_value_import");
return String.format("%s%s",
Helper.INSTANCE.getSettings().getIndentationPrefix(),
headerValueImport);
}
/**
* @return Header of the "delete" column.
*/
public String getHeaderValueDelete() {
final String headerValueDelete =
this.resourceBundle.getString("header_value_delete");
return String.format("%s%s",
Helper.INSTANCE.getSettings().getIndentationPrefix(),
headerValueDelete);
}
/**
* @return Label of the "import" button.
*/
public String getLabelImportOneButton() {
return this.resourceBundle.getString("label_import_one_button");
}
/**
* @return Label of the "import all" button.
*/
public String getLabelImportAllButton() {
return this.resourceBundle.getString("label_import_all_button");
}
/**
* @return Label of the "delete" button.
*/
public String getLabelDeleteOneButton() {
return this.resourceBundle.getString("label_delete_one_button");
}
/**
* @return Label of the "delete all" button.
*/
public String getLabelDeleteAllButton() {
return this.resourceBundle.getString("label_delete_all_button");
}
/**
* @param baseDirectory The base directory which could not be opened.
* @return Error message to be displayed if the base directory could not be
* opened.
*/
public String getErrorMessageBaseDirectory(final String baseDirectory) {
final String templateString = this.resourceBundle.getString(
"error_message_base_directory");
Map<String, String> valuesMap =
new ConcurrentHashMap<String, String>(1);
valuesMap.put("import.dir", getMarkupFilename(baseDirectory));
StrSubstitutor sub = new StrSubstitutor(valuesMap);
return sub.replace(templateString);
}
/**
* @param filename The name of the file that is to be deleted.
* @return Confirmation message to be displayed before a file will be
* deleted.
*/
public String getConfirmationMessageDeleteOneFile(final String filename) {
final String templateString = this.resourceBundle.getString(
"confirmation_message_delete_one_file");
Map<String, String> valuesMap =
new ConcurrentHashMap<String, String>(1);
valuesMap.put("filename", getMarkupFilename(filename));
StrSubstitutor sub = new StrSubstitutor(valuesMap);
return sub.replace(templateString);
}
/**
* @param size The number of all files that are to be deleted.
* @return Confirmation message to be displayed before all files will be
* deleted.
*/
public String getConfirmationMessageDeleteAllFiles(final int size) {
final String templateString = this.resourceBundle.getString(
"confirmation_message_delete_all_files");
Map<String, String> valuesMap =
new ConcurrentHashMap<String, String>(1);
valuesMap.put("no.files", String.valueOf(size));
StrSubstitutor sub = new StrSubstitutor(valuesMap);
return sub.replace(templateString);
}
/**
* @param filename The name of the file that cannot be deleted.
* @return Error message to be displayed if a file cannot be deleted.
*/
public String getErrorMessageDeleteFile(final String filename) {
final String templateString = this.resourceBundle.getString(
"error_message_delete_file");
Map<String, String> valuesMap =
new ConcurrentHashMap<String, String>(1);
valuesMap.put("filename", getMarkupFilename(filename));
StrSubstitutor sub = new StrSubstitutor(valuesMap);
return sub.replace(templateString);
}
/**
* @return Delete button in confirmation message.
*/
public String getOptionDeleteFile() {
return this.resourceBundle.getString("option_delete_file");
}
/**
* @return Cancel button in confirmation message.
*/
public String getOptionCancel() {
return this.resourceBundle.getString("option_cancel");
}
/**
* @param baseDirectory The base directory which does not contain any files
* to display.
* @return Message to display if the list of files is empty.
*/
public String getEmptyMessage(final String baseDirectory) {
final String templateString = this.resourceBundle.getString(
"empty_message");
Map<String, String> valuesMap =
new ConcurrentHashMap<String, String>(1);
valuesMap.put("import.dir", baseDirectory);
StrSubstitutor sub = new StrSubstitutor(valuesMap);
return sub.replace(templateString);
}
private static String getMarkupFilename(final String filename) {
return WordUtils.wrap(
filename,
Helper.INSTANCE.getSettings().getMessageFilenameLineMaxLength(),
"<br>", /*wrapLongWords*/ true);
}
}