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

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

Open
1 task done
adamlui opened this issue Jul 15, 2023 · 10 comments
Open
1 task done

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

adamlui opened this issue Jul 15, 2023 · 10 comments

Comments

@adamlui
Copy link

adamlui commented Jul 15, 2023

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

  • 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)

@trusktr
Copy link
Member

trusktr commented Jul 15, 2023

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

search: {

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
Copy link
Author

adamlui commented Jul 15, 2023

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
Copy link
Author

adamlui commented Jul 15, 2023

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
Copy link
Author

adamlui commented Jul 15, 2023

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
Copy link
Author

adamlui commented Jul 15, 2023

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

@adamlui
Copy link
Author

adamlui commented Jul 15, 2023

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
Copy link
Author

adamlui commented Jul 15, 2023

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
Copy link
Author

adamlui commented Jul 15, 2023

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

@trusktr
Copy link
Member

trusktr commented Jul 15, 2023

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
Copy link

5201314999 commented Jul 30, 2024

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

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

No branches or pull requests

3 participants