docsify icon indicating copy to clipboard operation
docsify copied to clipboard

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

Open adamlui opened this issue 2 years ago • 11 comments

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))?/
    },
  1. Visit the homepage
  2. Change languages
  3. 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

  • [x] Bug does still occur when all/other plugins are disabled?

  • Your OS: Windows 10

  • Node.js version: 18.15.0

  • npm/yarn version: 9.5.0

  • Browser version: 114.0.2

  • Docsify version: 4.13.0

  • Docsify plugins: search, code-copy

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)

adamlui avatar Jul 15 '23 20:07 adamlui

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.

trusktr avatar Jul 15 '23 22:07 trusktr

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 avatar Jul 15 '23 22:07 adamlui

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 avatar Jul 15 '23 22:07 adamlui

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 avatar Jul 15 '23 22:07 adamlui

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

adamlui avatar Jul 15 '23 22:07 adamlui

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 avatar Jul 15 '23 22:07 adamlui

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 avatar Jul 15 '23 23:07 adamlui

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

adamlui avatar Jul 15 '23 23:07 adamlui

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.

trusktr avatar Jul 15 '23 23:07 trusktr

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

5201314999 avatar Jul 30 '24 03:07 5201314999