Hi,
There are some options for translating database values here: https://asprunner.co...htm#transl_data
But none of them did what I needed so I came up with a different way.
For example, I have a menu->dish structure, and I need to be able to present dishes in either English or Spanish, without using separate tables or duplicate entries. This way each dish has one price, one placement on the menu, and my reports on dish popularity also work correctly whether the patron used the English or Spanish menu.
I did the following:
This will cause the translated value of title (en or sp) to be shown in the lookup dropdown box, instead of always showing the value selected as the 'Display field'.
Unfortunately this would be slow for many languages, but it works to include a couple and forces database integrity.
There are some options for translating database values here: https://asprunner.co...htm#transl_data
But none of them did what I needed so I came up with a different way.
For example, I have a menu->dish structure, and I need to be able to present dishes in either English or Spanish, without using separate tables or duplicate entries. This way each dish has one price, one placement on the menu, and my reports on dish popularity also work correctly whether the patron used the English or Spanish menu.
I did the following:
- In the dish table, create a title_en and title_sp column.
- In the database, create a view using UNION ALL to include the contents of the dish table twice, once with English titles and once with Spanish.
CREATE VIEW dish_multilanguage AS SELECT id, title_en AS title, 'English' AS lang FROM dish UNION ALL SELECT id, title_sp AS title, 'Spanish' AS lang FROM dish
- In the After Successful Login event, record the language in the session using
$_SESSION["language"] = mlang_getcurrentlang();
- Anywhere you need to do a Lookup table for a dish, you reference dish_multilanguage instead of dish, and in the WHERE box add
" lang='". $_SESSION["language"] ."'"
.
This will cause the translated value of title (en or sp) to be shown in the lookup dropdown box, instead of always showing the value selected as the 'Display field'.
Unfortunately this would be slow for many languages, but it works to include a couple and forces database integrity.
إرسال تعليق