I am working on an Android app that I would like to code in such a way so that the Spanish characters coming from the database are read as equivalent to the English ones. For instance, cafe and café would be identical.
Is there a way to do this?
Do you mean that you want queries to find both "cafe" and "café" when you search for "cafe"? You should be able to use a regular expressions to do this.
If this needs to be done on the fly, you could write a function that parses the request for 'e' and generate the correct regular expression before creating the DB query.
Related
I am working on an android application that will be used possibly by two sets of users. One will operate the app in English language and will enter all the information in English. However, a set of users would like to make the entries in Hindi.
Now my app can be displayed in both languages by having different sets of string.xml file and based on the language being used on phone or some setting in App. But my app will have a lot of forms in which user needs to input values that can be in hindi or english. I am not sure how to handle this. The exact questions will be:
How do I save the data entered in hindi in my database?
If somehow I do just word by word translation, there is a great chance of the meaning being lost. Is there any way to solve this?
I have to create reports based on these entries, if they are in different language, how hard will it be to insert them in database?
I would appreciate some solid pointers if you don't have time or energy to explain everything. Of course some fundamental explanations are most welcome.
By default TEXT fields in Android's sqlite3 are stored as UTF-8. I understand Hindi is encoded with UTF-8 and so is English so saving the text in one or other language shouldn´t be a problem.
Regarding the translation, see this question in SO where there is a discussion about different alternatives: https://stackoverflow.com/questions/17056168/google-translate-or-similar-api-for-android
I'm looking for the best way to find a random English word using an Android app. Is there a better way than saving a .txt file with all the words in your res/ folder, such as
http://www.stanford.edu/class/cs106l/assignments/dictionary.txt
then importing it into an ArrayList? The app I'm developing will search for words quite often, such as a random word starting with the letters 'A' or 'Be'. I'm worried about memory and runtime with this function.
Create a SQLite database containing all the words. You can then query that database using SQL to match your random word with various starting letters.
SQLite Details: http://developer.android.com/reference/android/database/sqlite/package-summary.html
Look for documentation on using LIKE in SQL for your text matching.
Example: http://www.techonthenet.com/sql/like.php
For randomness, find all words matching your criteria. Get the count of them (call it 'n'), then pick a random number 'x' between 1 and n, and take the xth record.
Use a prefix tree (or Trie) as described here.
It's extremly efficient, as all word-beginnings are only stored once.
I've just discovered an issue where city names that contain accent marks, e.g. La Cañada, Peñasco, etc., won't save to my database. Looking through the answers to another SO question, What is the best collation to use for MySQL with PHP?, I've tried changing both my database and the varchar's collation type from latin1_swedish_ci to utf8_general_ci which still refused the character. I also tried utf8_unicode_ci with a similar result.
I've verified that the save works if I strip out the accent mark on the client side, but ideally I'd like to keep it in there, since that is the real name of the city (according to google maps apis anyway).
What collation types do you use to support ñ?
Additional info: Using MySQL, phpMyAdmin, and CakePHP with an Android app as the client
Thanks for the suggestions so far. I guess this is turning into a CakePHP question now... I noticed that by default utf8 is not enabled, so I enabled it in my app/config/database.php file. I FTPed the file back to the server and tried it again still without any luck. Do I need to redeploy the application to kick off those db config changes, or is there another area of my application I should check? First time CakePHP user here.
Collation is merely the order in which characters are sorted, which is a necessary step in performing comparisons. It has nothing to do with how data is stored (except insofar as a given collation is specific to some encoding).
Character encoding is the mapping of characters to their binary representation for storage, which determines the supported character set.
However, just because a database/table/column are using a particular character encoding is not the end of the story. You must also consider the encoding used within your application and on its interfaces with other components (such as MySQL).
Whilst it's aimed at PHP, UTF-8 all the way through pretty much covers all of the things you need to consider.
I m working on app which uses sqlite database . I got sucess to store Strings in various languages and also fetching from database .
But My problem is that i want to store it in bold or italic style.
Is it possible ?? If yes then how can i achieve that kind of thing ?
Any help will be appreciated.
Format the strings using html.
When you want to display them use Html.fromhtml( your string)
E.g.
String myboldstring = <b>boldy</b>
textView.setText(Html.fromhtml(myboldstring));
Is it what you want?
As an alternative to LazyN's solution I suggest you look at using a standard markdown language for this kind of context (much as stack overflow does). There are several advantages:
Widely used around the web so your users are likely to understand how to use it.
Much more secure in the sense that one cannot inject malicious HTML/javascript; this is very difficult to prevent once you allow any HTML as LazyN suggests
Trivial to store/export/import etc as it is all legal text string
While using MyPHP admin, I edit records in mySQL database that then is updated into my Android application.
If I paste data into one of my table fields, I often get "NULL" displaying in my app. If I paste the web service URL into a browser I still get the NULL value for that particular field.
After further experimenting, I noticed that editing some characters, that tend to be non-standard, the NULL is replaced with my data. This characters seem to be apostrophes, dashes, and brackets...etc.
Is there some way to do a mass conversion so all my data will paste into my table without editing special characters?
I have tried pasting into Notepad and other editors with the same result.
I then tried various means to ensure my tables were using utf8 character set. This yielded no data to my app. (the Browser method still worked). I don't remember adding anything to my app that set the charset.
Any ideas?
Thanks!
Hard to judge without sample data, url, etc. But I would say, given that this data will be displayed on a mobile device, that you probably would need to paste your data into something like TextWrangler, or NotePad++ and you will have to do a regular expression find and replace on all of the special characters. When you're finished, you would have to reimport into your database.
Another solution is to filter out the special characters right on the server. You could use the PHP str_replace function to filter out special characters as well.
I hope this helps!