support different languages for Google reCAPTCHA

189 Views Asked by At

I am using reCaptcha API on android through SafetyNet API as given on Android Developer site. My application is multilingual application. When I all together change phones language setting, my reCaptcha appears in that language. But I want to change language according to selected locale on app level without changing phone language settings. Google docs has given language codes here. Can anyone help me with implementing this thing. Any help or any suggestion will be appreciated.

This is my current code. This works with default phone language very well.

private fun verifyGoogleReCAPTCHA() {
    SafetyNet.getClient(this)
        .verifyWithRecaptcha(CAPTCHA_API_SITE_KEY)
        .addOnSuccessListener(this@LoginActivity as Activity) { response ->
            // Indicates communication with reCAPTCHA service was
            // successful.
            val userResponseToken = response.tokenResult
            if (response.tokenResult?.isNotEmpty() == true) {
                // Validate the user response token using the
                // reCAPTCHA siteverify API.
                Log.v("token", userResponseToken)
                handleVerification(userResponseToken)
            }
        }
        .addOnFailureListener(this@LoginActivity as Activity){ e ->
            if (e is ApiException) {
                // An error occurred when communicating with the
                // reCAPTCHA service. Refer to the status code to
                // handle the error appropriately.
                Log.v("Error", "Error: ${CommonStatusCodes.getStatusCodeString(e.statusCode)}")
                Toast.makeText(
                    this,
                    "Error: ${CommonStatusCodes.getStatusCodeString(e.statusCode)}",
                    Toast.LENGTH_LONG
                ).show()
            } else {
                // A different, unknown type of error occurred.
                Log.d("Error", "Error: ${e.message}")
                Toast.makeText(this, "Error: ${e.message}", Toast.LENGTH_LONG).show()
            }
        }
}
0

There are 0 best solutions below