|
Lines 10-15
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.equinox.internal.provisional.p2.ui.query; |
11 |
package org.eclipse.equinox.internal.provisional.p2.ui.query; |
| 12 |
|
12 |
|
|
|
13 |
import java.net.URL; |
| 13 |
import java.util.*; |
14 |
import java.util.*; |
| 14 |
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; |
15 |
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; |
| 15 |
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; |
16 |
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; |
|
Lines 24-35
Link Here
|
| 24 |
static final Locale DEFAULT_LOCALE = new Locale("df", "LT"); //$NON-NLS-1$//$NON-NLS-2$ |
25 |
static final Locale DEFAULT_LOCALE = new Locale("df", "LT"); //$NON-NLS-1$//$NON-NLS-2$ |
| 25 |
static final String NAMESPACE_IU_LOCALIZATION = "org.eclipse.equinox.p2.localization"; //$NON-NLS-1$ |
26 |
static final String NAMESPACE_IU_LOCALIZATION = "org.eclipse.equinox.p2.localization"; //$NON-NLS-1$ |
| 26 |
|
27 |
|
|
|
28 |
// Get the license in the default locale. |
| 29 |
public static License getLicense(IInstallableUnit iu) { |
| 30 |
return getLicense(iu, getCurrentLocale()); |
| 31 |
} |
| 32 |
|
| 33 |
// Get the copyright in the default locale. |
| 34 |
public static Copyright getCopyright(IInstallableUnit iu) { |
| 35 |
return getCopyright(iu, getCurrentLocale()); |
| 36 |
} |
| 37 |
|
| 38 |
// Get a property in the default locale |
| 39 |
public static String getIUProperty(IInstallableUnit iu, String propertyKey) { |
| 40 |
return getIUProperty(iu, propertyKey, getCurrentLocale()); |
| 41 |
} |
| 42 |
|
| 43 |
public static License getLicense(IInstallableUnit iu, Locale locale) { |
| 44 |
License license = iu.getLicense(); |
| 45 |
String body = (license != null ? license.getBody() : null); |
| 46 |
if (body == null || body.length() <= 1 || body.charAt(0) != '%') |
| 47 |
return license; |
| 48 |
final String actualKey = body.substring(1); // Strip off the % |
| 49 |
body = getLocalizedIUProperty(iu, actualKey, locale); |
| 50 |
URL url = license.getURL(); |
| 51 |
return new License((url != null ? url.toExternalForm() : null), body); |
| 52 |
} |
| 53 |
|
| 54 |
public static Copyright getCopyright(IInstallableUnit iu, Locale locale) { |
| 55 |
Copyright copyright = iu.getCopyright(); |
| 56 |
String body = (copyright != null ? copyright.getBody() : null); |
| 57 |
if (body == null || body.length() <= 1 || body.charAt(0) != '%') |
| 58 |
return copyright; |
| 59 |
final String actualKey = body.substring(1); // Strip off the % |
| 60 |
body = getLocalizedIUProperty(iu, actualKey, locale); |
| 61 |
URL url = copyright.getURL(); |
| 62 |
return new Copyright((url != null ? url.toExternalForm() : null), body); |
| 63 |
} |
| 64 |
|
| 27 |
public static String getIUProperty(IInstallableUnit iu, String propertyKey, Locale locale) { |
65 |
public static String getIUProperty(IInstallableUnit iu, String propertyKey, Locale locale) { |
| 28 |
String value = iu.getProperty(propertyKey); |
66 |
String value = iu.getProperty(propertyKey); |
| 29 |
if (value == null || value.length() <= 1 || value.charAt(0) != '%') |
67 |
if (value == null || value.length() <= 1 || value.charAt(0) != '%') |
| 30 |
return value; |
68 |
return value; |
| 31 |
// else have a localizable property |
69 |
// else have a localizable property |
| 32 |
final String actualKey = value.substring(1); // Strip off the % |
70 |
final String actualKey = value.substring(1); // Strip off the % |
|
|
71 |
return getLocalizedIUProperty(iu, actualKey, locale); |
| 72 |
} |
| 73 |
|
| 74 |
private static String getLocalizedIUProperty(IInstallableUnit iu, String actualKey, Locale locale) { |
| 75 |
// Short circuit query if iu provides value for matching locale |
| 76 |
String localizedKey = makeLocalizedKey(actualKey, locale.toString()); |
| 77 |
String localizedValue = iu.getProperty(localizedKey); |
| 78 |
if (localizedValue != null) |
| 79 |
return localizedValue; |
| 80 |
|
| 33 |
final List locales = buildLocaleVariants(locale); |
81 |
final List locales = buildLocaleVariants(locale); |
| 34 |
final IInstallableUnit theUnit = iu; |
82 |
final IInstallableUnit theUnit = iu; |
| 35 |
|
83 |
|
|
Lines 89-100
Link Here
|
| 89 |
} |
137 |
} |
| 90 |
} |
138 |
} |
| 91 |
|
139 |
|
| 92 |
String defaultKey = makeLocalizedKey(actualKey, DEFAULT_LOCALE.toString()); |
140 |
for (Iterator iter = locales.iterator(); iter.hasNext();) { |
| 93 |
String defaultValue = iu.getProperty(defaultKey); |
141 |
String nextLocale = (String) iter.next(); |
| 94 |
if (defaultValue != null) |
142 |
String localeKey = makeLocalizedKey(actualKey, nextLocale); |
| 95 |
return defaultValue; |
143 |
String nextValue = iu.getProperty(localeKey); |
|
|
144 |
if (nextValue != null) |
| 145 |
return nextValue; |
| 146 |
} |
| 96 |
|
147 |
|
| 97 |
return value; |
148 |
return actualKey; |
| 98 |
} |
149 |
} |
| 99 |
|
150 |
|
| 100 |
/** |
151 |
/** |
|
Lines 111-117
Link Here
|
| 111 |
nl = nl.substring(0, lastSeparator); |
162 |
nl = nl.substring(0, lastSeparator); |
| 112 |
} |
163 |
} |
| 113 |
// Add the default locale (most general) |
164 |
// Add the default locale (most general) |
| 114 |
result.add(DEFAULT_LOCALE); |
165 |
result.add(DEFAULT_LOCALE.toString()); |
| 115 |
return result; |
166 |
return result; |
| 116 |
} |
167 |
} |
| 117 |
|
168 |
|
|
Lines 119-122
Link Here
|
| 119 |
return localeImage + '.' + actualKey; |
170 |
return localeImage + '.' + actualKey; |
| 120 |
} |
171 |
} |
| 121 |
|
172 |
|
|
|
173 |
private static Locale getCurrentLocale() { |
| 174 |
return Locale.getDefault(); |
| 175 |
} |
| 176 |
|
| 122 |
} |
177 |
} |