Android examples for Graphics:Spannable
Map the given ISO 639-1 language code to a name of a language, for example, "Spanish"
/*/* w w w.j a va 2 s . c o m*/ * Copyright 2011 Robert Theis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.content.Context; import android.content.res.Resources; import android.util.Log; import com.android.ashish.release.myOCR.R; public class Main{ public static final String TAG = "LanguageCodeHelper"; /** * Map the given ISO 639-1 language code to a name of a language, for example, * "Spanish" * * @param languageCode * ISO 639-1 language code * @return name of the language. For example, "English" */ public static String getTranslationLanguageName(Context context, String languageCode) { Resources res = context.getResources(); String[] language6391 = res .getStringArray(R.array.translationtargetiso6391_google); String[] languageNames = res .getStringArray(R.array.translationtargetlanguagenames_google); int len; // Finds the given language code in the translationtargetiso6391 array, and takes the name // with the same index from the translationtargetlanguagenames array. for (len = 0; len < language6391.length; len++) { if (language6391[len].equals(languageCode)) { Log.d(TAG, "getTranslationLanguageName: " + languageCode + "->" + languageNames[len]); return languageNames[len]; } } // Now look in the Microsoft Translate API list. Currently this will only be needed for // Haitian Creole. language6391 = res .getStringArray(R.array.translationtargetiso6391_microsoft); languageNames = res .getStringArray(R.array.translationtargetlanguagenames_microsoft); for (len = 0; len < language6391.length; len++) { if (language6391[len].equals(languageCode)) { Log.d(TAG, "languageCode: " + languageCode + "->" + languageNames[len]); return languageNames[len]; } } Log.d(TAG, "getTranslationLanguageName: Could not find language name for ISO 693-1: " + languageCode); return ""; } }