forked from cpupk/ecd
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
99 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
org.sf.feeling.decompiler/src/org/sf/feeling/decompiler/i18n/EcdResouceBundle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Chen Chao and other ECD project contributors. | ||
* 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 | ||
* https://www.eclipse.org/legal/epl-v10.html | ||
*******************************************************************************/ | ||
|
||
package org.sf.feeling.decompiler.i18n; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.text.MessageFormat; | ||
import java.util.Locale; | ||
import java.util.MissingResourceException; | ||
import java.util.ResourceBundle; | ||
|
||
public class EcdResouceBundle { | ||
|
||
protected final ResourceBundle resourceBundle; | ||
|
||
public EcdResouceBundle(Class<?> messagesClass) { | ||
ClassLoader classLoader = messagesClass.getClassLoader(); | ||
Locale targetLocale = Locale.getDefault(); | ||
String resourceBundleName = messagesClass.getPackageName() + ".messages"; | ||
this.resourceBundle = ResourceBundle.getBundle(resourceBundleName, targetLocale, classLoader); | ||
} | ||
|
||
public String getString(String key) { | ||
try { | ||
String result = resourceBundle.getString(key); | ||
try { | ||
result = new String(result.getBytes("ISO-8859-1"), "utf-8"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
} catch (UnsupportedEncodingException e) { | ||
return '!' + key + '!'; | ||
} | ||
return result; | ||
} catch (MissingResourceException e) { | ||
return '!' + key + '!'; | ||
} | ||
} | ||
|
||
/** | ||
* Gets formatted translation for current local | ||
* | ||
* @param key the key | ||
* @return translated value string | ||
*/ | ||
public String getFormattedString(String key, Object[] arguments) { | ||
return MessageFormat.format(getString(key), arguments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters