How to set Default language other than english in Android? - android

I have a project by my client that has built successfully in his system but as he sent to me I am unable to compile it because of unicode characters (Latin characters) in default strings.xml under res. I believe its the default localizations file but its forcing me to convert it into English but not parsing Latin Characters into it.
e.g.
<string name="old_questions">Questões e soluções dos anos anteriores</string>

Check that the XML is in UTF-8 and has
<?xml ... encoding="UTF-8"?>
or defaulted
<?xml ... ?>
I tried your text in my studio , well it is working fine. You could also update question with your error , that would help understand it better.
Another workaround for small texts would be to simply escape it.
<string name="Example">Example character \u0026</string>
go to this website : https://unicode-table.com/en/#control-character and this could help you .

Make sure your string file is in the default values folder.
You can check the android developers link for better understanding.
To help you better please post the exact error you get while compiling the code.

Related

Is it possible to include an emoji in an Android string resource

I would like to include an emoji in an Android String ressource in an XML file and I wanted to ask if this is possible or not?
I tried the solution suggested in Emoji in strings.xml file?:
<string name="message">Your rating was submitted successfully. Thank you👈!</string>
But this does not work. After "Thank you" nothing is displayed. Any idea how I can change that?
You can use this website: https://getemoji.com/
Go to this website and you will able to literally copy paste emojis in your string file. (No codes required)

Android - Convert Unicode to HTML Entity

As mentioned in Emoji in strings.xml file? you need to use Unicode smileys like these:
https://apps.timwhitlock.info/emoji/tables/unicode
as HTML Entity but why didn't he mentioned how to convert them to HTML Entity.
I tried all kind of online converters like https://www.online-toolz.com/tools/text-html-entities-convertor.php but they don't convert stuff like U+1F601 to anything.
Can someone enlighten me?
This is easier than you might think: U+1F601 corresponds to 😁.
Slight modification to Henry's answer, You may use as follows.
<string name="hello_world">Hello world! 😁</string>
// this is using in decimal
But I have found that it is giving run time errors in Lollipop and below.
It works on marshmallow and above.

Android application name error

I tried to build an android application, when I use non-english langues like persian as name of application it causes this error AndroidManifest.xml file missing and no manifest builds but when I use english it works successful, why?
at the top of every XML file in Android you'll see
<?xml version="1.0" encoding="utf-8"?>
So first I ask you: is persian included in utf-8 encoding?
I had a quick look on this link http://www.utf8-chartable.de/ and it seems to be me that's a no but I'm no language expert and that table might show persian as one of it related or base languages (like portuguese uses latin set)
If persian is not available in the utf-8 your best option to try to get this name in the app name is to create a strings_per.xml (inside the /values/ folder) and in there you put a different encoding and the string you need for the app name.
note that I tried to isolate the problematic variable in its own file because I'm not sure it would be a good idea to mix it with the rest of the manifest.
Farsi IS included in UTF8.
You need to add a string in strings.xml in /res/values.
Then define a farsi name there.
Your string.xml will look like this:
<string name="app_name">اسم اپ</string>
<string name="title_tab1">تماس با ما</string>
<string name="action_settings">Settings</string>
And you will reference it in you manifest.xml like this:
android:label="#string/app_name"
But remember: Farsi characters are not perfectly shown in android 2.2 and 2.3.
The characters are displayed separately. For later androids this is not an issue.

How to put Hebrew character in Android JAVA file?

For Android Platform:
I need to put Hebrew Character ₪ and some more like אורנג in string to check with the incoming data in java file. When I put this character It shows an error like "Some characters can not be mapped using "Cp1252" character encoding. Either change the encoding or remove the characters which are not supported by the "Cp1252" character encoding". These values are coming from SQLite database. Please see the attached snap. How can I solve this? Kindly give me some useful suggestions. Looking forward to hear from anybody who has a suggestion for me. Thanks.
Please open your eclipse.ini file from your eclipse folder with Note Pad and put the following permission into that.
-Dfile.encoding = UTF-8
Some more options as well:
For setting the encoding on a per WorkSpace basis, use Preferences->General->Workspace
To set the encoding on a per project basis open project properties and change to UTF-8
Hope this one help.
I think you'll need UTF-8 encoding for that.
These things are a little bit confusing. Reading this might clear some of the mist around encodings and character sets.
I think this may useful to you.
Keep this hebrew word in string.xml file. You can retrieve as
in String.xml
place hebrew word here
In java code:
String s=getString(R.string.hebrew_word);
Use this string as you want..

writing some characters like '<' in an xml file

since the beginning of my programmation, I used some special character like "<-", ""<<" im my string.xml in Eclipse while developping for Android.
All worked fine for one year, but today, i just wanted to make some minor changes and began to edit my xml files.
I get now compilation error on these characters because eclipse believe it's part of the xml blocks.
Any idea on how I could add this symbol "<" in my xml files?
Thank a lot.
Use
< for <
> for >
& for &
Another way to insert special character follow Moss guide: How can I write character & in android strings.xml by used Unicode definition:
Example:
<string name="item_unknown">\u003c Item Unknown \u003e</string>
which present in string :
< Item Unknown >
I stumbled upon this question, as I use HTML markup in my strings.
If you refer to the Android String Resources documentation,
in the section:
"Styling with HTML markup"
you will see that in strings.xml, you need to use &amplt; for an opening bracket, but you can safely use backslash and a closing bracket. For example:
<b>Text</b>
can be written as:
<b>Text</b>
in your strings.xml.
If using this HTML string in your code, you can use:
Html.fromHtml( getResources().getString(R.string.yourHTMLString )
and the output will be your bold string!

Categories

Resources