FirebaseLanguageIdentificationlanguageIdentifier=FirebaseNaturalLanguage.getInstance().getLanguageIdentification();languageIdentifier.identifyLanguage(text).addOnSuccessListener(newOnSuccessListener<String>(){@OverridepublicvoidonSuccess(@NullableStringlanguageCode){if(languageCode!="und"){Log.i(TAG,"Language: "+languageCode);}else{Log.i(TAG,"Can't identify language.");}}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptione){// Model couldn’t be loaded or other internal error.// ...}});
FirebaseLanguageIdentificationlanguageIdentifier=FirebaseNaturalLanguage.getInstance().getLanguageIdentification();languageIdentifier.identifyAllLanguages(text).addOnSuccessListener(newOnSuccessListener<String>(){@OverridepublicvoidonSuccess(List<IdentifiedLanguage>identifiedLanguages){for(IdentifiedLanguageidentifiedLanguage:identifiedLanguages){Stringlanguage=identifiedLanguage.getLanguageCode();floatconfidence=identifiedLanguage.getConfidence();Log.i(TAG,language+" ("+confidence+")");}}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptione){// Model couldn’t be loaded or other internal error.// ...}});
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[],[],null,["You can use ML Kit to identify the language of a string of text. You can\nget the string's most likely language or get confidence scores for all of the\nstring's possible languages.\n\nML Kit recognizes text in 103 different languages in their native scripts.\nIn addition, romanized text can be recognized for Arabic, Bulgarian, Chinese,\nGreek, Hindi, Japanese, and Russian.\n\n\u003cbr /\u003e\n\nBefore you begin\n\n1. If you haven't already, [add Firebase to your Android project](/docs/android/setup).\n2. Add the dependencies for the ML Kit Android libraries to your module (app-level) Gradle file (usually `app/build.gradle`): \n\n ```carbon\n apply plugin: 'com.android.application'\n apply plugin: 'com.google.gms.google-services'\n\n dependencies {\n // ...\n\n implementation 'com.google.firebase:firebase-ml-natural-language:22.0.0'\n implementation 'com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.7'\n }\n ```\n\nIdentify the language of a string\n\nTo identify the language of a string, get an instance of\n`FirebaseLanguageIdentification`, and then pass the string to the\n`identifyLanguage()` method.\n\nFor example: \n\n FirebaseLanguageIdentification languageIdentifier =\n FirebaseNaturalLanguage.getInstance().getLanguageIdentification();\n languageIdentifier.identifyLanguage(text)\n .addOnSuccessListener(\n new OnSuccessListener\u003cString\u003e() {\n @Override\n public void onSuccess(@Nullable String languageCode) {\n if (languageCode != \"und\") {\n Log.i(TAG, \"Language: \" + languageCode);\n } else {\n Log.i(TAG, \"Can't identify language.\");\n }\n }\n })\n .addOnFailureListener(\n new OnFailureListener() {\n @Override\n public void onFailure(@NonNull Exception e) {\n // Model couldn't be loaded or other internal error.\n // ...\n }\n });\n\nIf the call succeeds, a\n[BCP-47 language code](//en.wikipedia.org/wiki/IETF_language_tag) is\npassed to the success listener, indicating the language of the text. See the\n[complete list of supported languages](/docs/ml-kit/langid-support). If no\nlanguage could be confidently detected, the code `und` (undetermined) is passed.\n\nBy default, ML Kit returns a value other than `und` only when it identifies\nthe language with a confidence value of at least 0.5. You can change this\nthreshold by passing a `FirebaseLanguageIdentificationOptions` object to\n`getLanguageIdentification()`: \n\n FirebaseLanguageIdentification languageIdentifier = FirebaseNaturalLanguage\n .getInstance()\n .getLanguageIdentification(\n new FirebaseLanguageIdentificationOptions.Builder()\n .setIdentifyLanguageConfidenceThreshold(0.34f)\n .build());\n\nGet the possible languages of a string\n\nTo get the confidence values of a string's most likely languages, get an\ninstance of `FirebaseLanguageIdentification`, and then pass the string to the\n`identifyAllLanguages()` method.\n\nFor example: \n\n FirebaseLanguageIdentification languageIdentifier =\n FirebaseNaturalLanguage.getInstance().getLanguageIdentification();\n languageIdentifier.identifyAllLanguages(text)\n .addOnSuccessListener(\n new OnSuccessListener\u003cString\u003e() {\n @Override\n public void onSuccess(List\u003cIdentifiedLanguage\u003e identifiedLanguages) {\n for (IdentifiedLanguage identifiedLanguage : identifiedLanguages) {\n String language = identifiedLanguage.getLanguageCode();\n float confidence = identifiedLanguage.getConfidence();\n Log.i(TAG, language + \" (\" + confidence + \")\");\n }\n }\n })\n .addOnFailureListener(\n new OnFailureListener() {\n @Override\n public void onFailure(@NonNull Exception e) {\n // Model couldn't be loaded or other internal error.\n // ...\n }\n });\n\nIf the call succeeds, a list of `IdentifiedLanguage` objects is passed to the\nsuccess listener. From each object, you can get the language's BCP-47 code and\nthe confidence that the string is in that language. See the\n[complete list of supported languages](/docs/ml-kit/langid-support). Note that\nthese values indicate the confidence that the entire string is in the given\nlanguage; ML Kit doesn't identify multiple languages in a single string.\n\nBy default, ML Kit returns only languages with confidence values of at least\n0.01. You can change this threshold by passing a\n`FirebaseLanguageIdentificationOptions` object to\n`getLanguageIdentification()`: \n\n FirebaseLanguageIdentification languageIdentifier = FirebaseNaturalLanguage\n .getInstance()\n .getLanguageIdentification(\n new FirebaseLanguageIdentificationOptions.Builder()\n .setIdentifyAllLanguagesConfidenceThreshold(0.5f)\n .build());\n\nIf no language meets this threshold, the list will have one item, with the value\n`und`."]]