Add Open Search Description with multiple URLs based on language

432 Views Asked by At

The website I want to add OpenSearchDescription to has a language parameter in the URL path to define the vistors language. This means that the search URL will be different for every language, e.g. http://www.example.org/en/search and http://www.example.org/fr/search

The below snippet will allow to add a search URL, but for a specific language (e.g. English).

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
  <script/>
  <ShortName>Example Site</ShortName>
  <Description>Search Example Site</Description>
  <InputEncoding>UTF-8</InputEncoding>
  <Image width="16" height="16" type="image/x-icon">http://www.example.org/favicon.ico</Image>
  <Url type="application/x-suggestions+json" method="GET" template="http://suggestqueries.google.com/complete/search?output=firefox&amp;q={searchTerms}" />
  <Url type="text/html" method="GET" template="http://www.example.org/en/search?search_query={searchTerms}" />
</OpenSearchDescription>

The OSD documentation is not clear to me about adding multi language support. Could it be like this?

...
  <Url type="text/html" method="GET" template="http://www.example.org/{language}/search?search_query={searchTerms}" />
  <Language>en</Language>
  <Language>fr</Language>
...
1

There are 1 best solutions below

0
On

I'm try another way but don't working Ref:https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md#the-language-element

<Url type="text/html" method="GET" language="tr" template="https://example.com/tr/arama?q={searchTerms}"/>
<Url type="text/html" method="GET" language="en" template="https://example.com/en/search?q={searchTerms}"/>

Chrome acccept only last url;

Acccepted-language request header tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7

Result https://example.com/en/search?q=asdBut why /en it has to be a solution.

<Url type="text/html" method="GET" template="https://example.com/{language}/search?q={searchTerms}"/>

This look like good. But i change my OS default language Tr to En

Result: https://example.com/en-US/search?q=asd this unexpected, i dont't have this url and can't apply all language - country specification.

documentation for practical application is insufficient.

When I was researching what other people were doing in this matter, I noticed that no one was dealing with it.

The most convenient method is to use only one search path and user will be redirect with the 302 http code to other language search page for browser language (or saved preferences etc:lang cookies).

This is not the answer to the problem but it more realizable. (etc:pinterest) example code: https://stackoverflow.com/a/17826646

Alternative solution parse GET data and redirect another page:

<Url type="text/html" method="GET" template="https://example.com/search?q={searchTerms}&amp;lang={language}"/>

And handle any server-side language

if lang == "en" OR "en-US" OR en-UK ....
    redirect "https://example.com/en/search?q=" + searchTerms
else if lang == "xx" OR "yy"
    redirect "https://example.com/zz/search?q=" + searchTerms

this method is not different from http header read.