localize databases with working searching and ordering? |
Hello,
I try to implement an application that can be localized. Text in php and views is no problem, since I can use 'lang()', but now I have a database table that holds colors and their name. I stored the colors in english (black, blue, green, ...). No problem while just displaying them. I just use "<?= lang('Colors.' . $color->name) ?> in templates and get a localized output (e.g. german: schwarz, blau, grün). But now I offer the possibility to search and order by color and that leads to wrong (order) or no (search) results, since e.g. order In english:
Code: $db->query(' results in: Code: $db->query('
Search in form? What is the problem? Set up the select or radio form as ['green' => lang(...), 'black' => lang(...), 'blue' => lang(...),].
Create a regular search query. See https://codeigniter.com/user_guide/helpe...m_dropdown
You have to specify what colors can be queried into the table, then the results in view must be translated according to user preferences.
@xxxx[{::::::::::::::::::::::::::::::::>
It is not so easy. It is a search input, that is not restricted to one database column. You can search a term and it is looked up in serveral columns and all matching ones are shown.
You can try here: https://kh.4lima.de/routes Colors is a translated string. So sorting and searching is wrong. Search 'schwarz' (german), you won't find anything, but search 'black' and black routes are shown.
I'm not sure it's possible to do this easily. The initial search structure is incorrect. You will be searching for non-existent data.
As an variant, do not translate the keys for colors.
Hi,
The way I would do this: in a table I have multiple field for different languages, i.e. colorEN, colorDE, colorFR. The query would be something PHP Code: $query = $this->db->table('colors') Where $language is the current selected language. I guess this would also order the colors correctly.
Yeah, and have a bunch of garbage in the table to sort And when will there be five more localized fields?
Translate them.
PHP Code: <?php SEE: The Universal Solution: A Translation subschema Best Practices for Multi-Language Database Design What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(06-10-2024, 01:02 PM)JustJohnQ Wrote: We're talking about a colors table, right? What garbage do you mean? You have one additional column per language and if you do no restrict SELECT to one language column, all additonal language columns need to be process (sorted, etc.), even when not needed. For every typo you have to make an SQL query. I would like to maintain it in language files. Easier for translators. They just need to work work with text files. |
Welcome Guest, Not a member yet? Register Sign In |