Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question about i18n configuration #599

Closed
Justineo opened this issue Jan 28, 2019 · 4 comments
Closed

A question about i18n configuration #599

Justineo opened this issue Jan 28, 2019 · 4 comments

Comments

@Justineo
Copy link

Justineo commented Jan 28, 2019

Is your issue related to your own DocSearch implementation?

It's a general usage question. I saw in the docs that we can configure certain part in URL to match language/version facets. But what if I have a default language like this:

http://www.example.com/docs/installation    -> en
http://www.example.com/docs/fr/installation -> fr
http://www.example.com/docs/jp/installation -> jp

And the following config should help docsearch to recognize language facets like fr and jp:

{
  "start_urls": [
    {
      "url": "http://www.example.com/docs/(?:(?P<lang>.*?)/)?",
      "variables": {
        "lang": ["fr", "jp"]
      }
    }
  ]
}

My question is, in this case, how can I configure for the default language (en) so that on English pages docsearch only return those results not matching any language facets? Thanks in advance.

@s-pace
Copy link

s-pace commented Jan 31, 2019

👋 @Justineo

You should rely on the content of your pages instead of relying on the URL. You can either:

You will need to update your JS snippet as following:

docsearch({
  apiKey: '21cdc123c620ec4bb81259c32e90c08f',
  indexName: 'veui',
  inputSelector: '### REPLACE ME ####',
  algoliaOptions: { 'facetFilters': ["lang:$LANG"] },
  debug: false // Set debug to true if you want to inspect the dropdown
});
  • Replace $LANG with the lang you want to search on. The list of possible lang is extracted from your website according to your global lang selector. So as of today you have: en-US, zh-Hans

    For example if you want to refine the search to the lang en-US just specify:

 'facetFilters': ["lang:en-US"]

@Justineo
Copy link
Author

Justineo commented Feb 1, 2019

@s-pace

Thanks! I have a further question: how can I properly re-initialize the docsearch after it's initialized? My site is using a front-end router so that I need to switch language at runtime.

@s-pace
Copy link

s-pace commented Feb 2, 2019

Your index will be updated every 24H. You will need to wait for the next crawl to be able to update your front. You can run our crawler on your own if you want more control. You will need you own algolia account

@Justineo
Copy link
Author

Justineo commented Feb 2, 2019

@s-pace

I mean the docsearch.js API in the browser. I cannot find an API to change facetFilters setting or just dispose the old instance so that I can initialize again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants