just for curious, i got a question!
My app is almost ready.. I have implemented bilingual (English/Tamil) when users select thr preferred language in Settings then whole app gets converted into that language (i used custom Locale). Everything works fine.
My question is, Can we do the same to SQlite database? which fetch data automatically based on locale from table
"country-en"or"country-ta" ? is there any way? i heard that thr is a method SQLiteOpenHelper.onConfigure(setLocale()); to set locale in sqlitedatabase. i want to know how it works!
The method you describe above is not related to language localization for the client. It's related to locale options on the database (for example how to treat string comparisons with accented characters).
Anyway, if you think of it... what does localizing a database mean? You can either localize the structure or the data. Localizing the structure (table names...) doesn't make sens because the user is not aware of it. Localizing the data doesn't make sense either, because that means that if the users changes language settings, next time he uses your app he won't see his data!
If the DB only contains static data and you need to provide a different DB for different languages, you could use localization to lookup for the database filename.
Of course, yes, you can.
When you do your queries, just append "en" or "ta".
Something like "SELECT FROM Country_" + yourLocale + "..." - if you want to use two different tables.
OR you could use one single table with an integer field "Language" and you pass an int (0 = english, 1 = tamil - only for alphabetical order, which is easier to remind)...
Something like "... WHERE ... AND Language = 0"
Related
I'm making an android app with multi-language support.
I have around 30 language to support my app.
I'm playing within 2 Case.
case 1 . First case is creating values folder of every language in res folder.
case 2. Second case Get every language content with a key from server
e.g. TXT_HELLO = HELLO if user choose English
TXT_HELLO. = HOLA. if user choose Spanish
Suppose from language list I select Spanish during language change
then server give me list of every Spanish content with a same key
[Key] = [Value]
e.g. TXT_HELLO = Hola
TXT_GOOD = Bueno
& then I save this value with key is session & all key also in my Constant class
Similarly In Case if I select English:
[Key] = [Value]
e.g. TXT_HELLO = Hello
TXT_GOOD = good. as Soon
This is how my kotlin code work.
fun getLanguageValue(key : String)->{
return sharedPre.getString(key)
}
txtViewHello.text = getLanguageValue(MyConstant.TXT_HELLO)
cons and pros of case 1 .
pros : It handle by system and good memory management
cons : Language only can add on new release apk. if some word is wrong then can't be correct without release.
cons and pros of case 2 .
pros : if some word is wrong then can correct online. No need to release new APK or can add more language at any time.
cons : It handle by me and initialization of objects is more complex.
So please suggest me what is best approach & what is best practice to change language.
You could attempt to write your own language switcher that does this, but I'd advise against it. This is basically fighting the system, and is very hard to handle properly.
The best way to handle multiple languages is to use resource qualifiers, and make the system do the hard work for you. It will also match the user's expectation that your app will be in the same language as the entire rest of their phone.
I have stored data in SQLite database in both English and Hindi.
I have two columns in database, name and address respectively, and I am storing some raw in English and some in Hindi statically.
Now, My Question is "How can I know about that which type of data I am fetching from database ?"
Is it in English language or Hindi language?
Is there any language checker available in Android?
How can I get done this task ?
Thanks in Advance.
Why don't you create a new column for flag 'language_type'
When value equals
1 :- Hindi
2 :- English
While entering the data, You can check the flag accordingly.
Hi i plan to develop an android application for English and Spanish Languages.For that we store data in Sq lite Database.without depends on the device language.
Application contains List of long text values stored in sq lite database and data retrieved from the db and shown in list view.how can i store different languages data in sq lite and how to retrieve and display in view based on language selection.
You could create a table in sqlite that contains nodes as one column and two other columns that contains the spanish version of the same and English version. Like:
ID NODE SPANISH ENGLISH
1 LOGIN S-LOGIN LOGIN
use :
Locale current = getResources().getConfiguration().locale;
to get the current locale, google a little bit to find out how to get the current language selection.
In the onResume method of the activity:
1. Check the current locale
2. Based on the current locale, fetch the strings for the labels and views
3. SetText to the views using the strings that you obtain
And that's it.
I hope this much clue helps!
i am new to android development,so dint get me wrong. I am developing an application in which a text is generated.which is normally a word. The word is checked in a database for is corresponding value pair. Here the word is the key and its corresponding value is the value .
Since the text is auto generated it sometimes goes wrong(mis spelled). How do i perform a check of auto generated word to match with the mostly matched letters in the database of key word.
example: auto-generated word(key) - value
americ:
america : a country
Here the auto generatd word is americ(key) is not matched since it only contains america in its pair set.it need to be corrected as america.
You are probably using SQLite. Your best bet is soundex, which is desribed here.
Soundex has many shortcomings, but it might get you started. If you want a real measure, then go with Levenshtein distance, which is not built into the database (as far as I know).
I am new to both Android and Stack Overflow. I have started developing and Android App and I am wondering two things:
1) Is it possible to parametrize a TextView? Lets say I want to render a text message which states something like: "The user age is 38". Lets suppose that the user age is the result of an algorithm. Using some typical i18n framework I would write in my i18n file something like "The user age is {0}". Then at run time I would populate parameters accordingly. I haven't been able to figure out how to do this or similar approach in Android.
2) Let's suppose I have a complex object with many fields. Eg: PersonModel which has id, name, age, country, favorite video game, whatever. If I want to render all this information into a single layout in one of my activities the only way I have found is getting all needed TextViews by id and then populate them one by one through code.
I was wondering if there is some mapping / binding mechanism in which I can execute something like: render(myPerson, myView) and that automatically through reflection each of the model properties get mapped into each of the TextViews.
If someone has ever worked with SpringMVC, Im looking for something similar to their mechanism to map domain objects / models to views (e.g. spring:forms).
Thanks a lot in advanced for your help. Hope this is useful for somebody else =)
bye!
In answer to #1: You want String.format(). It'll let you do something like:
int age = 38;
String ageMessage = "The user age is %d";
myTextView.setText(String.format(ageMessage, age));
The two you'll use the most are %d for numbers and %s for strings. It uses printf format if you know it, if you don't there's a quicky tutorial in the Formatter docs.
For #2 I think you're doing it the best way there is (grab view hooks and fill them in manually). If you come across anything else I'd love to see it.