Android Open Source - journal Translation Helper






From Project

Back to project page journal.

License

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.

Java Source Code

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;
       }
    }
}




Java Source Code List

cochrane343.journal.Constants.java
cochrane343.journal.CurrencyHelper.java
cochrane343.journal.DateTimeHelper.java
cochrane343.journal.ExpenseEditListener.java
cochrane343.journal.ExpensesListAdapter.java
cochrane343.journal.MainActivity.java
cochrane343.journal.MonthlyExpensesFragment.java
cochrane343.journal.MonthlyExpensesPagerAdapter.java
cochrane343.journal.SettingsActivity.java
cochrane343.journal.TranslationHelper.java
cochrane343.journal.contentprovider.JournalContentProvider.java
cochrane343.journal.contentprovider.JournalContract.java
cochrane343.journal.contentprovider.JournalDatabaseHelper.java
cochrane343.journal.dialogs.CategorySpinnerAdapter.java
cochrane343.journal.dialogs.ExpenseDialogFragment.java
cochrane343.journal.dialogs.ExpenseDialogListener.java
cochrane343.journal.exceptions.IllegalDisplayModeException.java
cochrane343.journal.exceptions.IllegalLoaderIdException.java
cochrane343.journal.exceptions.IllegalUriException.java
cochrane343.journal.exceptions.MissingFragmentArgumentException.java