Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 222309 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java (-31 / +1 lines)
Lines 69-74 Link Here
69
	 * of strings from a specified IU in a specified locale
69
	 * of strings from a specified IU in a specified locale
70
	 * @see RequiredCapability#getNamespace()
70
	 * @see RequiredCapability#getNamespace()
71
	 * @see ProvidedCapability#getNamespace()
71
	 * @see ProvidedCapability#getNamespace()
72
	 * TODO: this should be in API, probably in IInstallableUnit
72
	 */
73
	 */
73
	public static final String NAMESPACE_IU_LOCALIZATION = "org.eclipse.equinox.p2.localization"; //$NON-NLS-1$
74
	public static final String NAMESPACE_IU_LOCALIZATION = "org.eclipse.equinox.p2.localization"; //$NON-NLS-1$
74
75
Lines 293-329 Link Here
293
		return MetadataFactory.createInstallableUnit(iu);
294
		return MetadataFactory.createInstallableUnit(iu);
294
	}
295
	}
295
296
296
	/*
297
	 * @param bd
298
	 * @param manifestLocalizations	map from locale to translated properties
299
	 * @return installableUnitFragment
300
	 */
301
	//	private static IInstallableUnitFragment createLocalizationFragmentOfBundle(BundleDescription bd, Map manifestLocalizations) {
302
	//		InstallableUnitFragmentDescription fragment = new MetadataFactory.InstallableUnitFragmentDescription();
303
	//		String fragmentId = makeBundleLocalizationFragmentId(bd.getSymbolicName());
304
	//		fragment.setId(fragmentId);
305
	//		fragment.setVersion(bd.getVersion());
306
	//
307
	//		RequiredCapability[] hostReqs = new RequiredCapability[] {MetadataFactory.createRequiredCapability(NAMESPACE_ECLIPSE_TYPE, bd.getSymbolicName(), new VersionRange(bd.getVersion(), true, bd.getVersion(), true), null, false, false, false)};
308
	//		fragment.setHost(hostReqs);
309
	//
310
	//		fragment.setSingleton(true);
311
	//
312
	//		ArrayList providedCapabilities = new ArrayList(manifestLocalizations.size());
313
	//		for (Iterator iter = manifestLocalizations.keySet().iterator(); iter.hasNext();) {
314
	//			Locale locale = (Locale) iter.next();
315
	//			Properties translatedStrings = (Properties) manifestLocalizations.get(locale);
316
	//			Enumeration propertyKeys = translatedStrings.propertyNames();
317
	//			while (propertyKeys.hasMoreElements()) {
318
	//				String nextKey = (String) propertyKeys.nextElement();
319
	//				fragment.setProperty(locale.toString() + '.' + nextKey, translatedStrings.getProperty(nextKey));
320
	//			}
321
	//			providedCapabilities.add(makeTranslationCapability(bd.getSymbolicName(), locale));
322
	//		}
323
	//		fragment.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()]));
324
	//
325
	//		return MetadataFactory.createInstallableUnitFragment(fragment);
326
	//	}
