Regardless of locale I want to write Android app code which applies fonts based on this app keyboard selected (soft input selected).
if (keyboard language is persian) {
apply font family persianFont and do not apply this font on existing characters
}
else if (language is English) {
apply Signika font and do not apply this font on existing characters
}
else (for every other language) use default fonts operating system allows
If you answer the question please note:
I need code to detect keyboard language and apply font family and font sizes in that language without affecting existing text.
Thanks
There's no way to do this. Keyboards are separate apps, and they handle language display on their own. There is no API for the OS to query what language they're displaying, or for the keyboard to tell the OS what language its using. The best you can do is get the OS locale, which is they language the user requested for strings to be displayed in. But you cannot detect if their keyboard is set to a language other than the locale.
Related
I'm working on a multi-language React Native application. When the user's app is in Arabic or Persian language, a font with Arabic digits will be used. And when they are in other languages (like English), a font with English digits will be used. One of our customers sent me the image below. The thing is their app is in English language but their phone's language settings is set to Persian language and so I think their device's settings is messing up the fonts in application. I expect all digits to be in English (since this is the behavior on my own Android phone with English language settings), but as you can see in the image below, all the digits before decimal points are shown in Arabic numbers. Is there a way to stop such behavior? For example once I had a problem with Android's dark theme getting applied to my application and ruining the colors but I added the following code to android/app/src/main/res/values/styles.xml and the problem was fixed.
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:forceDarkAllowed">false</item>
<!-- Customize your theme here. -->
</style>
I mean, isn't there a similar solution like adding a property somewhere in AndroidManifest.xml, styles.xml, etc. to fix this issue?
Thanks in advance.
Ok. After lots of investigation, I found that the problem was from my own code and not from Android OS. I had created a method called withCommas to format numbers with comma separation and stuff.
Number.prototype.withCommas = function () {
const splitArray = this.toString().split('.')
if (splitArray.length === 1) return parseFloat(splitArray[0]).toLocaleString();
return parseFloat(splitArray[0]).toLocaleString() + '.' + splitArray[1]
}
Now the problem is obvious. You have to explicitly tell the String.toLocaleString to use en-US locale (which I forgot). If you don't specify the locale, it will use whatever locale that the user's device is on. So I changed all toLocaleString() appearances with toLocaleString("en-US") and the problem is solved now.
can I change the referring a resource folders programmaticaly. I need to use a language that is not supported by android, in my case Sinhala. can I create a values_sin folder and refer it when user select Sinhala language. can I change the font together with that for entire application.
How about this: put your Sinhala strings in res/values/strings.xml, and the English strings in res/values-en/strings.xml or maybe even better, in res/values-en-rIN/strings.xml. When using the second method, your app will be in English only if the user selects "English (India)" as the phone's language. In any other case, the default resources will be used - which in your case will be in Sinhala!
Edit 2: actually, Android does support Sinhalese, using res/values-si. If you can't select Sinhalese as your device's default language, you could change it at runtime. There are plenty of posts already, such as Changing Locale within the app itself
In my app,i have used 'locale' to change language hindi in programatically.and i also used .ttf file to convert title of app sub page in hindi language.but when i change language ,the other control change language automatically..for ex,datepicker etc,
when i have to set value in textview directly,its value can't be converted in hindi .but when i have some changes regarding that value and after set value in textview,then it will convert hindi language automaetically.please give me some solution of this.
Thank you.
I can tell you from my own experiences that it will result in strange behaviour when changing the language "manually". It is not recommended. Sometimes even changing the device orientation will overwrite your changes due to the changed configuration. Just be aware that this approach is not supported or intended by Android.
Am doing a danish project, so when i long press in the edit text box i need the "Edit", "copy", "paste" etc commands in danish. In my phone there is no danish language can be selected.
any help is appreciated.
thanks in advance....
jibysthomas
I think you have to use Typeface for using Danish language without selecting Danish language from your phone language.
And for long press dialog I think you have to make your custom dialog and use that. I am not sure but this is my idea.
Thanks.
I use "Scandinavian keyboard " and when i need it press and hold the input box and change the "input method" to this keyboard
https://play.google.com/store/apps/details?id=com.android.inputmethod.norwegian&hl=es
hope it works 4 you
Your Android build must support each localization for the system menus to appear in the desired language. Yes it is possible to support a language by overriding the system menus but if you use Danish as your default language in the app and the system language is set to Danish the system menus will appear in Danish.
Download a custom locale app from the market and use it to change your phone locale to Danish. In your app, you then need to support localization. Read this document on localization. It helped me a lot when I was localizing an app. Briefly, you will need to create a "values-da" folder under res, create strings.xml and define the strings you need with your Danish values. Don't forget that you need to have a strings.xml file in your regular "values" folder as well with all the strings defined. This folder represents the default string values, and is useful to fall back on if a string is not found in your "values-da" folder.
Trust me, the whole process is actually a lot easier than it sounds.
Im trying to build aosp for my devkit, and i'd like to know where
should i look to for :
to changing font size of texts
in settings section ( i've replaced
droid fonts with another one but the
new font kind large) or global font
setting.
to change position of texts in
settings section ( usually all texts
are
in left side, i want to try and put it in right side for example).
the language locale names that
showed in settings/language &
keyboards.. where are they stored .
i looked into LocalePicker.java but
could not figure it out.
For example i want to change a locale name from english to it's native
language (In some android builds i've seen arabic locale was in english, and
some other builds it was shown in native arabic العربية).