[GH-ISSUE #1025] Can't load zh-CN or zh-TW #674

Closed
opened 2026-02-25 22:37:48 +03:00 by kerem · 1 comment
Owner

Originally created by @binsee on GitHub (Jan 28, 2022).
Original GitHub issue: https://github.com/floccusaddon/floccus/issues/1025

Describe the bug

Simplified Chinese (zh-CN) and Traditional Chinese (zh-TW) cannot be loaded.

To Reproduce

Steps to reproduce the behavior:

  1. Add Chinese in chrome chrome://settings/languages
  2. Open the floccus page 'chrome-extension://fnaicdffflnofjppbagibeoednhnbjhg/dist/html/options.html#/'
  3. You will find that the Chinese text is not displayed
  4. Click the F12 key to open Devtools
  5. Click the F5 key to refresh the page
  6. You can see the error messages in Devtools:
options.js:2 Error: Cannot find module './zh-CN.json'
    at r (options.js:2:287)
    at a (options.js:2:236)
    at options.js:2:1293669
options.js:2 Error: Cannot find module './zh.json'
    at r (options.js:2:287)
    at a (options.js:2:236)
    at options.js:2:1293898

image

Expected behavior

Dispaly Chinese text.

Screenshots

image

Desktop

(please complete the following information)

  • OS: Windows 11 / Android 11
  • Browser Chrome
  • Browser Version 97
  • Floccus version: 4.9.0 / 4.8.7
  • Floccus sync method: webdav

Server

(please complete the following information)

Note: Please write down the actual version numbers instead of writing 'latest'.

Debug log

It is often useful to provide a debug log file along with the issue. You can obtain a debug log of the most recent sync runs by clicking 'Debug log' in the bottom right corner of the floccus panel in your browser.

Note: As your debug log usually contains large parts of your bookmark data, instead of attaching it publicly to the issue here, I recommend uploading it privately at the following URL https://cloud.marcelklehr.de/s/PCi3iLWrzdMZSmw

  • Debug log provided

Additional context

The code to load the language in floccus is as follows:

// src\ui\index.js
i18n.setLocales(navigator.languages)
i18n.load()

// src\lib\native\I18n.ts
  async load():Promise<void> {
    for (const locale of this.locales) {
      try {
        this.messages = (await import(`../../../dist/_locales/${locale}.json`)).default
        this.locale = locale
        break
      } catch (error) {
        console.warn(error)
      }
      try {
        this.messages = (await import(`../../../dist/_locales/${locale.split('-')[0]}.json`)).default
        this.locale = locale.split('-')[0]
        break
      } catch (error) {
        console.warn(error)
      }
    }
  }

navigator.languages return:

navigator.languages
(2) ['zh-CN', 'zh']

In strings returned by navigator.languages, use the symbol - instead of _.

In the code of floccus, the symbol - is used to find the translation file, but the symbol _ is used in the translation file name.

As a result, translation files whose filenames use the symbol _ cannot be loaded.

Originally created by @binsee on GitHub (Jan 28, 2022). Original GitHub issue: https://github.com/floccusaddon/floccus/issues/1025 ### Describe the bug Simplified Chinese (`zh-CN`) and Traditional Chinese (`zh-TW`) cannot be loaded. ### To Reproduce Steps to reproduce the behavior: 1. Add Chinese in chrome `chrome://settings/languages` 2. Open the floccus page 'chrome-extension://fnaicdffflnofjppbagibeoednhnbjhg/dist/html/options.html#/' 3. You will find that the Chinese text is not displayed 4. Click the `F12` key to open Devtools 5. Click the `F5` key to refresh the page 6. You can see the error messages in Devtools: ```js options.js:2 Error: Cannot find module './zh-CN.json' at r (options.js:2:287) at a (options.js:2:236) at options.js:2:1293669 options.js:2 Error: Cannot find module './zh.json' at r (options.js:2:287) at a (options.js:2:236) at options.js:2:1293898 ``` ![image](https://user-images.githubusercontent.com/5285894/151582424-e73cfa7e-56d0-4e4b-87c0-1708debdeea6.png) ### Expected behavior Dispaly Chinese text. ### Screenshots ![image](https://user-images.githubusercontent.com/5285894/151581705-efacfeea-cc72-40db-98c9-667bb5786961.png) ### Desktop (please complete the following information) - OS: Windows 11 / Android 11 - Browser Chrome - Browser Version 97 - Floccus version: 4.9.0 / 4.8.7 - Floccus sync method: webdav ### Server (please complete the following information) Note: Please write down the actual version numbers instead of writing 'latest'. ### Debug log It is often useful to provide a debug log file along with the issue. You can obtain a debug log of the most recent sync runs by clicking 'Debug log' in the bottom right corner of the floccus panel in your browser. Note: As your debug log usually contains large parts of your bookmark data, instead of attaching it publicly to the issue here, I recommend uploading it privately at the following URL https://cloud.marcelklehr.de/s/PCi3iLWrzdMZSmw - [ ] Debug log provided ### Additional context The code to load the language in floccus is as follows: ```js // src\ui\index.js i18n.setLocales(navigator.languages) i18n.load() // src\lib\native\I18n.ts async load():Promise<void> { for (const locale of this.locales) { try { this.messages = (await import(`../../../dist/_locales/${locale}.json`)).default this.locale = locale break } catch (error) { console.warn(error) } try { this.messages = (await import(`../../../dist/_locales/${locale.split('-')[0]}.json`)).default this.locale = locale.split('-')[0] break } catch (error) { console.warn(error) } } } ``` `navigator.languages` return: ```js navigator.languages (2) ['zh-CN', 'zh'] ``` In strings returned by navigator.languages, use the symbol `-` instead of `_`. In the code of floccus, the symbol `-` is used to find the translation file, but the symbol `_` is used in the translation file name. As a result, translation files whose filenames use the symbol `_` cannot be loaded.
kerem 2026-02-25 22:37:48 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Mar 20, 2023):

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

<!-- gh-comment-id:1476307795 --> @github-actions[bot] commented on GitHub (Mar 20, 2023): This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/floccus#674
No description provided.