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.
Related
How can I in my android apps allow for several languages in the easiest way possible? I have seen bigger projects use xml files, and the coding of those isn't hard, but I can't seem to integrate it into the code. The other way which is actually very tricky is using booleans but that would require several languages from the start, and I can only supply 2 at this point.
The languages have to be easy to integrate at a late state, so it doesn't require changing several thousand lines, but the initial work has to be done in an early state(the late state integration is for the languages, the early is for support of it)
I'm using android studio
You should read the documentation. It's surprisingly very easy to incorporate multiple languages in your app as you just need to move all your strings into values/strings.xml and then provide other languages with the same string ids but different values at values-[LANGUAGE_ISO_CODE]/strings.xml.
Example
values/strings.xml
<resources>
<string name="app_name">Something</string>
</resources>
For Arabic language
values-ar/strings.xml
<resources>
<string name="app_name">شئ</string>
</resources>
To add support for more locales, create additional directories inside res/.
Each directory's name should adhere to the following format:
-b+[+] For example, values-b+es/ contains string resources for locales with the language code es.
Similarly, mipmap-b+es+ES/ contains icons for locales with the es language code and the ES country code.
Android loads the appropriate resources according to the locale settings of the device at runtime.
For example, the following are some different resource files for different languages: English strings (default locale), /values/strings.xml:
<resources>
<string name="hello">Hello</string>
</resources>
French strings (fr locale), /values-fr/strings.xml:
<resources>
<string name="hello">Bonjour</string>
</resources>
Use the Resources in your App:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello" />
Define all your text in your strings.xml file and avoid hard-coding your text into your app. You can use a third-party translation service to perform all your translations for you.
there are two ways to do so:
using systme's language: to detect the system language and then the app will launch with
this system's language.To do so,
1. first , you need to have all strings of the app not hard coded, meaning you have to have them all defined in the strings file under values folder
2. go to the strings file and on the top toolbar choose the globe icon and choose the second language you want to add.
3. the system will provide you with a translator where to translate each word of your defined strings.
4. once completed , the system will automatically add new strings file under value folder with the second language.
5. now if you change the phone system's language to the second language , the app will open with the second language automatically.
second way to support language without changing the system's language:
1. develop your code with the main language completely
2. you need ,preferably, to avoid hard coding the strings as well. so define all stings in the string file
for each language you want to add, repeat the activities you want to translate with the new language
add button for each language you need to add to the app
code onclicklistener for each button that will direct the app to the activities of its language
Let me specify the problem first.
My app is designed for text mainly in Hindi, and I want to target Android OS below 4.1, which doesn't support hindi characters(yes, I've tried various Hindi fonts, which don't work properly, or the desired outcome is not the expected one).
So, I've prepared icons with hindi text, and all works perfectly fine now.
The problem left with is, how can I specify hindi text for the launcher icon?
I've tried to specify hindi text by creating an image with hindi text, and left the application:label ="" and activity:label="" blank.
But the text doesn't appear in where the app name should have appeared, or apparently I didn't create the image correctly.
Any help in this regard would be appreciated :)
I hope you already have tried Krutidev (Hindi Font), if not you can try it.
Though it may late to answer now, but as i read this now, i would like to answer since I did the same in my application in the following way:
1. Just in application tag of your app's manifest, give app name as normal:
android:label="#string/app_name"
2. in resource file strings.xml, add a string 'app_name' with the name your want for your app. Be careful, what i did was: i typed the text using Google transliteration and i gave this in Hindi.
3. Then when you save your strings.xml, it will ask you to save this in proper encoding, then choose 'utf-8', and that's it.
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.
I'm currently using an EditText field with a grey background. My problem is that when auto-correction happens, you can't see the grey auto-corrected words against the grey background. Is there a way to change the default font used by auto-correct?
You can configure the appearance of pretty much everything by theming your application. That would also be the way to go to customize the appearance of your EditText.
Read the Styles and Themes guide at Android Developers.
I recommend you have a look at the themes.xml file of the emulator of your target platform. It's located in android-sdk/platforms/android-X/data/res/values.
I have a current Android app that uses i18n via resources. res/values-es/strings.xml and so on. When I test it on a device with the language set to Espanol it pulls the correct resources, from the values-es file, but the accent characters are way out of whack.
For example, I want to use the lowercase o with an accent (ó). I have tried with the actual character in the strings.xml file (using the character map on Ubuntu to create the string) and with the entity, in either case it comes out like some other character set accent I don't recognize:
The same character looks perfect WITHIN strings.xml when using many different text editors. And the file is UTF-8 (tried recreating it with the Android "wizard" tool in Eclipse to make sure).
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="label_app_version">Versión</string>
</resources>
Now I've used French, and German before in other Android apps, with all sorts of accents, and haven't seen this problem, so I'm entirely confused at the moment. What am I doing wrong this time?
I finally solved this one. I was using a font and calling setTypeface earlier in the code. The font I'm using must not have the special characters needed for the other languages. I need to check to make sure my user's are using a locale that my font supports before setting the font.
I should have realized this and checked it earlier.
So the bottom line is this, if you get strange results with certain characters in different locales, make sure you're not using fonts that don't support those characters. Fall back to not using a font (don't call setTypeface) and test that way.
That diacritic is actually called a breve, common in many eastern european languages. I had the same problems before once. I even have a question here on SO. Since nobody solved the problem, it's worth the shot...
This isn't clear to me yet:
Does it happen only on this project? Did you try others? (maybe a project mistake)
Try including other language folders (try, say, values-fr). Do you have the same problem?
Did you try to build your app inside Eclipse? Did you try building manually on the command line?
Then, you could try:
Instead of the "ó" (here in PT we use the same), try \u00f3. Like: Versi\u00f3n. Do you get the proper latin small o with acute? Just to clear things.
Build your app using ant ($ ant release) manually on the command line. Report back the results.
This may help the guys here (who are much more experienced than I am) guess where the problem can be.
Best regards!
Check how the actual strings.xml file is stored.
In the file tree in Eclipse, right-click on the strings.xml file and select properties.
You will get a properties dialog for the file.
If not selected already, select the "Resource" line in the left column.
Check the "Text file encoding" area at the bottom.
It maybe selected as "default" or a specific encoding such as "UTF-8" selected.
Select the UTF-8 option. Save file. Clean & Build project (to re-gen resources) and then see if any changes.
See attached screenshot.
Suerte, Andrew
This is strange as it should not cause a problem. Maybe you should try to embed string into CDATA section, like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="label_app_version"><![CDATA[Versión]]></string>
</resources>