docsifyjs / docsify

🃏 A magical documentation site generator.
https://docsify.js.org
MIT License
27.86k stars 5.68k forks source link

Localized search placeholders don't appear even when config'd #2132

Open adamlui opened 1 year ago

adamlui commented 1 year ago

Bug Report

When filling localized info in placeholder, noData & pathNamespaces of window.$docsify.search in index.html, only English appears even on non-English pages

Steps to reproduce

  1. Fill window.$docsify.search in index.html with localized info such as:
    search: {
        paths: 'auto',
        placeholder: { '/': 'Search',
            '/zh-cn/': '搜索', '/ja/': '찾다', '/ko/': '検索', '/hi/': 'खोज', '/de/': 'Suchen', '/es/': 'Buscar',
            '/fr/': 'Recherche', '/it/': 'Ricerca', '/pt/': 'Procurar' },
        noData: { '/': 'No results!',
            '/zh-cn/': '没有结果!', '/ja/': '結果がありません!', '/ko/': '결과가 없습니다!', '/hi/': 'कोई परिणाम नहीं!',
            '/de/': 'Keine Ergebnisse!', '/es/': '¡No hay resultados!', '/fr/': 'Aucun résultat!',
            '/it/': 'Nessun risultato!', '/pt/': 'Sem resultados!' },
        pathNamespaces: /^(\/(zh-cn|ja|ko|hi|de|es|fr|it|pt))?/
    },
  2. Visit the homepage
  3. Change languages
  4. Go to search bar and observe the placeholder is English still

What is current behaviour

Search bar displays English

What is the expected behaviour

Search bar displays localized language

Other relevant information

Please create a reproducible sandbox

The codesandbox.io site keeps giving error when I try to upload files (https://github.com/chatgptjs/chatgpt.js/tree/main/docs)

Edit 307qqv236

Mention the docsify version in which this bug was not present (if any)

trusktr commented 1 year ago

It looks like it works on the Docsify site. Can you start with the config for search like in here:

https://github.com/docsifyjs/docsify/blob/a69c22ac79f117f091fcfc96c46dc440ef151e48/index.html#L70

And then carefully convert to your languages and see where it breaks?

Also we can't see your working code example so we cannot see if there is some other issue.

adamlui commented 1 year ago

Ok I thought my link to the folder containig index.html made it clear but here's a link to the index.html https://github.com/kudoai/chatgpt.js/blob/main/docs/index.html

I'm adding languages offline one by one now

adamlui commented 1 year ago

It immediately fails to show the placeholder at 1 language added

                search: {
                    paths: 'auto',
                    placeholder: { '/': 'Search',
                        '/zh-cn/': '搜索' },
                    noData: { '/': 'No results!',
                        '/zh-cn/': '没有结果!' },
                    pathNamespaces: ['/zh-cn'],
                },
adamlui commented 1 year ago

however when I use the docsify/index.html format, it works

        search: {
          noData: {
            '/zh-cn/': '没有结果!',
            '/': 'No results!',
          },
          paths: 'auto',
          placeholder: {
            '/zh-cn/': '搜索',
            '/': 'Search',
          },
          pathNamespaces: ['/zh-cn'],
        },

...so it appears order of keys or values matters, something i don't recall the instructions mentioning

adamlui commented 1 year ago

I found the glitch, if / is the 1st key in either placeholder or noData then no translations show (for that obj)

adamlui commented 1 year ago

If this is intended behavior, the docs should explicitly state this because the first example

image

...makes it look like '/' should go first in obj's

adamlui commented 1 year ago

pathNamespaces: /^(\/(zh-cn|ja|ko|hi|de|es|fr|it|pt))?/ isn't indexing the translated docs though, I'm trying the docsify/index.html way now

adamlui commented 1 year ago

I can't get it to work that way either :(

trusktr commented 1 year ago

Ah, good find a out the ordering. We should definitely mention that in the docs.

I guess / matches everything, so it doesn't have a chance to fall through to try other cases (like string.match). So more-specific items should go first.

I hadn't noticed as I haven't tried translations myself yet.

5201314999 commented 4 months ago

It also has some errors in my project. It can only show the undefined, it accords to the hash of the location ? and it can search the file by the current lanaguage

 search: {
          maxAge: 86400000, // 过期时间,单位毫秒,默认一天
          paths: "auto", // or 'auto'
          // placeholder: "Search",
          placeholder: {
            "/zh-cn": "搜索",
            "/en": "Type to search",
          },

          noData: "No Results",
          depth: 2, // 搜索标题的最大层级, 1 - 6
          hideOtherSidebarContent: false, // 是否隐藏其他侧边栏内容
        },

url: chinese: http://localhost:3000/zh-cn#/. url: english: http://localhost:3000/en#/

image image