comparison org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/LocalizationUtils.d @ 105:bbe49769ec18

...
author Frank Benoit <benoit@tionex.de>
date Sun, 08 Nov 2009 12:42:30 +0100
parents bc29606a740c
children
comparison
equal deleted inserted replaced
104:88652073d1c2 105:bbe49769ec18
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/ 10 *******************************************************************************/
13 module org.eclipse.core.internal.runtime.LocalizationUtils; 11 // Port to the D programming language:
12 // Frank Benoit <benoit@tionex.de>
13 module org.eclipse.core.internal.runtimeLocalizationUtils;
14 14
15 import java.lang.all; 15 import java.lang.all;
16 16
17 import org.eclipse.core.internal.runtimeCommonMessages; // packageimport
18
19 import java.lang.reflect.Field;
20
17 /** 21 /**
18 * Helper methods related to string localization. 22 * Helper methods related to string localization.
19 * 23 *
20 * @since org.eclipse.equinox.common 3.3 24 * @since org.eclipse.equinox.common 3.3
21 */ 25 */
22 public class LocalizationUtils { 26 public class LocalizationUtils {
23 /** 27 /**
24 * This method can be used in the absence of NLS class. The method tries to 28 * This method can be used in the absence of NLS class. The method tries to
25 * use the NLS-based translation routine. If it falls, the method returns the original 29 * use the NLS-based translation routine. If it falls, the method returns the original
26 * non-translated key. 30 * non-translated key.
27 * 31 *
28 * @param key case-sensitive name of the filed in the translation file representing 32 * @param key case-sensitive name of the filed in the translation file representing
29 * the string to be translated 33 * the string to be translated
30 * @return The localized message or the non-translated key 34 * @return The localized message or the non-translated key
31 */ 35 */
32 static public String safeLocalize(String key) { 36 static public String safeLocalize(String key) {
33 //TODO: LocalizationUtils tries to load module CommonMessages. How to handle this? 37 try {
34 // try { 38 Class messageClass = Class.forName("org.eclipse.core.internal.runtime.CommonMessages"); //$NON-NLS-1$
35 // Class messageClass = Class.forName("org.eclipse.core.internal.runtime.CommonMessages"); //$NON-NLS-1$ 39 if (messageClass is null)
36 // if (messageClass is null) 40 return key;
37 // return key; 41 Field field = messageClass.getDeclaredField(key);
38 // Field field = messageClass.getDeclaredField(key); 42 if (field is null)
39 // if (field is null) 43 return key;
40 // return key; 44 Object value = field.get(null);
41 // Object value = field.get(null); 45 if ( null !is cast(String)value )
42 // if (value instanceof String) 46 return cast(String) value;
43 // return (String) value; 47 } catch (ClassNotFoundException e) {
44 // } catch (ClassNotFoundException e) { 48 // eat exception and fall through
45 // // eat exception and fall through 49 } catch (NoClassDefFoundError e) {
46 // } catch (NoClassDefFoundError e) { 50 // eat exception and fall through
47 // // eat exception and fall through 51 } catch (SecurityException e) {
48 // } catch (SecurityException e) { 52 // eat exception and fall through
49 // // eat exception and fall through 53 } catch (NoSuchFieldException e) {
50 // } catch (NoSuchFieldException e) { 54 // eat exception and fall through
51 // // eat exception and fall through 55 } catch (IllegalArgumentException e) {
52 // } catch (IllegalArgumentException e) { 56 // eat exception and fall through
53 // // eat exception and fall through 57 } catch (IllegalAccessException e) {
54 // } catch (IllegalAccessException e) { 58 // eat exception and fall through
55 // // eat exception and fall through 59 }
56 // }
57 return key; 60 return key;
58 } 61 }
59 } 62 }