cld3 binding

This commit is contained in:
M66B
2021-01-18 22:57:15 +01:00
parent 01328483f5
commit 77674b0730
2 changed files with 29 additions and 0 deletions

View File

@@ -41,11 +41,23 @@ import java.util.Locale;
import java.util.Set;
public class TextHelper {
static {
System.loadLibrary("fairemail");
}
private static native String jni_language(byte[] octets);
static Locale detectLanguage(Context context, String text) {
// Why not ML kit? https://developers.google.com/ml-kit/terms
if (TextUtils.isEmpty(text))
return null;
if (BuildConfig.DEBUG) {
// https://github.com/google/cld3
String lang = jni_language(text.getBytes());
return Locale.forLanguageTag(lang);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
return null;