I have data in different languages inserted into my db, such as chinese, french, english, malay, japanese, korean, etc.
How can I detect those languages and query the specific one. For example if I only want to query data in chinese and display it to users.
If I were you, I’d have something like this to store the text that is displayed in your UI controls:
There will be one unique
control_idfor each control (e.g. button) in your UI. Each control can have many labels, one for each language.Then, each UI control can have a different label for each language. (I’m assuming a two-letter ISO language code here, but you could also use a numeric ID or some other identification scheme.)
This makes it easy to add new languages just by adding rows to the
ui_labelstable, and easy to switch the language displayed in the UI just by switching thelanguagevalue that you use in your queries.The data for a button could look like this:
As an alternative to this approach, though, you may want to look into gettext, which is a standard way to do translation in PHP. It doesn’t use your database. If it’s a requirement to put the strings in the database (for example, if an end-user has to be able to edit them), then this isn’t an option, but it may be something that you can consider. If you are interested in this, you might want to have a look at this blog post:
http://verens.com/2008/04/03/translation-in-php/