I am trying to display text in Indian regional languages on an Android app.
I've set up all the localization folders even though, I just want to have only one language for my app (say Punjabi).
In my strings.xml I have tried putting Hindi characters and Chinese characters and these are displayed correctly on the emulator. But when I put in Punjabi characters nothing shows up on the emulator.
Any reason for this? Can I overcome this problem?
I have the option of using a .ttf file in the assets folder for punjabi font. But that is not what I want to do because it does not give me complete control over the contents being displayed. Each .ttf behaves differently.
Any help is truly appreciated.
There is no support for local Indian languages on Android as yet. Hence the UTF-8 characters that fall outside the acceptable range for Android are ignored. Hence we see a blank being displayed.
Related
I am working on an Android app which supports few other locales apart from English (like PTBr). I get the text from server in PTBr (Brazilian Portuguese) and I display it as it is in a Text view. I have also set my phone's locale to PTBr but still don't see the complete text. A few characters are missing.
I am stressing on "server-data" since I don't have it locally, and thus I can't put it in res-string folders.
Thanks!
I have a rooted phone and was trying to play around with my phone. It has android 2.2 installed. What I want to do is to display Hndi/Tamil/Telugu text inside the application that I was trying to develop. Obviously android 2.2 does not support these fonts.
As the phone is rooted doing this was easy for one language. I just followed the tips given in this link Enable Hindi Fonts on Rooted Device and was able to get Hindi fonts throughout the system. Similar approach helped me setup Tamil fonts.
But I am not able to make both Hindi and Tamil work together. The possible solutions I can think off are :
i) Create a common ttf file which shall contain both Hindi and Tamil fonts. But I have no idea whether this is possible or not.
ii) Keep a .ttf file for each language in the assets/fonts/ folder but again this is showing just square boxes on the device.
I tried this link Display Different Languages In Applicationtoo but again this seems to work for only supported fonts.
Any guidance would be highly appreciated. Thanks
Try this sample application.I shared here the whole application code for how to display one text in multiple languages especially Kannada and Telugu.
PREAMBLE: since API 17 (Android 4.2), there's a method TextView.setTextLocale() that explicitly solves this problem for TextViews and derived classes. Assign a Japanese locale (Locale.JAPAN), and Unihan characters will look Japanese.
I have an application on Android that displays Japanese text in WebViews and TextViews. There are some Chinese characters (kanji) that look, by convention, differently in China and in Japan, but share the same Unicode codepoint. Normally, the browser would rely upon the lang tag to choose the correct glyph. On Android, they all default to their Chinese shapes, and I want Japanese shapes.
The problem is well explained in this article. This article also serves as a perfect illustration of the problem - when watched on Android (up to 2.2), the characters in the "Examples of language-dependent characters" all look the same, and Chinese.
Using the lang="ja" attribute does not help. Switching the whole system locale to Japanese does not help either.
I'm wondering about Android phones that are sold in Japan. Do characters like 直, 今, 化 look Chinese-style on those, too? I'm assuming not.
So the questions are: are there official localized images of Android out there? Can I get one to run on the emulator? Is the DroidSansFallback font still the only CJK-enabled font on those? And if it is, is it the same as on the vanilla USA Android?
I'm kind of hoping that the Japanese glyphs are hidden somewhere deep in the font (Unicode private area or something). If so, I could leverage them...
EDIT: located DroidSansJapanese.ttf, installed it on the emulator by copying into /system/fonts, restarted. It made no difference on the look of the Unihan article. Even the hint area of the Japanese text input (which should know better) displays as if Chinese.
How do I know the typeface name of the DroidSansJapanese.ttf? I have a feeling it's still Droid Sans, same as in the built-in DroidSansFallback font. But if they contain the same typeface, what governs which one should take precedence? One would think - system locale, but apparently not. Fonts in Android are installed just by copying, right?
There are fonts with full Japanese support. I've heard some people talking about DroidSansJapanese.tff and TakaoPGothic.
Found a somewhat cludgey solution.
The DroidSansJapanese.ttf font exists and is available for download, for example, here. I downloaded it, renamed it to DroidSansJapanese.mp3 to avoid the 1MB compressed asset limit, and placed it under assets/web. I then introduced the following CSS statement:
#font-face
{
font-family: "DroidJP";
src:url('DroidSansJapanese.mp3')
}
Then I added 'DroidJP' to the font-family of every relevant CSS style. The way I load my HTML, the assets/web folder is already designated as the base for loading linked content.
Upon careful examination, I found several places in the app where Japanese was in TextViews. For those, I've loaded the typeface like this:
Typeface s_JFont =
Typeface.createFromAsset(Ctxt.getAssets(), "web/DroidSansJapanese.mp3");
and called setTypeface() on every relevant TextView. Now for PROFIT!
This expanded my APK by about 1 MB. There was an alternative way, where I'd store the font in the assets in compressed form - that'd save me about 500 KB of APK size, but then I'd have to expand it to phone memory on the first run, worry about data folder path, and lose compatibility with Android 1.5.
Some credit is due: here and here. Does not work on Android 2.1 (the WebViews, not the TextViews) - that's a known bug.
Now, the question remains - how do I identify devices where the default font already contains the Japanese shapes?
EDIT re: the mp3 hack. I've implemented the chunked solution at first, but then decided to go with font in the assets. The chunked approach has one upside - smaller APK size - and the following downsides:
Consumes more phone memory - you end up storing both compressed font in assets and uncompressed in the data directory
Is incompatible with Android 1.5 on the TextView side - the method Typeface.createFromFile() was introduced in API level 4
Complicates HTML generation - the CSS with the #font-face declaration needs to be parametrised, since the data path is a variable
Slows down the first app startup - you spend time combining the chunks
Storing the font as a compressed asset is not an option either - the font then doesn't show up in WebView, and you can clearly see in LogCat the message about "Data exceeds UNCOMPRESS_DATA_MAX".
Using the following in your onCreate/OnCreateView:
AssetManager am = getContext().getApplicationContext().getAssets();
mDroidSansJapaneseTypeface = Typeface.createFromAsset(am, String.format(Locale.JAPAN, "fonts/%s", "DroidSansJapanese.ttf")); //I put the font file in the assets/fonts/ folder
And then for your textviews:
myTextView.setTypeface(mDroidSansJapaneseTypeface);
myTextView.setTextLocale(Locale.JAPAN);
Be aware that not 100% of all fonts will be displayed in Android. I haven't seen too many problems for Japanese characters, but other CJK characters may appear as blank boxes, no matter what ttf file you use.
I am working with an Arabic translator who is translating my strings.xml from english to arabic. I realize that only Honeycomb or Cyanogen roms will support arabic rendering, but that is ok.
Our problem is that the text keeps getting flipped around. It seems that some text editors (like Eclipse) blatantly do not support right-to-left text. And in some cases, the text is not flipped character by character, but word by word, or parts of the sentence get rearranged ... when copying from Microsoft Word back into the UTF-8 xml file.
For example, the translator supplied lines with spaces on each end, and naturally I wanted to clean these up. But doing so flipped some of the text around!
For example:
إغلاق التطبيق
became:
التطبيقإغلاق
just by removing spaces around the edges.
Questions:
1. What editor should I be using?
2. Is it ok to mix english and Arabic on the same line (such as the App Name or other words that should not be translated) or is this fundamentally a no-no?
I am currently working on an Arabic/English project, and I speek both languages, so I can provide you with my experience :)
Answer to Question 1:
Any editor that supports UTF8 will do. I am now using both eclipse and notepad++.
To setup eclipse with UTF8 (which is not the default for some reason), go to window menu -> preferences -> general -> workspace then change text file encoding from deault (cp1252) to other, and choose utf8, then restart eclipse.
For notepad++, ensure you install supported locales, including Arabic. It is not checked during instulation and you have to tick the checkbox to enable that feature.
Answer to Question 2:
It is absolutely fine to mix Arabic and English words together in a sentence. A very very good article I found about that is written here http://www.w3.org/International/tutorials/bidi-xhtml/
This article describes design concepts for sites that support right-to-left languages (including Arabic and Hebrew), with emphasis on Arabic due to it being a more complex language because some letters get connected to others and some do not.
Even though this article is talking about website design, it has a good amount of how Arabic and English languages should be mixed.
There a simple way to insert the right to left and left to right marks in any application under windows:
1- Right to left mark: ALT + 0254 from the right numeric pad in the keyboard
2- Left to Right mark: ALT + 0253 from the right numeric pad in the keyboard
Withouusing any special editors or macros, this can be used in any application, whether in Notepad, Word, HTML, XML... etc.
Hopefully, this would be helpful for everybody
Best regards
Your Arabic Translation Team
1- I developed few Android apps that support Arabic and I am using Notepad++ to edit the resources file without any problems. Just remember to select RTL from view menu (Ctrl+Alt+R).
Virtually all Android devices that support Unicode will display Arabic letters, but if bidi algorithm is not part of specific Android version you can use a custom library to connect letters and display Arabic correctly.
Here is a library that I used before
A Blog that describes how to use it
2- In general, I would not recommend mixing Arabic and English especially if it will involve special characters as it can be displayed awkwardly.
I know the Eclipse part, the default font in Eclipse doesnt support Unicode, So change it to "Aria Unicode MS" font. To do this in Eclipse workspace click on Windows in Menu Bar -> Preferences -> General -> Appearance -> Colors and Fonts. Now in the file explorer like menu in right, expand Basic, select "Text Font" and click on Edit.. button.
Hope this solves your viewing issue with Eclipse.
About Arabic app name issue, think on this, if you do localization correctly, then the Arabic name for app will be displayed only when the user changes the handset locale (and thus language) to Arabic, otherwise the default English app name will be displayed. So, just set the Arabic name in Arabic string.xml and English in the English one and you should be good.
As for editor part, there is no way to answer your question without knowing the platform. On Windows, standard Notepad should do.
For mixing strings, it is rather common scenario. It is typical that App Name won't get translated. Also, sometimes you need to put some English description in the brackets. You might need to play with strong directionality marks in such case (otherwise brackets would look a bit strange).
how to show hindi characters in android ,i have simple webview apllication ,it loads the url of some site which contains hindi characters ,but its showing [][][][ at place of those characters ,even the default android browser shows the same (not showing the hindi characters) the android version is 2.1, text encoding is set on unicode(UTF-8) in default android browser .,is there is any way to get the support for hindi characters
i hope my question is clear ,
Its the font-support
The Characters other than the most Basic ones, are not there in the TTF Font Files - Namely, DroidSans and DroidSansFallback
Any system needs to have the font on it to display the same.
In case of web pages, you can provide the font to the client to download and use
But in case of Android, its supposed to load characters only from DroidSans.ttf and DroidSansFallback.ttf
So if you want to view something in Hindi, these font files ( in system/fonts ) must support your characters
Your Options...
DroidSans.ttf is limited so you can't edit that. Download any font that has Hindi Character support and name it to DroidSans.ttf and replace in system/fonts.
- This will mess your default font
Download a TTF font that has Hindi Characters and Name it to DroidSansFallback.ttf and replace in system/fonts.
- This won't mess up anything & is a Better Option
Create a font using Font Designing Softwares and ADD as many characters as you wish (including HINDI) and follow the latter part of statement 2.
- The BEST Option !!
Use a Browser that has its own support for Hindi Fonts.
- Simplest option for people without ROOT *
* - Root implies Rooting of Android Device - Rooting Android
With Opera Mini browser, now you can read Indian language content on mobile phones which don't have built in unicode fonts. For this we need to turn
on the bitmap fonts in 'opera mini'
Type 'about: config' in mini address bar. This opens configuration settings.
There is a option for use bitmap fonts. Change that to Yes.
There is no way (not yet) to show any of the Indian characters of Indian languages on Android. It simply is not supported. See the following links for further information:
Link 1
Link2
It existed as a feature request, at least until 2.2. I am not sure if language support has been added for Hindi and other Indian languages from Android 2.3 and 3.0 onwards.
On a side note, does the same website work properly when you open it with a normal web browser?
Hindi is not supported in most devices.
But you still can browse Hindi websites using the app, SETT Hindi Browser if your Android version is above 2.2. It's an exclusive browser for Hindi & it displays Hindi in any device.
Here is the link: https://market.android.com/details?id=lk.bhasha.sett.hindi
Here is how it displays Hindi:
Me also struggled with this for one day but finally found a solution.
Just add these two lines of code it will work
WebSettings webSettings = webView.getSettings();
webSettings.setDefaultTextEncodingName("utf-8");