I18nDictionary.java
24.4 KB
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.jcr.JcrUtil
* com.google.gson.Gson
* com.google.gson.GsonBuilder
* com.google.gson.JsonElement
* com.google.gson.JsonObject
* com.google.gson.JsonParser
* javax.jcr.Binary
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Value
* javax.jcr.ValueFactory
* javax.jcr.Workspace
* javax.jcr.query.Query
* javax.jcr.query.QueryManager
* javax.jcr.query.QueryResult
* org.apache.commons.lang3.RandomStringUtils
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.resource.PersistenceException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.jcr.resource.JcrResourceUtil
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.wcm.translation.impl;
import com.adobe.cq.wcm.translation.impl.TranslationUtils;
import com.day.cq.commons.jcr.JcrUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.jcr.Workspace;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.jcr.resource.JcrResourceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class I18nDictionary {
private static final Logger log = LoggerFactory.getLogger(I18nDictionary.class);
private static final int DICT_NAME_RANDOM_STRING_LENGTH = 15;
private static final String I18N_JCR_ENTRY_PREFIX = "entry_";
private static String COMMENT_START_IDENTIFIER = " ((";
private static String COMMENT_END_IDENTIFIER = "))";
public static Resource fetchI18nDictionaryResource(Resource parent, String baseName, String language) throws UnsupportedEncodingException {
log.trace("In function: fetchI18nDictionaryResource with Language:{} BaseName:{}", (Object)language, (Object)baseName);
Iterable childList = parent.getChildren();
for (Resource child : childList) {
if (!I18nDictionary.isI18nDictionary(child) || !StringUtils.equalsIgnoreCase((CharSequence)TranslationUtils.getAttribute(child, "jcr:language", String.class), (CharSequence)language) || !StringUtils.equals((CharSequence)TranslationUtils.getAttribute(child, "sling:basename", String.class), (CharSequence)baseName)) continue;
log.trace("I18n dictionary(Lang:{}) found at {}", (Object)language, (Object)child.getPath());
return child;
}
log.trace("I18n dictionary(Lang:{}) not found at {}", (Object)language, (Object)parent.getPath());
return null;
}
public static boolean isI18nDictionary(Resource resource) {
String[] mixinTypes = TranslationUtils.getAttribute(resource, "jcr:mixinTypes", String[].class);
String language = TranslationUtils.getAttribute(resource, "jcr:language", String.class);
return mixinTypes != null && language != null && Arrays.asList(mixinTypes).contains("mix:language");
}
public static Resource getOrCreateI18nDictionaryResource(ResourceResolver resourceResolver, String parentPath, String language, String baseName, boolean isJson) {
Resource resource;
try {
Resource parentResource = ResourceUtil.getOrCreateResource((ResourceResolver)resourceResolver, (String)parentPath, (String)"sling:Folder", (String)"sling:Folder", (boolean)false);
resource = I18nDictionary.fetchI18nDictionaryResource(parentResource, baseName, language);
if (resource == null) {
resource = I18nDictionary.createI18nDictionaryResource(parentResource, language, baseName, isJson);
}
}
catch (Exception e) {
resource = null;
}
return resource;
}
private static Resource createI18nDictionaryResource(Resource parent, String language, String baseName, boolean isJson) throws UnsupportedEncodingException, RepositoryException, PersistenceException {
Node i18nNode;
log.trace("In function: createI18nDictionaryResource");
log.trace("Create I18n dictionary at {}/{}", (Object)parent.getPath(), (Object)language);
ResourceResolver resourceResolver = parent.getResourceResolver();
if (isJson) {
String dictionaryName = language + ".json";
while (parent.getChild(dictionaryName) != null) {
dictionaryName = language + "_" + RandomStringUtils.randomAlphanumeric((int)15) + ".json";
}
log.trace("Creating JSON based I18n dictionary({}) at {}", (Object)language, (Object)(parent.getPath() + "/" + dictionaryName));
i18nNode = ((Node)parent.adaptTo(Node.class)).addNode(dictionaryName, "nt:file");
Node content = i18nNode.addNode("jcr:content", "nt:resource");
content.setPrimaryType("nt:resource");
content.setProperty("jcr:mimeType", "application/json");
content.setProperty("jcr:data", "{}");
} else {
Node parentNode = (Node)parent.adaptTo(Node.class);
String dictionaryName = JcrUtil.createValidChildName((Node)parentNode, (String)language);
log.trace("Creating JCR based I18n dictionary({}) at {}", (Object)language, (Object)(parent.getPath() + "/" + dictionaryName));
i18nNode = JcrResourceUtil.createPath((Node)parentNode, (String)dictionaryName, (String)"nt:unstructured", (String)"sling:Folder", (boolean)false);
if (!StringUtils.isEmpty((CharSequence)baseName)) {
i18nNode.setProperty("sling:basename", baseName);
}
}
i18nNode.addMixin("mix:language");
i18nNode.setProperty("jcr:language", language);
resourceResolver.commit();
return resourceResolver.getResource(i18nNode.getPath());
}
public static boolean isI18nEntry(Resource resource) throws RepositoryException {
Node node = (Node)resource.adaptTo(Node.class);
if (node != null && node.hasProperty("sling:message")) {
if (node.isNodeType("sling:MessageEntry")) {
return true;
}
Property properties = node.getProperty("jcr:mixinTypes");
for (Value value : properties.getValues()) {
if (!StringUtils.equals((CharSequence)value.toString(), (CharSequence)"sling:Message")) continue;
return true;
}
}
return false;
}
public static ArrayList<Resource> getI18nJCREntryResourceList(Resource i18nDict) {
Iterable childList = i18nDict.getChildren();
ArrayList<Resource> resourceList = new ArrayList<Resource>();
for (Resource child : childList) {
try {
if (!I18nDictionary.isI18nEntry(child)) continue;
resourceList.add(child);
}
catch (RepositoryException e) {
log.error("Error reading I18n JCR entries", (Throwable)e);
}
}
return resourceList;
}
static String getI18nJCREntryKey(Resource jcrEntry) throws RepositoryException {
String key = TranslationUtils.getAttribute(jcrEntry, "sling:key", String.class);
if (key == null) {
return jcrEntry.getName();
}
return key;
}
public static void getAllKeysFromDict(Resource i18nDict, HashSet<String> i18nKeySet) {
if (TranslationUtils.checkFileExtension((Node)i18nDict.adaptTo(Node.class), ".json")) {
I18nDictionary.getAllKeysFromJsonDict(i18nDict, i18nKeySet);
} else {
I18nDictionary.getAllKeysFromJcrDict(i18nDict, i18nKeySet);
}
}
static void getAllKeysFromJsonDict(Resource i18nDict, HashSet<String> i18nKeySet) {
try {
JsonParser parser = new JsonParser();
InputStream jsonStream = (InputStream)i18nDict.adaptTo(InputStream.class);
InputStreamReader jsonReader = new InputStreamReader(jsonStream, "UTF-8");
JsonObject jsonObject = parser.parse((Reader)jsonReader).getAsJsonObject();
Set jsonEntries = jsonObject.entrySet();
for (Map.Entry jsonEntry : jsonEntries) {
i18nKeySet.add((String)jsonEntry.getKey());
}
}
catch (UnsupportedEncodingException ignored) {
// empty catch block
}
}
static void getAllKeysFromJcrDict(Resource i18nDict, HashSet<String> i18nKeySet) {
Iterable childList = i18nDict.getChildren();
for (Resource child : childList) {
try {
if (!I18nDictionary.isI18nEntry(child)) continue;
i18nKeySet.add(I18nDictionary.getI18nJCREntryKey(child));
}
catch (RepositoryException e) {
log.error("Error reading I18n JCR entries", (Throwable)e);
}
}
}
public static void getAllEntriesFromDict(Resource i18nDict, HashMap<String, String> i18nEntryMap) {
if (TranslationUtils.checkFileExtension((Node)i18nDict.adaptTo(Node.class), ".json")) {
I18nDictionary.getAllEntriesFromJsonDict(i18nDict, i18nEntryMap);
} else {
I18nDictionary.getAllEntriesFromJcrDict(i18nDict, i18nEntryMap);
}
}
static void getAllEntriesFromJsonDict(Resource i18nDict, HashMap<String, String> i18nEntryMap) {
try {
JsonParser parser = new JsonParser();
InputStream jsonStream = (InputStream)i18nDict.adaptTo(InputStream.class);
InputStreamReader jsonReader = new InputStreamReader(jsonStream, "UTF-8");
JsonObject jsonObject = parser.parse((Reader)jsonReader).getAsJsonObject();
Set jsonEntries = jsonObject.entrySet();
for (Map.Entry jsonEntry : jsonEntries) {
i18nEntryMap.put((String)jsonEntry.getKey(), ((JsonElement)jsonEntry.getValue()).getAsString());
}
}
catch (UnsupportedEncodingException ignored) {
// empty catch block
}
}
static void getAllEntriesFromJcrDict(Resource i18nDict, HashMap<String, String> i18nEntryMap) {
Iterable childList = i18nDict.getChildren();
for (Resource child : childList) {
try {
if (!I18nDictionary.isI18nEntry(child)) continue;
i18nEntryMap.put(I18nDictionary.getI18nJCREntryKey(child), TranslationUtils.getAttribute(child, "sling:message", String.class));
}
catch (RepositoryException e) {
log.error("Error reading I18n JCR entries", (Throwable)e);
}
}
}
public static HashSet<String> getAllI18nDictKeys(ResourceResolver resolver, String language, String baseName) {
HashSet<String> i18nKeySet = new HashSet<String>();
List<Node> i18nDictNodeList = I18nDictionary.getAllI18nDicts(resolver, language, baseName);
if (i18nDictNodeList != null) {
for (Node i18nDict : i18nDictNodeList) {
try {
I18nDictionary.getAllKeysFromDict(resolver.getResource(i18nDict.getPath()), i18nKeySet);
}
catch (RepositoryException ignored) {}
}
}
return i18nKeySet;
}
static List<Node> getAllI18nDicts(ResourceResolver resolver, String language, String baseName) {
log.trace("In function: getAllI18nDicts for {}", (Object)language);
ArrayList<Node> i18nDicts = new ArrayList<Node>();
try {
Session session = (Session)resolver.adaptTo(Session.class);
QueryManager qm = session.getWorkspace().getQueryManager();
QueryResult result = baseName == null ? qm.createQuery("//element(*, mix:language)[@jcr:language=\"" + language + "\" ]", "xpath").execute() : qm.createQuery("//element(*, mix:language)[@sling:basename=\"" + baseName + "\" " + "and @jcr:language=\"" + language + "\" ]", "xpath").execute();
NodeIterator nodes = result.getNodes();
log.trace("{} dictionaries found", (Object)nodes.getSize());
while (nodes.hasNext()) {
Node node = nodes.nextNode();
i18nDicts.add(node);
log.trace("{}", (Object)node.getPath());
}
}
catch (RepositoryException e) {
return null;
}
return i18nDicts;
}
public static NodeIterator getAllI18nDictsAtPath(ResourceResolver resolver, String path, String baseName) {
log.trace("In function: getAllI18nDictsAtPath path:{} basename:{}", (Object)path, (Object)baseName);
try {
Session session = (Session)resolver.adaptTo(Session.class);
QueryManager qm = session.getWorkspace().getQueryManager();
QueryResult result = baseName == null ? qm.createQuery("/jcr:root" + path + "//element(*, mix:language)", "xpath").execute() : qm.createQuery("/jcr:root" + path + "//element(*, mix:language)[@sling:basename=\"" + baseName + "\" ]", "xpath").execute();
return result.getNodes();
}
catch (RepositoryException e) {
log.error("Can't get i18n dictionaries from {}", (Object)path, (Object)e);
return null;
}
}
public static boolean addEntriesToDict(Resource i18nDict, HashMap<String, String> newEntries) {
log.trace("In function: addEntriesToDict");
if (TranslationUtils.checkFileExtension((Node)i18nDict.adaptTo(Node.class), ".json")) {
return I18nDictionary.addEntriesToJsonDict(i18nDict, newEntries);
}
return I18nDictionary.addEntriesToJcrDict(i18nDict, newEntries);
}
private static boolean addEntriesToJsonDict(Resource jsonDict, HashMap<String, String> newEntries) {
log.trace("In function: addEntriesToJsonDict");
boolean bSave = false;
try {
JsonParser parser = new JsonParser();
InputStream jsonStream = (InputStream)jsonDict.adaptTo(InputStream.class);
InputStreamReader jsonReader = new InputStreamReader(jsonStream, "UTF-8");
JsonObject jsonObject = parser.parse((Reader)jsonReader).getAsJsonObject();
for (Map.Entry<String, String> newEntry : newEntries.entrySet()) {
jsonObject.addProperty(newEntry.getKey(), newEntry.getValue());
bSave = true;
}
if (bSave) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
ByteArrayInputStream inputStream = new ByteArrayInputStream(gson.toJson((JsonElement)jsonObject).getBytes(Charset.forName("UTF-8")));
Node jsonJcrContent = ((Node)jsonDict.adaptTo(Node.class)).getNode("jcr:content");
jsonJcrContent.setProperty("jcr:data", jsonJcrContent.getSession().getValueFactory().createBinary((InputStream)inputStream));
}
}
catch (Exception e) {
bSave = false;
}
return bSave;
}
private static boolean addEntriesToJcrDict(Resource i18nDict, HashMap<String, String> newEntries) {
boolean bSave = false;
HashMap<String, String> existingEntries = new HashMap<String, String>();
I18nDictionary.getAllEntriesFromJcrDict(i18nDict, existingEntries);
Node destDictNode = (Node)i18nDict.adaptTo(Node.class);
if (existingEntries.size() > 0) {
int entryCnt = existingEntries.size();
for (Map.Entry<String, String> newEntry : newEntries.entrySet()) {
String key = newEntry.getKey();
if (existingEntries.containsKey(key)) continue;
++entryCnt;
try {
bSave = I18nDictionary.addI18nJcrEntry(destDictNode, "entry_" + entryCnt, key, newEntry.getValue());
}
catch (RepositoryException ignored) {
log.error("Could not add entry:{}", (Object)key);
}
}
} else {
int entryCnt = 0;
for (Map.Entry<String, String> newEntry : newEntries.entrySet()) {
String key = newEntry.getKey();
++entryCnt;
try {
bSave = I18nDictionary.addI18nJcrEntry(destDictNode, "entry_" + entryCnt, key, newEntry.getValue());
}
catch (RepositoryException ignored) {
log.error("Could not add entry:{}", (Object)key);
}
}
}
return bSave;
}
public static boolean addEntriesToDict(Resource i18nDict, HashSet<String> newEntries) {
log.trace("In function: addEntriesToDict");
if (TranslationUtils.checkFileExtension((Node)i18nDict.adaptTo(Node.class), ".json")) {
return I18nDictionary.addEntriesToJsonDict(i18nDict, newEntries);
}
return I18nDictionary.addEntriesToJcrDict(i18nDict, newEntries);
}
private static boolean addEntriesToJsonDict(Resource jsonDict, HashSet<String> newEntries) {
log.trace("In function: addEntriesToJsonDict");
boolean bSave = false;
try {
JsonParser parser = new JsonParser();
InputStream jsonStream = (InputStream)jsonDict.adaptTo(InputStream.class);
InputStreamReader jsonReader = new InputStreamReader(jsonStream, "UTF-8");
JsonObject jsonObject = parser.parse((Reader)jsonReader).getAsJsonObject();
for (String newEntry : newEntries) {
String[] stringAndComment;
if (I18nDictionary.disJoinStringAndComment(newEntry, stringAndComment = new String[2])) {
jsonObject.addProperty(newEntry, stringAndComment[0]);
} else {
jsonObject.addProperty(newEntry, newEntry);
}
bSave = true;
}
if (bSave) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
ByteArrayInputStream inputStream = new ByteArrayInputStream(gson.toJson((JsonElement)jsonObject).getBytes(Charset.forName("UTF-8")));
Node jsonJcrContent = ((Node)jsonDict.adaptTo(Node.class)).getNode("jcr:content");
jsonJcrContent.setProperty("jcr:data", jsonJcrContent.getSession().getValueFactory().createBinary((InputStream)inputStream));
}
}
catch (Exception e) {
bSave = false;
}
return bSave;
}
private static boolean addEntriesToJcrDict(Resource i18nDict, HashSet<String> newEntries) {
boolean bSave = false;
HashMap<String, String> existingEntries = new HashMap<String, String>();
I18nDictionary.getAllEntriesFromJcrDict(i18nDict, existingEntries);
Node destDictNode = (Node)i18nDict.adaptTo(Node.class);
if (existingEntries.size() > 0) {
int entryCnt = existingEntries.size();
String[] stringAndComment = new String[2];
for (String newEntry : newEntries) {
if (existingEntries.containsKey(newEntry)) continue;
++entryCnt;
try {
if (I18nDictionary.disJoinStringAndComment(newEntry, stringAndComment)) {
bSave = I18nDictionary.addI18nJcrEntry(destDictNode, "entry_" + entryCnt, newEntry, stringAndComment[0]);
continue;
}
bSave = I18nDictionary.addI18nJcrEntry(destDictNode, "entry_" + entryCnt, newEntry, newEntry);
}
catch (RepositoryException ignored) {
log.error("Could not add entry:{}", (Object)newEntry);
}
}
} else {
int entryCnt = 0;
String[] stringAndComment = new String[2];
for (String newEntry : newEntries) {
++entryCnt;
try {
if (I18nDictionary.disJoinStringAndComment(newEntry, stringAndComment)) {
bSave = I18nDictionary.addI18nJcrEntry(destDictNode, "entry_" + entryCnt, newEntry, stringAndComment[0]);
continue;
}
bSave = I18nDictionary.addI18nJcrEntry(destDictNode, "entry_" + entryCnt, newEntry, newEntry);
}
catch (RepositoryException ignored) {
log.error("Could not add entry:{}", (Object)newEntry);
}
}
}
return bSave;
}
private static boolean addI18nJcrEntry(Node destDictNode, String name, String key, String value) throws RepositoryException {
String nodeName = JcrUtil.createValidChildName((Node)destDictNode, (String)name);
Node newEntry = destDictNode.addNode(nodeName, "nt:folder");
if (newEntry != null) {
log.trace("Creating I18n JCR entry at {}", (Object)newEntry.getPath());
newEntry.addMixin("sling:Message");
newEntry.setProperty("sling:key", key);
newEntry.setProperty("sling:message", value);
return true;
}
return false;
}
private static boolean disJoinStringAndComment(String srcString, String[] stringAndComment) {
int commentStartIndex = srcString.indexOf(COMMENT_START_IDENTIFIER);
int commentEndIndex = srcString.indexOf(COMMENT_END_IDENTIFIER);
if (commentStartIndex >= 0 && commentEndIndex >= 0) {
stringAndComment[1] = srcString.substring(commentStartIndex + COMMENT_START_IDENTIFIER.length(), commentEndIndex);
stringAndComment[0] = srcString.substring(0, commentStartIndex);
return true;
}
return false;
}
public static Resource getOrCreateLanguageCopyParentResource(Resource dictResource) throws PersistenceException {
Resource parentResource = dictResource.getParent();
String parentPath = parentResource.getPath();
if (!parentPath.startsWith("/apps/") && !parentPath.startsWith("/content/")) {
String relativePath = parentPath.substring(parentPath.substring(1).indexOf(47) + 2);
parentPath = "/apps/" + relativePath;
parentResource = ResourceUtil.getOrCreateResource((ResourceResolver)dictResource.getResourceResolver(), (String)parentPath, (String)"sling:Folder", (String)"sling:Folder", (boolean)false);
}
return parentResource;
}
public static Resource getOrCreateLanguageCopy(ResourceResolver resourceResolver, String strSrcDictPath, String targetLanguage) {
Resource srcDictResource = resourceResolver.resolve(strSrcDictPath);
try {
Resource parentResource = I18nDictionary.getOrCreateLanguageCopyParentResource(srcDictResource);
Resource languageCopyResource = null;
if (parentResource != null) {
String srcBaseName = TranslationUtils.getAttribute(srcDictResource, "sling:basename", String.class);
boolean isJson = TranslationUtils.checkFileExtension((Node)srcDictResource.adaptTo(Node.class), ".json");
languageCopyResource = I18nDictionary.getOrCreateI18nDictionaryResource(resourceResolver, parentResource.getPath(), targetLanguage, srcBaseName, isJson);
I18nDictionary.copyDictionaryEntries(srcDictResource, languageCopyResource);
}
return languageCopyResource;
}
catch (PersistenceException e) {
return null;
}
}
public static void copyDictionaryEntries(Resource srcDictionary, Resource destDictionary) {
HashMap<String, String> i18nEntryMap = new HashMap<String, String>();
I18nDictionary.getAllEntriesFromDict(srcDictionary, i18nEntryMap);
I18nDictionary.addEntriesToDict(destDictionary, i18nEntryMap);
}
}