با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
می توانید از ML Kit برای شناسایی زبان رشته ای از متن استفاده کنید. میتوانید محتملترین زبان رشته را دریافت کنید یا برای همه زبانهای احتمالی رشته امتیازات اطمینان کسب کنید.
ML Kit متن را به 103 زبان مختلف در اسکریپت های اصلی آنها تشخیص می دهد. علاوه بر این، متن رمانسازی شده را میتوان به زبانهای عربی، بلغاری، چینی، یونانی، هندی، ژاپنی و روسی تشخیص داد.
برای شناسایی زبان یک رشته، نمونه ای از FirebaseLanguageIdentification را دریافت کنید و سپس رشته را به متد identifyLanguage() ارسال کنید.
به عنوان مثال:
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.// ...}});
اگر تماس با موفقیت انجام شود، یک کد زبان BCP-47 به شنونده موفق ارسال می شود که زبان متن را نشان می دهد. لیست کامل زبان های پشتیبانی شده را ببینید. اگر هیچ زبانی به طور مطمئن شناسایی نشد، کد und (نامشخص) ارسال می شود.
بهطور پیشفرض، ML Kit تنها زمانی مقداری غیر از und برمیگرداند که زبان را با مقدار اطمینان حداقل 0.5 شناسایی کند. میتوانید این آستانه را با ارسال یک شی FirebaseLanguageIdentificationOptions به getLanguageIdentification() تغییر دهید:
برای بدست آوردن مقادیر اطمینان محتمل ترین زبان های رشته، نمونه ای از FirebaseLanguageIdentification را دریافت کنید و سپس رشته را به متد identifyAllLanguages() ارسال کنید.
به عنوان مثال:
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.// ...}});
اگر تماس با موفقیت انجام شود، لیستی از اشیاء IdentifiedLanguage به شنونده موفقیت ارسال می شود. از هر شی، می توانید کد BCP-47 زبان و اطمینان از اینکه رشته در آن زبان است را دریافت کنید. لیست کامل زبان های پشتیبانی شده را ببینید. توجه داشته باشید که این مقادیر اطمینان از اینکه کل رشته در زبان داده شده است را نشان می دهد. ML Kit چندین زبان را در یک رشته شناسایی نمی کند.
به طور پیشفرض، ML Kit فقط زبانهایی را با مقادیر اطمینان حداقل 0.01 برمیگرداند. میتوانید این آستانه را با ارسال یک شی FirebaseLanguageIdentificationOptions به getLanguageIdentification() تغییر دهید:
تاریخ آخرین بهروزرسانی 2025-09-06 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-06 بهوقت ساعت هماهنگ جهانی."],[],[],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`."]]