TranslationPropertiesHandler.java
4.09 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.catalog.util.localization.LocaleMap
* com.scene7.is.provider.catalog.Catalog
* com.scene7.is.provider.catalog.ObjectRecord
* com.scene7.is.sleng.ImageAccessException
* com.scene7.is.util.callbacks.Option
* com.scene7.is.util.error.ApplicationException
* org.jetbrains.annotations.NotNull
* org.jetbrains.annotations.Nullable
*/
package com.scene7.is.ps.provider;
import com.scene7.is.catalog.util.localization.LocaleMap;
import com.scene7.is.provider.catalog.Catalog;
import com.scene7.is.provider.catalog.ObjectRecord;
import com.scene7.is.ps.provider.ModifierSet;
import com.scene7.is.ps.provider.PropertiesHandler;
import com.scene7.is.ps.provider.Request;
import com.scene7.is.ps.provider.defs.ModifierEnum;
import com.scene7.is.sleng.ImageAccessException;
import com.scene7.is.util.callbacks.Option;
import com.scene7.is.util.error.ApplicationException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class TranslationPropertiesHandler
extends PropertiesHandler {
@Override
protected Map<String, Object> getProperties(Request request) throws ImageAccessException {
HashMap<String, Object> props = new HashMap<String, Object>();
ObjectRecord descriptor = request.getGlobalAttributes().getOrDie(ModifierEnum.I_UNTRANSLATED_DESCRIPTOR);
try {
String modifierLocaleId = request.getGlobalAttributes().get(ModifierEnum.LOCALE);
TranslationPropertiesHandler.setTranslationProperties(descriptor, props, modifierLocaleId);
}
catch (ApplicationException e) {
String finalError = "Failed to get translation properties";
throw new ImageAccessException(8, finalError, (Throwable)e);
}
return props;
}
private static void setTranslationProperties(ObjectRecord record, Map<String, Object> dst, @Nullable String modifierLocaleId) throws ImageAccessException {
LocaleMap localeMap = record.getCatalog().getLocaleMap();
String localeId = modifierLocaleId;
if (!localeMap.isEmpty()) {
if (localeId == null) {
localeId = record.getCatalog().getDefaultLocale();
}
String translatedId = record.getName();
Option globalLocale = record.getCatalog().getGlobalLocale();
List translatedIds = globalLocale.isDefined() && !((String)globalLocale.get()).isEmpty() ? localeMap.getTranslatedIdsWithGlobalLocale(localeId, translatedId, (String)globalLocale.get()) : localeMap.getTranslatedIds(localeId, translatedId);
if (translatedIds == null) {
throw new ImageAccessException(20, "Unknown locale: " + localeId + " - no default rule defined", null);
}
TranslationPropertiesHandler.setProperty("xlate.translatedIds", TranslationPropertiesHandler.translatedIdsToString(translatedIds), dst);
} else {
TranslationPropertiesHandler.setProperty("xlate.translatedIds", "", dst);
}
}
private static void setProperty(@NotNull String name, @Nullable Object value, @NotNull Map<String, Object> dst) {
if (value != null) {
if (value instanceof String) {
String tmp = (String)value;
if (!tmp.isEmpty()) {
dst.put(name, value);
}
} else {
dst.put(name, value);
}
}
}
private static String translatedIdsToString(@NotNull List<String> translatedIds) {
if (translatedIds.isEmpty()) {
return "";
}
StringBuilder builder = new StringBuilder();
builder.append(translatedIds.get(0));
for (int i = 1; i < translatedIds.size(); ++i) {
builder.append(',');
builder.append(translatedIds.get(i));
}
return builder.toString();
}
private static interface TranslationProps {
public static final String TRANSLATED_IDS = "xlate.translatedIds";
}
}