Skip to content

Localization

Supported Languages

Document Reader SDK supports the following languages:

  • Arabic (ar)
  • Bangla (bn)
  • Czech (cs)
  • Danish (da)
  • German (de)
  • Greek (el)
  • English (en)
  • Spanish (es)
  • Finnish (fi)
  • French (fr)
  • Hebrew (he)
  • Hindi (hi)
  • Croatian (hr)
  • Hungarian (hu)
  • Indonesian (id)
  • Italian (it)
  • Japanese (ja)
  • Korean (ko)
  • Malay (ms)
  • Norwegian (nb)
  • Dutch (nl)
  • Polish (pl)
  • Portuguese (pt)
  • Romanian (ro)
  • Russian (ru)
  • Slovak (sk)
  • Swedish (sv)
  • Thai (th)
  • Turkish (tr)
  • Ukrainian (uk)
  • Vietnamese (vi)
  • Chinese Simplified (zh-Hans)
  • Chinese Traditional (zh-Hant)

Customizing Localization

If any language is required by your application but is not supported by Document Reader SDK, or you want to change our localized strings, you can add localized strings to strings.xml file and allow the Document Reader SDK to be presented to the users in their desired system locale. To do it, you need to know the identifiers of the strings that are available in the values.xml file provided with the latest release version. You can redefine every string in Document Reader SDK with the appropriate translated values. This way, when the user has their device's System Language set to a language supported by your application, the SDK will utilize the appropriate string resources.

The values.xml file with all available strings can be found in the project: External Libraries -> Gradle: com.regula.documentreader:api:X.X.X@aar -> values -> values.xml

Info

For more information on localizing your application and best practices, please see the official Android documentation.

Changing the app's language programmatically

If you wish to allow users to change the app's language right in the app, you can apply the following code snippet to your code (changing to Spanish is demonstrated there):

public class ContextUtils extends ContextWrapper {
    public ContextUtils(Context base) {
        super(base);
    }

    public static ContextWrapper updateLocale(Context context, Locale localeToSwitchTo) {
        Resources resources = context.getResources();
        Configuration configuration = resources.getConfiguration();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            LocaleList localeList = new LocaleList(localeToSwitchTo);
            LocaleList.setDefault(localeList);
            configuration.setLocales(localeList);
        } else {
            configuration.locale = localeToSwitchTo;
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
            context = context.createConfigurationContext(configuration);
        } else {
            resources.updateConfiguration(configuration, resources.getDisplayMetrics());
        }

        return new ContextUtils(context);
    }
}
class ContextUtils(base: Context?) : ContextWrapper(base) {
    companion object {
        fun updateLocale(context: Context, localeToSwitchTo: Locale?): ContextWrapper {
            var context: Context = context
            val resources: Resources = context.getResources()
            val configuration: Configuration = resources.getConfiguration()
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                val localeList = LocaleList(localeToSwitchTo)
                LocaleList.setDefault(localeList)
                configuration.setLocales(localeList)
            } else {
                configuration.locale = localeToSwitchTo
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
                context = context.createConfigurationContext(configuration)
            } else {
                resources.updateConfiguration(configuration, resources.getDisplayMetrics())
            }
            return ContextUtils(context)
        }
    }
}

In your application class, you should modify the attachBaseContext method:

public class MainApplication extends Application {        
    @Override
    protected void attachBaseContext(Context newBase) {
        Locale localeToSwitchTo = new Locale("es");
        ContextWrapper localeUpdatedContext = ContextUtils.updateLocale(newBase, localeToSwitchTo);

        super.attachBaseContext(localeUpdatedContext);
    }
}
class MainApplication : Application() {
    override fun attachBaseContext(newBase: Context?) {
        val localeToSwitchTo = Locale("es")
        val localeUpdatedContext = ContextUtils.updateLocale(newBase, localeToSwitchTo)
        super.attachBaseContext(localeUpdatedContext)
    }
}

In your activity class, you should also modify the attachBaseContext method:

public class MainActivity extends AppCompatActivity {        
    @Override
    protected void attachBaseContext(Context newBase) {
        Locale localeToSwitchTo = new Locale("es");
        ContextWrapper localeUpdatedContext = ContextUtils.updateLocale(newBase, localeToSwitchTo);

        super.attachBaseContext(localeUpdatedContext);
    }
}
class MainActivity : AppCompatActivity() {
    override fun attachBaseContext(newBase: Context?) {
        val localeToSwitchTo = Locale("es")
        val localeUpdatedContext = ContextUtils.updateLocale(newBase, localeToSwitchTo)
        super.attachBaseContext(localeUpdatedContext)
    }
}

Here is the alternative solution with deprecated API:

Configuration configuration = getResources().getConfiguration();
configuration.setLocale(new Locale("es"));
getResources().updateConfiguration(configuration,  getResources().getDisplayMetrics());
getApplicationContext().getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
val configuration: Configuration = resources.configuration
configuration.setLocale(Locale("es"))
resources.updateConfiguration(configuration, resources.displayMetrics)
applicationContext.resources.updateConfiguration(configuration, resources.displayMetrics)

Warning

Make sure that you have updated configuration for resources also for allicationContext.