Two languages in sqlite database - Android - android

I have simple database - one table with 6 collumns. 3 of them i want have in two languages.
Is it possible to do it automatically ? Like add language prefix to collumn and it will choose language(_EN,_PL) that user use ? It will work ?
I must have everything in one database, because I copy it to users device.
I can' t find information about it, thanks for help.

No, that isn't how SQLite DBs work even with Android's localization features. You can do it with strings.xml (for example) by creating...
/res/values/strings.xml
/res/values-pl/strings.xml
...and so on but databases and queries work on absolute column names.
The best way of doing this I can think of is to identify the local language and simply use the abbreviation as a suffix or prefix when building queries etc.

Related

Levenshtein distance in ROOM database

I have created an application that using some predefined dictionaries (for different languages) to show user matching word (each word atm is search by normalised value e.g. "łowić" -> "lowic" and search by given prefix). The problem is it is not very useful as it is usual that user will mistype some characters and using this solution, i am not able to show him proper hint. As it was available in SQLite to add extensions, that in ROOM database i can not find any way to do it. The extra problem here is that the dictionaries can contain enormous number of words so i can not calculate this by my own.
So:
is there any way to use extensions like https://github.com/agusibrahim/android-sqlite-extension in room database?
if not, should i use other database or can i do it other way?
Any advice will be appreciated.
While I have not tried it my guess is no, you cannot use Room with Android SQLite support library.
The reason is that Room depends on the SQLite3 built-in packages and doesn't "know" that this library exists in your project.
You can skip using Room and include that package in your project and then use the extension as explained in the base project:
Android SQLite support library
and the extensions project:
SQLite3 Extension for Android

Why app ids are stored in strings.xml in Android?

Isn't strings.xml is supposed to be used as a text storage for easing the translation of text in the app to other languages?
For example - Facebook app id according to facebook manuals is advised to be stored in strings.xml.
It means that if I want to share this file with 3-th parties for translation - I will have to manually remove all ids by myself, or share those ids with 3-th parties.
Isn't strings.xml is supposed to be used as a text storage for easing the translation of text in the app to other languages?
No. It's string storage for any kind of strings. Majority of use is localization related but it is perfectly fine to have anything that is string there like API keys, tokens whatever.
Please be aware that you are not limited to just strings.xml file. You can have as many *.xml files holding string resources as you like (so it's quite common to split localization per class/functional module and keep it in separate xml file).
You can create more then one strings.xml you could name it appids.xml and store all your ids inside this file. It is common software design pardigm to seperate data from code, so you won't just use a String constant for your id.
For Android best practices, Google is the source to go, for example they propose the usage of an appids.xml file here: Getting started with Play Games
Facebook might be using this simpler form of storing your id to make the tutorial easier to follow.
Basically it may happen that the ids that you're going to use inside your app may occur in multiple java class files. So by mistake there may be a chance that you mistype the id or secret key which will result in failure of result that you are expecting. As a good practice you should store such things in strings.xml which will help you minimizing the possibility of error in your result. Also if you change your id or key because of any reason then you might have to change that in each file where you've mentioned it. Instead of that if you just change it in strings.xml then it will automatically reflect at every instance where you've used it.
Going further, Android is open source. Thus any app that you create can be reverse engineered and all the code can be read. This leads to leakage of your id's and may be some secret keys for any api that you've used inside your app.

Can I Use string.xml resources as a data base?

I'm using in my Flashcards app strings.xml (value folder) as a database from where I extract the Questions & answers. Some colleagues told me that I'm miss-using string.xml!?
I really don't see any drawback using strings.xml as a database?
Do you agree with me regarding this point?
Do yo have better solution I mean better source code of a flashcards app to learn from it the best practices.
here is my code:
resId1=getApplicationContext().getResources().getIdentifier(
"textname" + 1, "string", getPackageName());
tex1=getResources().getString(resId1);
Many thank for your thoughts and assistance.
It is OK to use strings.xml as a read-only database, as long as you don't need to join data or do more advanced searches with it.
Using strings.xml is no different than using a text file as a "database" (I use that term lightly here).
You have to decide what's better for you here. Do you prefer to have a text file as a source of your data (which under certain circumstances can be completely viable) or do you need more control over your data (join, search, etc.).
If so, you can use the built in SqlLite to allow you to use an RDMBS but if not and you don't need to do anything other than having a read-only source of text, a text file approach is absolutely fine (even if it's in strings.xml).
I would suggest you to use Strings.xml as language file only, but if you think you don't have any confidential information's you are allowed to use Strings.xml as a database(but not recommended) however you can't store new values on runtime at Strings.xml.To handle some fewer data you can use SharedPreferences to store them and retrieve them, by (key, value) simple to use.
If u have large set of data then go for SQLite.

Localize multi platform projects - Consolidate string-files

In our multi-platform projects, we have multiple localization files with different notation and file format (iOS .string, Android .xml, etc.).
Now we want to localize them in many languages, but in the different files, there are many equal strings. so anybody knows of a good way to consolidate these strings-files to one big localization file, hand this to the translation agency and then splut them back up into the different files?
Anybody knows a good approach?
I've worked on an iOS/Android project with 20 translations, and we used an Excel spreadsheet to keep track of all the translatable strings. The *.strings files for XCode and the *.xml files for Eclipse are then automagically generated using my custom VBA macro.
I've put an example Excel spreadsheet with VBA macro here:
http://members.home.nl/bas.de.reuver/files/multilanguage.zip
You can convert your existing .strings or .xml files to spreadsheet format (key value pairs, tab separated) with the tool below. Then you can send the spreadsheet to your translators, they fill in a column of translated values, send it back and you can simply generate your new translation files.
http://members.home.nl/bas.de.reuver/files/stringsconvert.html
EDIT in 2021
The homepage is offline now, but I've added the Excel/spreadsheet example on github:
https://github.com/BdR76/Manage-translations
Was in the same situation with my app about a month ago.
If you use SmoothLocalize for your localization (which I would recommend as they are really easy and super cheap), you don't have to pay for repeat strings on the 2nd order. So you would pay the full 4c/word for your iOS localization, then just paste in your order number for the Android localization and you don't have to pay to translate them again.
Also if they are EXACTLY the same, they will convert a .strings to a .xml for you so you would only have to do one order, just email them.

Android, retrieves from different values folder

I am a newbie for android and really need you all helps to complete my task ^^. I am currently doing a project which is quite similar to android localization. However, there is another native language that is not stated down in language or a language-region combination that provided by the android setting. Is there any other ways that i can do to make the application retrieve different strings when different language selected?
I have try to create different names of values folder but it doesn't work when the folder named as "values-penan".
Thanks if anyone could help!

Categories

Resources