Autocomplete with multilanguage

8 months 1 week ago #320870 by ericmuc
Autocomplete with multilanguage was created by ericmuc
Hi,

I am using this code:
SELECT en_name
FROM `#__comprofiler_languages`
WHERE (
    `iso_639-1` = '[value]'
    OR `en_name` LIKE '%[value]%'
    OR `de_name` LIKE '%[value]%'
)

I have a mysql table with EN and DE languages names.

I have installed two languages, German and English.

Do you have a code snippet or a hint for getting:

If the German language in the website is used, the autocomplete shows for saving the German result and if the English language in the website is used, the autocomplete shows for saving the English result?

Thanks, best regards
Eric

Please Log in to join the conversation.

8 months 1 week ago #320871 by krileon
Replied by krileon on topic Autocomplete with multilanguage
Typically you wouldn't translate in the database like that. You'd have 1 database value then translate using language overrides as it will pass thought translations in CB when the query result is turned into auto complete options. You should however be able to just use a language IF substitution in the query. Substitutions are ran before the query is executed so should give desired results.

SELECT `[cb:if language_code="de"]de_name[cb:else]en_name[/cb:else][/cb:if]`
FROM `#__comprofiler_languages`
WHERE (
    `iso_639-1` = '[value]'
    OR `en_name` LIKE '%[value]%'
    OR `de_name` LIKE '%[value]%'
)


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: ericmuc

Please Log in to join the conversation.

8 months 1 week ago #320903 by ericmuc
Replied by ericmuc on topic Autocomplete with multilanguage
Hi,

Thanks, that is very helpfull.

At the moment I am struggling with following:

1) I want to have multilanguage site and a visitor shall be able to search for "Englisch" OR "English" for example
2) both searches shall show: users with "English" and with "Englisch"
3) and over all if the site is in English, the language shall be shown as "English" and if it is in German, the language shall be shown as "Englisch"

So I think this idea is not new but I have not the answer at the moment, how to do that in best manner.

Do you have an idea for making that in CB?

Thanks, best regards
Eric

Please Log in to join the conversation.

8 months 1 week ago #320907 by krileon
Replied by krileon on topic Autocomplete with multilanguage
If you want a multilingual site then don't create language specific values. Use generic values and have the display translate based off the viewing users language. For example your dropdown might have the below.

Value: COLOR_RED
Label: Red
Value: COLOR_BLUE
Label: Blue

COLOR_RED and COLOR_BLUE are what is stored in the database. Red and Blue are what is displayed to the user and is ran through translation API. So you can use language overrides to make them multilingual. It doesn't matter if this comes from a Query Select, Code Select, or regular Select field. As for example a Query Select you've the following parameters.

Value Column: this is Value as described above
Label Column: this is Label as described above

Using your custom database table above you'd have the below.

SELECT `iso_639-1`, `en_name`
FROM `#__comprofiler_languages`
Value Column: iso_639-1
Label Column: en_name

Now you'd just add language overrides for the values of en_name column. I guess you could still conditioning it as follows though.

SELECT `iso_639-1`, `[cb:if language_code="de"]de_name[cb:else]en_name[/cb:else][/cb:if]` AS 'label'
FROM `#__comprofiler_languages`
Value Column: iso_639-1
Label Column: label


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

8 months 1 week ago #320909 by ericmuc
Replied by ericmuc on topic Autocomplete with multilanguage
Hi,

Thank you very much. Looks right, your suggestion.

But how can the user search for example for "red"?

The content in the field is "COLOR_RED", isn't it (only Label = "red" or "rot")? Do the search works also with your suggestion? Do I have do soemthing more, that also the search for "red" is working?

Thanks, best regards
Eric

Please Log in to join the conversation.

8 months 1 week ago #320912 by krileon
Replied by krileon on topic Autocomplete with multilanguage
If it's a regular select field then they'd just select what they want to search. The problem is you're doing this on a Text field as Autocomplete. Autocomplete is just a suggested value for a Text field. There isn't really an option to make that multilingual as it just accepts whatever text the user supplies and autocomplete just fills in whatever they selected from the dropdown. So no searching "Red" won't search for "Red" or "Rot" when it comes to a Text field.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.447 seconds

Facebook Twitter LinkedIn