comparison dwtx/core/internal/runtime/LocalizationUtils.d @ 3:6518c18a01f7

eclipse.core package without osgi dependencies
author Frank Benoit <benoit@tionex.de>
date Wed, 26 Mar 2008 00:57:19 +0100
parents
children 46a6e0e6ccd4
comparison
equal deleted inserted replaced
2:a012107a911c 3:6518c18a01f7
1 /*******************************************************************************
2 * Copyright (c) 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtx.core.internal.runtime.LocalizationUtils;
14
15 import dwt.dwthelper.utils;
16
17 /**
18 * Helper methods related to string localization.
19 *
20 * @since dwtx.equinox.common 3.3
21 */
22 public class LocalizationUtils {
23 /**
24 * 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
26 * non-translated key.
27 *
28 * @param key case-sensetive name of the filed in the translation file representing
29 * the string to be translated
30 * @return
31 */
32 static public String safeLocalize(String key) {
33 //TODO: LocalizationUtils tries to load module CommonMessages. How to handle this?
34 // try {
35 // Class messageClass = Class.forName("dwtx.core.internal.runtime.CommonMessages"); //$NON-NLS-1$
36 // if (messageClass is null)
37 // return key;
38 // Field field = messageClass.getDeclaredField(key);
39 // if (field is null)
40 // return key;
41 // Object value = field.get(null);
42 // if (value instanceof String)
43 // return (String) value;
44 // } catch (ClassNotFoundException e) {
45 // // eat exception and fall through
46 // } catch (NoClassDefFoundError e) {
47 // // eat exception and fall through
48 // } catch (SecurityException e) {
49 // // eat exception and fall through
50 // } catch (NoSuchFieldException e) {
51 // // eat exception and fall through
52 // } catch (IllegalArgumentException e) {
53 // // eat exception and fall through
54 // } catch (IllegalAccessException e) {
55 // // eat exception and fall through
56 // }
57 return key;
58 }
59 }