Back to project page journal.
The source code is released under:
MIT License
If you think the Android project journal listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package cochrane343.journal; /*from ww w . java 2s.co m*/ import static cochrane343.journal.Constants.LOGGING_TAG; import android.content.Context; import android.content.res.Resources; import android.util.Log; /** * The helper class for translating database values. * * @author cochrane34 * @since 1.0 */ public class TranslationHelper { private static final int NO_RESOURCE = 0; /** * @param original the <code>String</code> to translate * @param context the context for retrieving translation resources * @return the translation of the given <code>String</code> if a translation is found or the original * <code>String</code> if none is found */ public static String translate(final String original, final Context context) { final Resources resources = context.getResources(); final int stringId = resources.getIdentifier(original, "string", context.getClass().getPackage().getName()); if (stringId != NO_RESOURCE) { try { return resources.getString(stringId); } catch (Resources.NotFoundException e) { if (Log.isLoggable(LOGGING_TAG, Log.WARN)) { Log.w(LOGGING_TAG, "Found no translation for String: " + original); } return original; } } else { return original; } } }