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.

Comments

dom.’s picture

Hi!
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 :

            'no_results'    => $match->no_results,
            'all_results'   => $match->all_results,

to

            'no_results'    => t($match->no_results),
            'all_results'   => t($match->all_results),

it should do the trick (assuming you will then translate the terms in the translation interface of course).

Let me know

  • Dominique CLAUSE committed e98ad8f on 7.x-4.x
    Issue #2382785 : Add localization on all_results and no_results labels.
    
dom.’s picture

Status: Active » Closed (fixed)
ñull’s picture

Status: Closed (fixed) » Needs work

Error message
The submitted string contains disallowed HTML: {"label":"No results found for [search-phrase]<\/b>.
Click to perform full search.","value":"[search-phrase]","link":"","group":{"group_id":"no_results"}}

Apparently this is not the way to do it.

dom.’s picture

Hi,
I could not reproduce #4. Can you specify what translation you entered ? Does it have some HTML ? Does it have some special chars ?

ñull’s picture

StatusFileSize
new54.35 KB

At /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?

dom.’s picture

Status: Needs work » Needs review
StatusFileSize
new1.21 KB

Indeed you are right.
Here come a patch with correction. Could you have a try at it please ?
Miro.

jmdeleon’s picture

StatusFileSize
new7.61 KB

Hello 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 :)

dom.’s picture

Hi,
Thanks a lot for this proposition, I will test it soon.
Dom.

ñull’s picture

StatusFileSize
new36.17 KB

I tested #8 but I still get the same error message when I try to translate:
The submitted string contains disallowed HTML

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.

dom.’s picture

Status: Needs review » Needs work

will retest after #8 and #10

dom.’s picture

Status: Needs work » Needs review
StatusFileSize
new12.45 KB

Hi !
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.

  • Dominique CLAUSE committed 9fa1dbd on 7.x-4.x
    Issue #2382785 by Dominique CLAUSE, ñull, jmdeleon: Add localize to...
dom.’s picture

Status: Needs review » Closed (fixed)

Did 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.

chevali’s picture

Hi, 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

dom.’s picture

Hi 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".

ñull’s picture

I am having trouble showing results from different languages, it only shows the ones in original language, not translated ones.

What 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.

chevali’s picture

The 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.

ñull’s picture

The default drupal search page/block searches correctly, returning results in either language

Can 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.

thulenb’s picture

I 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?

dom.’s picture

Hi 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.

thulenb’s picture

Hi 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:

  • I have two enabled languages - German and English (German is the source language)
  • In the settings I enter the text for "no results" message label in English ("No locations found")
  • Now, I look up this string in the string translation settings. I can find it and I am sure it is the correct one because it is the only string.
  • Now, I can translate the string into German (the original text is English and the text to translate is German - just I expected it)
  • After saving I tested if it works by switching the languages. Unfortunately, it does not work.
  • I tried to investigate where the error is and went back to the settings page. I can see that the setting changed. Where I actually entered the English term ("No locations found") the setting is replaced by the German term (probalbly because of the string translation)

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!

sano’s picture

I 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.

NathanWR’s picture

StatusFileSize
new756 bytes

I 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.