On a multilingual site the search autocomplete suggestions can be localised with a correct view, but how to localise the text that appears when there is no result? I guess you can change the strings labeled as:
- Custom "view all results" message label
- Custom "no result" message label
But when you use two languages? I don't have a clue how to do this. Somebody can give me a hint.
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | localize_labels-2382785-24.patch | 756 bytes | NathanWR |
| #12 | localize_labels-2382785-12.patch | 12.45 KB | dom. |
| #6 | search_autocomplete_issue_2382785.jpg | 54.35 KB | ñull |
| #10 | search_autocomplete_issue_2382785_10.jpg | 36.17 KB | ñull |
| #7 | localize_labels-2382785-7.patch | 1.21 KB | dom. |
Comments
Comment #1
dom. commentedHi!
I don't really have time to try out I'm sorry, but I think if you change lign 78-79 from search_autocomplete.module :
to
it should do the trick (assuming you will then translate the terms in the translation interface of course).
Let me know
Comment #3
dom. commentedComment #4
ñull commentedApparently this is not the way to do it.
Comment #5
dom. commentedHi,
I could not reproduce #4. Can you specify what translation you entered ? Does it have some HTML ? Does it have some special chars ?
Comment #6
ñull commentedAt /admin/config/regional/translate/translate I searched for the string "No results found for". Attached a screenshot of the error when I put in the Spanish field the untranslated English original. As you can see that already caused the same error.
It has nothing to do with my translation. A JSON string is no HTML at all and is not accepted by the localization system. I think the t() were put in the wrong place. Isn't there any location in the code where the string is pure HTML?
Comment #7
dom. commentedIndeed you are right.
Here come a patch with correction. Could you have a try at it please ?
Miro.
Comment #8
jmdeleon commentedHello Dominique CLAUSE,
The patch in #7 seemed to work for me, but a new set of localized strings was created for each page I used an Autocompleted form for -- this caused problems when I had used a form on several pages (like a global search box that is placed at the top of all pages). I spun up a slightly more comprehensive patch, also with better HTML :)
Comment #9
dom. commentedHi,
Thanks a lot for this proposition, I will test it soon.
Dom.
Comment #10
ñull commentedI tested #8 but I still get the same error message when I try to translate:

With some trying I discover that no HTML tags are accepted at all in the translation. For the moment I translated without the bold and line break tags.
Comment #11
dom. commentedwill retest after #8 and #10
Comment #12
dom. commentedHi !
Thanks jmdeleon for patch proposition at #8. It works fine from a clean install. However, if applying after already installed version I could reproduce the error from ñull. This comes from former label already in the DB with the former html tags.
<strong>is allowed in translations while<br/>is not.The following patch apply includes 3 corrections :
- prevent multi translation after usage, just how it is described and corrected in #8, thanks jmdeleon for that.
- remove all tags including
<strong>in labels: now the[search-phrase]get's embedded with<span class='ui-autocomplete-field-term'></span>just how it is done in search term results which is a better way to do.- include a migration patch to remove previous version html tags stored in DB. => run update.php after applying patch.
Please review if possible.
Dom.
Comment #14
dom. commentedDid someone give a second try to this ? The patch is commited on 7.x-4.x-dev and will be included in 4.2 release.
Comment #15
chevali commentedHi, I am having trouble showing results from different languages, it only shows the ones in original language, not translated ones. you mentioned "On a multilingual site the search autocomplete suggestions can be localised with a correct view" so what is a correct views settings for this?
I would appreciate the help
Comment #16
dom. commentedHi chevali,
Can you be more specific about your issue ?
Where did I right correct view ? That surely means a properly configured view.
Saying you have the node "foo node" which is also available in french as "noeud bar".
- Saying you visit the site in french and type foo, you won't get results.
- Saying you visit the site in french and type bar, you should get displayed "noeud bar" not "foo node".
Comment #17
ñull commentedWhat I found essential to get the right language is to include a language filter criteria. I had the similar problems as you until I added the filter Content: Language (= Current user's language). I hope that helps.
Comment #18
chevali commentedThe default drupal search page/block searches correctly, returning results in either language, the autocomplete one doesn't search the translated language, only returns results from their original language. tried adding the content language, doesn't work, plus i don't want user language specific searches, since the user might use either language in the search ( products ). so i was wondering what should i add in the view to be able to output both languages.
Comment #19
ñull commentedCan you explain that better? What do you consider correct?
I consider correct separating the two languages with Content: Language (= Current user's language) following a generalized expectation that when you choose a language that it strictly obeys the wish of the user to only show the preferred language. That is what I understand when we use the term localize.
Comment #20
thulenb commentedI have still a problem with translating the individual labels in the settings:
- so my source language is German
- the second language on my site is English
Now, in the settings I enter the German term for "no results" --> "keine Ergebnisse".
Then, I search for the term I entered in the string translation. I can find the term but I am asked to give a German translation, not an English one which is what I need.
I tried a lot. For example, I entered the English term in the settings and then translated it into German in the string translations. In this case, on both language versions, the English term is displayed. Additionally, I tried to change my source language from German into English and tried all settings again. No luck.
It seems to my, that the translation is ignored. It is always the term that is entered in the settings and that's getting displayed.
Besides, I am using the newest version 7.4.7.
Does somebody has an advise?
Comment #21
dom. commentedHi ThuleNB,
The second option is the one: enter the terms in english in the settings and translate it in german in the translation section. Make sure though to find and translate the proper one since it may not be obvious which one is correct.
Comment #22
thulenb commentedHi Dom,
many thanks for your qucik response.
This is what I already tried and tried it again. But good to know that this is the way it should work. Maybe a detailled description of what I recognized helps:
So my guess is that the original term that was entered in the settings gets changed after translation. Thus, I have the translated German term and also the German term in the settings page. This is probably why I get the German term on both, the English and German sites.
Does this make sense? Thanks!
Comment #23
sano commentedI am also unable to translate the source (English) phrase for no results into a second language. Using version 7.x-4.7+2-dev (2016-Feb-16) which seems to have the patch applied. I am using the "User" language selection method.
Comment #24
NathanWR commentedI was also unable to translate the all_results and no_results running version 7.x-4.9. It appears that the translation hasn't been working since commit 82f5697 on Feb 5, 2015.
It may not be the best way, but I created a patch to translate the json data since [search-phrase] is replaced with the search term before the json decode now.