How do you handle extra strings lines added by translators? - android

I recently started getting translations into 5 languages for an app I'm working on. When I got the translated strings back, there were a bunch of extra lines added around any tags like <b> or xliff:g. In cases where the text before/after the tag was not a space (e.g. it was punctuation), the extra line causes Android to show an extra space. For example, consider the following string in English:
<string name="welcome_title">Welcome to <xliff:g id="app_name">App Name</xliff:g>!</string>
Pretty simple, right? When a TextView displays this in English, it obviously shows the desired result:
Welcome to App Name!
However, two separate translators (through the Play Store translation service) have now given me back translations that look like the following, e.g. in Spanish:
<string name="welcome_title">
Bienvenido a
<xliff:g id="app_name">App Name</xliff:g>
!
</string>
which causes a TextView displaying this text to show an extra space between "App Name" and the exclamation point:
Bienvenido a App Name !
Practically, this means I have to manually inspect/edit all of the thousands of lines of translations done for me to make sure there aren't extra spaces. Not only is it extremely annoying, but in cases like Arabic, I have no clue how correct any spacing is and it's really hard to know I'm editing correctly.
Has anyone come up with a way to prevent this from happening or clean it up quickly when it does happen? I couldn't find anything on this, but it's early and maybe I haven't had enough coffee! I can't be the only one who's had to deal with this.

Related

Android Strings xml stores every value?

Do we have to place every text that we have to type in buttons or inputs or on plain surface of an activity.what happens if we don't provide values of text strings to strings xml??
what happens if we don't provide values of text strings to strings
xml??
you will get a lot of warnings from lint and no strings localization
Using strings.xml is mainly for localization, it's easy to translate a XML file and use it, not using strings.xml is a headache later on when you want to translate your app.
You may not use it, but maybe later you'll regret it.
Besides localization, it's very handy to have all strings located in the same place, when for instance, you have to change some label or correct some messages displayed to users.
Looking for strings in the code afterward could be a real pain when thousand of lines of code are produced.

Android - Appending text lines. Help choose the right control

Folks,
In my social networking application, single-line messages come from various users. As the message comes in, I need to display them in our UI as a single line that shows the time, the user, and the message line. All 3 fields need to be colored differently.
I tried to use TextView but am running into a problem. As I need various colors, I thought of using SpannableString but the problem is that TextView.Append does not support SpannableString as a parameter.
The other thought I had was to build html style text as each line comes in.
I am wondering if I am overlooking something. Perhaps there is a better user control or a better way to achieve my objective.
Thank you in advance for your help.
Regards,
Peter
Use Html and with help of <font color><font/> tag, you can set single text with different color#
String result="<font color=color_code>First Textview</font> <font color=color_code>Second Textview</font><font color=color_code>Third TextView</font>";
textview.setText(Html.fromHtml(result));
You should use three different text fields, nest them in a table layout using columns, or a relative layout. That way they will automatically resize no matter what length.
You can also use the android:weight tag to control how much room each one takes up.
The reason is that usually its 1 label per field in data structure. As per MVC software design pattern.

Android TextView URLDecode and fromHTML not quite working

I am working with HTML and Unicode text that I'm querying from a database. I'm trying to convert it for proper display in a text view.
Here is the relevant code where I'm attempting the conversion:
ReviewView.setText(Html.fromHtml(URLDecoder.decode(cursor.getString(14), "UTF-8")).toString());
However, it's only partially working. Here is an example of the text I'm working with:
is%20in%20the%20title.%3C/p%3E%3Cstrong%3EBoiled%20Brocoli%3C/strong%3E%3Cbr%20/%3EApparently%20brocoli%20does%20not%20make%20for%20a%20good%20pesto.%20This%20tasted%20like%20brocoli%20I%20used%20to%20cook%20when%20I%20was%20eleven%20at%20home%2C%20which%20is%20to%20say%20I%20don%27t%20really%20remember%20it.%3C/p%3E
I want it to look like:
is in the title.
Boiled Broccoli
Apparently broccoli does not make for a good pesto. This tasted like broccoli I used to cook when I was eleven at home which is to say I don't really remember it.
Instead I'm getting:
is in the title.Boiled Broccoli
Apparently broccoli does not make for a good pesto. This tasted like broccoli I used to cook when I was eleven at home which is to say I don't really remember it.
Any ideas on how to properly decode this?
Thanks!
The start of the Paragraph tag is wrong. in your case,it starts with a end tag, like this < / p > (added space inside the tags for clarity). Also replace the strong tag with b. It should work now.
Separating the commands actually fixed this. So on separate lines I complete first the decode then the fromHTML.

Strange Characters Showing in Android Text View

I have a text view that is showing a couple of characters as rectangles and I can't figure out where they are coming from. Any ideas?
Here is the XML with the text:
<item>
Five cents per gallon discount. Go online to www.amerigas.com or yellow pages for the closest AmeriGas location.
\n\n
 
 Offers subject to change without notice, some restrictions may apply, contact store for details. Offer does not apply to fixed price customers. You must provide your Farm Bureau membership number to your AmeriGas dealer prior to delivery of your propane in order to receive the discount.\n
</item>
And here is a screenshot:
EDIT: In the XML, I notice when I paste it here the is a large space before Offers, which is where the characters are showing up. That space doesn't show up in my editor though.
My guess is that after the \n\n in the XML file, you have tab or some other odd white-space characters that the font does not handle correctly. Replace them with regular spaces and the little boxes should go away.
You need to replace the special char \n.
Just do this:
string = string.replace("\\\n", System.getProperty("line.separator"));

Printing arabic strings in android

In my application I need to add some string to a list and print them back. Problem is when I print them I can see the letters has inter change whithing the word.The word is in Arabic. (before 4.2 android doesnt support natively for Arabic).
What I tried was using several Arabic rendering classes such as fursi class and Arabi utility class. Nothing is helped me.
Here is the word ٣.. ما زاد على actually this part ٣.. should be the first it always goes to right as I have shown. Is there way to solve this thing. this is the one and only bug to hold the application to add to market :(
Oh, ouch! Arabic is worse than Hebrew in this aspect because Arabic has its own digits! Right!
I once had a similar problem on Windows, with symbols that weren't treated exactly as Hebrew but also not exactly as non-Hebrew. The only way I found to fix this was to split the string into two - print the problematic symbols (your 300) and then print the rest of the string.
I thought that with Unicode things has gotten better. I guess not always.
UPDATE: In a comment you said the translation of the string was 3.. . In Arabic, zero and a dot look very similar (which is why I confused a dot with a zero). Perhaps the person responsible of the input typed it wrong, not being fluent in Arabic, as well? 3.. doesn't make a lot of sense (3. does, and so does 300, but 3.. ?). Check the input, it might be wrong, and that can confuse the layout algorithm.
I can't technically understand the reason behind my action to correct above issue. However this is it . ` I reverse the word and separated letters by "+" and added to the list.It is amazing !

Categories

Resources