How to check specific language supported by device in android

Locale.getAvaialableLocales() provides you with all the locales available on the device. but the device installs fonts that support only some of the available locales.

I used Resources.getSystem().getAssets().getLocales() It returns the list languages ​​available in the options "-> Language and Inputs → Language" .

But the device is able to support more languages ​​that do not exist in "settings → Language and Inputs → Language" .

For example In my device Karbon Resource.getSystem (). GetAssets (). GetLocales () returns only Hindi and Punjabi as supporting languages. But this device works great when choosing the Telugu language using the Trekking app.

So, is there a way we can verify a specific language is supported by the device.

0
android
source share
2 answers

Good question Shiva.

Until now, many have discussed the same, ending without an answer.

google group discussion here

Neither Locale.getAvailableLocales() nor Resources.getSystem().getAssets().getLocales() gives you the correct set of locales, on which you can depend on the application language support.

The reason is

Both of them give you a list of all the locales supported by this OS. There may be more than 100 languages ​​supported by the OS, but the device manufacturer cannot place all these language fonts (ttf files) in / system / fonts / (or any system font) just to save ROM memory. What they do, since they make specific regions of the region, they only put the fonts (locales) that are associated with this percussion region. It is for this reason that you will not find Indian regional languages ​​in America.

The best way to solve this is to include all the ttf files in your application assets for any languages ​​you want to support, just as we support different language strings.

But take care of font licensing and all.

Hope this helps.

+3
source share

I have done the following:

Call the method as follows:

 isSupported(context,"English") //here "English" is the hardcoded string in specific language like Hindi,Urdu,panjabi .....etc. 

The supported method will return true if the device has the ability to draw a specific language font with another wise return false.

 public static boolean isSupported(Context context, String text) { final int WIDTH_PX = 200; final int HEIGHT_PX = 80; int w = WIDTH_PX, h = HEIGHT_PX; Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap.Config conf = Bitmap.Config.ARGB_8888; Bitmap bitmap = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap Bitmap orig = bitmap.copy(conf, false); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.rgb(0, 0, 0)); paint.setTextSize((int) (14 * scale)); // draw text to the Canvas center Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); int x = (bitmap.getWidth() - bounds.width()) / 2; int y = (bitmap.getHeight() + bounds.height()) / 2; canvas.drawText(text, x, y, paint); boolean res = !orig.sameAs(bitmap); orig.recycle(); bitmap.recycle(); return res; } 

Hope this helps you!

0
source share

All Articles