327
	public static void createHostLocalizationFragment(IInstallableUnit bundleIU, BundleDescription bd, String hostId, String[] hostBundleManifestValues, Set localizationIUs) {
297
	public static void createHostLocalizationFragment(IInstallableUnit bundleIU, BundleDescription bd, String hostId, String[] hostBundleManifestValues, Set localizationIUs) {
328
		Map hostLocalizations = getHostLocalizations(new File(bd.getLocation()), hostBundleManifestValues);
298
		Map hostLocalizations = getHostLocalizations(new File(bd.getLocation()), hostBundleManifestValues);
329
		if (hostLocalizations != null) {
299
		if (hostLocalizations != null) {
(-)src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java (-21 / +66 lines)
Lines 13-51 Link Here
13
import java.util.*;
13
import java.util.*;
14
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
14
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
15
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
15
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
16
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
16
import org.eclipse.equinox.internal.provisional.p2.metadata.*;
17
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
17
import org.eclipse.equinox.internal.provisional.p2.metadata.query.IUPropertyQuery;
18
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
18
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
19
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
19
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
20
20
21
public class IUPropertyUtils {
21
public class IUPropertyUtils {
22
22
23
	// TODO: these constants should come from API, eg. IInstallableUnit or ???
23
	static final Locale DEFAULT_LOCALE = new Locale("df", "LT"); //$NON-NLS-1$//$NON-NLS-2$
24
	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$
24
26
25
	public static String getIUProperty(IInstallableUnit iu, String propertyKey, Locale locale) {
27
	public static String getIUProperty(IInstallableUnit iu, String propertyKey, Locale locale) {
26
		String value = iu.getProperty(propertyKey);
28
		String value = iu.getProperty(propertyKey);
27
		if (value == null || value.length() <= 1 || value.charAt(0) != '%')
29
		if (value == null || value.length() <= 1 || value.charAt(0) != '%')
28
			return value;
30
			return value;
29
		// else have a localizable property
31
		// else have a localizable property
30
		String actualKey = value.substring(1);
32
		final String actualKey = value.substring(1); // Strip off the %
31
		String localizationBundles[] = buildLocalizationVariants(iu, locale);
33
		final List locales = buildLocaleVariants(locale);
34
		final IInstallableUnit theUnit = iu;
35
36
		Collector hostLocalizationCollector = new Collector() {
37
			public boolean accept(Object object) {
38
				boolean haveHost = false;
39
				boolean haveLocale = false;
40
				if (object instanceof IInstallableUnitFragment) {
41
					IInstallableUnitFragment fragment = (IInstallableUnitFragment) object;
42
					RequiredCapability[] hosts = fragment.getHost();
43
					for (int i = 0; i < hosts.length; i++) {
44
						RequiredCapability nextHost = hosts[i];
45
						if (IInstallableUnit.NAMESPACE_IU_ID.equals(nextHost.getNamespace()) && //
46
								theUnit.getId().equals(nextHost.getName()) && //
47
								nextHost.getRange() != null && //
48
								nextHost.getRange().isIncluded(theUnit.getVersion())) {
49
							haveHost = true;
50
							break;
51
						}
52
					}
53
54
					if (haveHost) {
55
						ProvidedCapability[] provides = fragment.getProvidedCapabilities();
56
						for (int j = 0; j < provides.length && !haveLocale; j++) {
57
							ProvidedCapability nextProvide = provides[j];
58
							if (NAMESPACE_IU_LOCALIZATION.equals(nextProvide.getNamespace())) {
59
								String providedLocale = nextProvide.getName();
60
								if (providedLocale != null) {
61
									for (Iterator iter = locales.iterator(); iter.hasNext();) {
62
										if (providedLocale.equals(iter.next())) {
63
											haveLocale = true;
64
											break;
65
										}
66
									}
67
								}
68
							}
69
						}
70
					}
71
				}
72
				return (haveHost && haveLocale ? super.accept(object) : false);
73
			}
74
		};
32
75
33
		IMetadataRepositoryManager repoMgr = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName());
76
		IMetadataRepositoryManager repoMgr = (IMetadataRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IMetadataRepositoryManager.class.getName());
34
77
		IUPropertyQuery iuQuery = new IUPropertyQuery(IInstallableUnit.PROP_TYPE_FRAGMENT, "true"); //$NON-NLS-1$
35
		for (int i = 0; i < localizationBundles.length; i++) {
78
		Collector collected = repoMgr.query(iuQuery, hostLocalizationCollector, null);
36
			InstallableUnitQuery iuQuery = new InstallableUnitQuery(localizationBundles[i]);
79
		if (!collected.isEmpty()) {
37
			Collector collected = repoMgr.query(iuQuery, new Collector(), null);
80
			String translation = null;
38
			if (!collected.isEmpty()) {
81
			for (Iterator iter = collected.iterator(); iter.hasNext() && translation == null;) {
39
				for (Iterator iter = collected.iterator(); iter.hasNext();) {
82
				IInstallableUnit localizationIU = (IInstallableUnit) iter.next();
40
					IInstallableUnit localizationIU = (IInstallableUnit) iter.next();
83
				for (Iterator jter = locales.iterator(); jter.hasNext();) {
41
					String translation = localizationIU.getProperty(actualKey);
84
					String localeKey = makeLocalizedKey(actualKey, (String) jter.next());
85
					translation = localizationIU.getProperty(localeKey);
42
					if (translation != null)
86
					if (translation != null)
43
						return translation;
87
						return translation;
44
				}
88
				}
45
			}
89
			}
46
		}
90
		}
47
91
48
		String defaultKey = DEFAULT_LOCALE.toString() + '.' + actualKey;
92
		String defaultKey = makeLocalizedKey(actualKey, DEFAULT_LOCALE.toString());
49
		String defaultValue = iu.getProperty(defaultKey);
93
		String defaultValue = iu.getProperty(defaultKey);
50
		if (defaultValue != null)
94
		if (defaultValue != null)
51
			return defaultValue;
95
			return defaultValue;
Lines 53-77 Link Here
53
		return value;
97
		return value;
54
	}
98
	}
55
99
56
	private static final String TRANSLATED_PROPERTIES_NAME = "_translated_properties"; //$NON-NLS-1$
57
58
	/**
100
	/**
59
	 */
101
	 */
60
	private static String[] buildLocalizationVariants(IInstallableUnit iu, Locale locale) {
102
	private static List buildLocaleVariants(Locale locale) {
61
		String id = iu.getId().toString();
62
		String nl = locale.toString();
103
		String nl = locale.toString();
63
		ArrayList result = new ArrayList(4);
104
		ArrayList result = new ArrayList(4);
64
		int lastSeparator;
105
		int lastSeparator;
65
		while (true) {
106
		while (true) {
66
			result.add(id + '_' + nl + TRANSLATED_PROPERTIES_NAME);
107
			result.add(nl);
67
			lastSeparator = nl.lastIndexOf('_');
108
			lastSeparator = nl.lastIndexOf('_');
68
			if (lastSeparator == -1)
109
			if (lastSeparator == -1)
69
				break;
110
				break;
70
			nl = nl.substring(0, lastSeparator);
111
			nl = nl.substring(0, lastSeparator);
71
		}
112
		}
72
		// Add the empty suffix last (most general)
113
		// Add the default locale (most general)
73
		result.add(id + TRANSLATED_PROPERTIES_NAME);
114
		result.add(DEFAULT_LOCALE);
74
		return (String[]) result.toArray(new String[result.size()]);
115
		return result;
116
	}
117
118
	private static String makeLocalizedKey(String actualKey, String localeImage) {
119
		return localeImage + '.' + actualKey;
75
	}
120
	}
76
121
77
}
122
}
(-)src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/IUGeneralInfoPropertyPage.java (-6 / +6 lines)
Lines 54-71 Link Here
54
		layout.marginHeight = 0;
54
		layout.marginHeight = 0;
55
		composite.setLayout(layout);
55
		composite.setLayout(layout);
56
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
56
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
57
		//addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_NameLabel, iu.getProperty(IInstallableUnit.PROP_NAME));
57
		Locale currentLocale = Locale.getDefault();
58
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_NameLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME, Locale.getDefault()));
58
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_NameLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME, currentLocale));
59
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_IdentifierLabel, iu.getId());
59
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_IdentifierLabel, iu.getId());
60
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_VersionLabel, iu.getVersion().toString());
60
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_VersionLabel, iu.getVersion().toString());
61
		//addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ProviderLabel, iu.getProperty(IInstallableUnit.PROP_PROVIDER));
61
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ProviderLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_PROVIDER, currentLocale));
62
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ProviderLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_PROVIDER, Locale.getDefault()));
62
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ContactLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_CONTACT, currentLocale));
63
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ContactLabel, iu.getProperty(IInstallableUnit.PROP_CONTACT));
64
63
65
	}
64
	}
66
65
67
	private void createDescriptionSection(Composite parent, IInstallableUnit iu) {
66
	private void createDescriptionSection(Composite parent, IInstallableUnit iu) {
68
		String description = iu.getProperty(IInstallableUnit.PROP_DESCRIPTION);
67
		Locale currentLocale = Locale.getDefault();
68
		String description = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_DESCRIPTION, currentLocale);
69
		if (description != null && description.length() > 0) {
69
		if (description != null && description.length() > 0) {
70
			Group group = new Group(parent, SWT.NONE);
70
			Group group = new Group(parent, SWT.NONE);
71
			group.setText(ProvUIMessages.IUGeneralInfoPropertyPage_DescriptionLabel);
71
			group.setText(ProvUIMessages.IUGeneralInfoPropertyPage_DescriptionLabel);

Return to bug 222309