Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 183968 Details for
Bug 331260
Implement an extensible translation service
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
patch
patch.txt (text/plain), 13.33 KB, created by
Thomas Schindl
on 2010-11-26 20:08:37 EST
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2010-11-26 20:08:37 EST
Size:
13.33 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.e4.core.services >Index: .project >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.services/.project,v >retrieving revision 1.2 >diff -u -r1.2 .project >--- .project 4 Feb 2009 18:56:31 -0000 1.2 >+++ .project 27 Nov 2010 01:08:01 -0000 >@@ -25,6 +25,11 @@ > <arguments> > </arguments> > </buildCommand> >+ <buildCommand> >+ <name>org.eclipse.pde.ds.core.builder</name> >+ <arguments> >+ </arguments> >+ </buildCommand> > </buildSpec> > <natures> > <nature>org.eclipse.pde.PluginNature</nature> >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF,v >retrieving revision 1.33 >diff -u -r1.33 MANIFEST.MF >--- META-INF/MANIFEST.MF 20 Jul 2010 19:43:28 -0000 1.33 >+++ META-INF/MANIFEST.MF 27 Nov 2010 01:08:01 -0000 >@@ -11,6 +11,7 @@ > CDC-1.1/Foundation-1.1 > Import-Package: javax.inject, > org.eclipse.osgi.service.debug;version="1.1.0", >+ org.eclipse.osgi.service.localization;version="1.1.0", > org.osgi.framework;version="1.3.0", > org.osgi.service.event;resolution:=optional, > org.osgi.util.tracker;version="1.4.2" >@@ -47,3 +48,4 @@ > Eclipse-ExtensibleAPI: true > Bundle-ClassPath: injection_annotations.jar, . > Bundle-Activator: org.eclipse.e4.core.internal.services.ServicesActivator >+Service-Component: OSGI-INF/translationService.xml >Index: OSGI-INF/translationService.xml >=================================================================== >RCS file: OSGI-INF/translationService.xml >diff -N OSGI-INF/translationService.xml >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ OSGI-INF/translationService.xml 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,8 @@ >+<?xml version="1.0" encoding="UTF-8"?> >+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.e4.core.services"> >+ <implementation class="org.eclipse.e4.core.internal.services.TranslationServiceImpl"/> >+ <service> >+ <provide interface="org.eclipse.e4.core.services.translation.ITranslationService"/> >+ </service> >+ <reference bind="dsRegisterTranslationProvider" cardinality="1..1" interface="org.eclipse.e4.core.services.translation.ITranslationProvider" name="ITranslationProvider" policy="static" unbind="dsUnregisterTranslationProvider"/> >+</scr:component> >Index: build.properties >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.services/build.properties,v >retrieving revision 1.5 >diff -u -r1.5 build.properties >--- build.properties 20 Jul 2010 19:43:28 -0000 1.5 >+++ build.properties 27 Nov 2010 01:08:02 -0000 >@@ -1,19 +1,10 @@ >-############################################################################### >-# Copyright (c) 2008 IBM Corporation and others. >-# All rights reserved. This program and the accompanying materials >-# are made available under the terms of the Eclipse Public License v1.0 >-# which accompanies this distribution, and is available at >-# http://www.eclipse.org/legal/epl-v10.html >-# >-# Contributors: >-# IBM Corporation - initial API and implementation >-############################################################################### >-source.. = src/ > output.. = bin/ > bin.includes = META-INF/,\ > .,\ > plugin.xml,\ > .options,\ > about.html,\ >- plugin.properties >+ plugin.properties,\ >+ OSGI-INF/translationService.xml > src.includes = schema/ >+source.. = src/ >Index: src/org/eclipse/e4/core/internal/services/ServicesActivator.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/ServicesActivator.java,v >retrieving revision 1.1 >diff -u -r1.1 ServicesActivator.java >--- src/org/eclipse/e4/core/internal/services/ServicesActivator.java 30 Nov 2009 16:55:53 -0000 1.1 >+++ src/org/eclipse/e4/core/internal/services/ServicesActivator.java 27 Nov 2010 01:08:02 -0000 >@@ -11,6 +11,8 @@ > package org.eclipse.e4.core.internal.services; > > import org.eclipse.osgi.service.debug.DebugOptions; >+import org.eclipse.osgi.service.localization.BundleLocalization; >+import org.eclipse.osgi.service.localization.LocaleProvider; > import org.osgi.framework.BundleActivator; > import org.osgi.framework.BundleContext; > import org.osgi.util.tracker.ServiceTracker; >@@ -20,6 +22,8 @@ > static private ServicesActivator defaultInstance; > private BundleContext bundleContext; > private ServiceTracker debugTracker = null; >+ private ServiceTracker localeProviderTracker = null; >+ private ServiceTracker bundleLocalizationTracker = null; > > public ServicesActivator() { > defaultInstance = this; >@@ -38,6 +42,17 @@ > debugTracker.close(); > debugTracker = null; > } >+ >+ if (localeProviderTracker != null) { >+ localeProviderTracker.close(); >+ localeProviderTracker = null; >+ } >+ >+ if (bundleLocalizationTracker != null) { >+ bundleLocalizationTracker.close(); >+ bundleLocalizationTracker = null; >+ } >+ > bundleContext = null; > } > >@@ -55,4 +70,26 @@ > return defaultValue; > } > >+ public LocaleProvider getLocaleProvider() { >+ if (localeProviderTracker == null) { >+ localeProviderTracker = new ServiceTracker(bundleContext, >+ LocaleProvider.class.getName(), null); >+ localeProviderTracker.open(); >+ } >+ >+ return (LocaleProvider) localeProviderTracker.getService(); >+ } >+ >+ public BundleLocalization getBundleLocalization() { >+ if (bundleLocalizationTracker == null) { >+ bundleLocalizationTracker = new ServiceTracker(bundleContext, >+ BundleLocalization.class.getName(), null); >+ bundleLocalizationTracker.open(); >+ } >+ return (BundleLocalization) bundleLocalizationTracker.getService(); >+ } >+ >+ public BundleContext getContext() { >+ return bundleContext; >+ } > } >Index: src/org/eclipse/e4/core/internal/services/TranslationServiceImpl.java >=================================================================== >RCS file: src/org/eclipse/e4/core/internal/services/TranslationServiceImpl.java >diff -N src/org/eclipse/e4/core/internal/services/TranslationServiceImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/core/internal/services/TranslationServiceImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,126 @@ >+package org.eclipse.e4.core.internal.services; >+ >+import java.util.Collections; >+import java.util.HashMap; >+import java.util.Locale; >+import java.util.Map; >+import java.util.ResourceBundle; >+import org.eclipse.e4.core.services.translation.ITranslationProvider; >+import org.eclipse.e4.core.services.translation.ITranslationService; >+import org.eclipse.osgi.service.localization.LocaleProvider; >+import org.osgi.framework.Bundle; >+ >+public class TranslationServiceImpl implements ITranslationService { >+ private Map<String, ITranslationProvider> providerMap = Collections >+ .synchronizedMap(new HashMap<String, ITranslationProvider>()); >+ >+ private Locale getLocale() { >+ LocaleProvider localeProvider = ServicesActivator.getDefault().getLocaleProvider(); >+ if (localeProvider != null) { >+ Locale currentLocale = localeProvider.getLocale(); >+ if (currentLocale != null) >+ return currentLocale; >+ } >+ return Locale.getDefault(); >+ } >+ >+ public String translate(String category, String key) { >+ return translate(getLocale(), category, key); >+ } >+ >+ public String translate(Locale locale, String category, String key) { >+ ITranslationProvider pv = getProvider(category); >+ >+ if (pv != null) { >+ return pv.translate(locale, category, key); >+ } >+ >+ throw new IllegalArgumentException("Category '" + category + "' unknown."); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ >+ private ITranslationProvider getProvider(String category) { >+ ITranslationProvider pv = providerMap.get(category); >+ if (pv == null) { >+ pv = tryCreateBundleLocalization(category); >+ // TODO Should we cache it? Then we need to add a tracker if the bundle is >+ // installed/uninstalled >+ } >+ >+ return pv; >+ } >+ >+ private ITranslationProvider tryCreateBundleLocalization(String category) { >+ for (Bundle b : ServicesActivator.getDefault().getContext().getBundles()) { >+ String[] parts = category.split("@"); >+ if (b.getSymbolicName().equals(parts[0]) >+ && (parts.length == 1 || parts[1].equals(b.getVersion().toString()))) { >+ final Bundle bundle = b; >+ return new ITranslationProvider() { >+ >+ public String translate(Locale locale, String category, String key) { >+ ResourceBundle resBundle = ServicesActivator.getDefault() >+ .getBundleLocalization().getLocalization(bundle, locale.toString()); >+ if (resBundle != null) { >+ try { >+ return resBundle.getString(key); >+ } catch (Exception e) { >+ return ""; //$NON-NLS-1$ >+ } >+ } >+ return ""; //$NON-NLS-1$ >+ } >+ }; >+ } >+ } >+ >+ return null; >+ } >+ >+ public String[] translate(String category, String... keys) { >+ return translate(getLocale(), category, keys); >+ } >+ >+ public String[] translate(Locale locale, String category, String... keys) { >+ ITranslationProvider pv = getProvider(category); >+ if (pv != null) { >+ String[] rv = new String[keys.length]; >+ for (int i = 0; i < keys.length; i++) { >+ rv[i] = pv.translate(locale, category, keys[i]); >+ } >+ return rv; >+ } >+ throw new IllegalArgumentException("Category '" + category + "' unknown."); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ >+ public void registerTranslationProvider(String category, ITranslationProvider provider) { >+ if (providerMap.containsKey(category)) { >+ throw new IllegalArgumentException( >+ "Can not register more than one provider for category '" + category + "'."); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ providerMap.put(category, provider); >+ } >+ >+ public void unregisterTranslationProvider(String category, ITranslationProvider provider) { >+ if (providerMap.get(category) == provider) { >+ providerMap.remove(category); >+ } >+ } >+ >+ public void dsRegisterTranslationProvider(ITranslationProvider provider, >+ Map<String, String> data) { >+ for (String s : data.get("CATEGORIES").split(";")) { //$NON-NLS-1$//$NON-NLS-2$ >+ try { >+ registerTranslationProvider(s, provider); >+ } catch (IllegalArgumentException e) { >+ // TODO: handle exception >+ } >+ } >+ } >+ >+ public void dsUnregisterTranslationProvider(ITranslationProvider provider, >+ Map<String, String> data) { >+ for (String s : data.get("CATEGORIES").split(";")) { //$NON-NLS-1$//$NON-NLS-2$ >+ unregisterTranslationProvider(s, provider); >+ } >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/e4/core/services/translation/ITranslationProvider.java >=================================================================== >RCS file: src/org/eclipse/e4/core/services/translation/ITranslationProvider.java >diff -N src/org/eclipse/e4/core/services/translation/ITranslationProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/core/services/translation/ITranslationProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,17 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 BestSolution.at and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Tom Schind<tom.schindl@bestsolution.at> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.e4.core.services.translation; >+ >+import java.util.Locale; >+ >+public interface ITranslationProvider { >+ public String translate(Locale locale, String category, String key); >+} >Index: src/org/eclipse/e4/core/services/translation/ITranslationService.java >=================================================================== >RCS file: src/org/eclipse/e4/core/services/translation/ITranslationService.java >diff -N src/org/eclipse/e4/core/services/translation/ITranslationService.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/core/services/translation/ITranslationService.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,27 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 BestSolution.at and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Tom Schind<tom.schindl@bestsolution.at> - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.e4.core.services.translation; >+ >+import java.util.Locale; >+ >+public interface ITranslationService { >+ public String translate(String category, String key); >+ >+ public String translate(Locale locale, String category, String key); >+ >+ public String[] translate(String category, String... keys); >+ >+ public String[] translate(Locale locale, String category, String... keys); >+ >+ public void registerTranslationProvider(String category, ITranslationProvider provider); >+ >+ public void unregisterTranslationProvider(String category, ITranslationProvider provider); >+} >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 331260
:
183968
|
184155
|
185001
|
185457
|
186664
|
186665
|
186735
|
186742
|
186743
|
186844