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

i18n 有問題 #973

Closed
sao-coding opened this issue Sep 9, 2024 · 2 comments · Fixed by #1007
Closed

i18n 有問題 #973

sao-coding opened this issue Sep 9, 2024 · 2 comments · Fixed by #1007

Comments

@sao-coding
Copy link
Contributor

配置
image
image

前端 Nextjs(React)

有試過強制加 locale 沒用

'use client'

import React from 'react'
import { usePathname } from 'next/navigation'
import Artalk from 'artalk'

import 'artalk/dist/Artalk.css'

const ArtalkComment = () => {
  const container = React.useRef<HTMLDivElement>(null)
  const artalk = React.useRef<Artalk>()
  const pathname = usePathname()

  React.useEffect(() => {
    artalk.current = Artalk.init({
      el: container.current!,
      pageKey: pathname,
      pageTitle: '留言板',
      server: 'http://192.168.1.11:23366',
      site: 'TIPX'
      // ...
    })

    return () => {
      artalk.current?.destroy()
    }
  }, [container, pathname])

  return <div ref={container}></div>
}

export default ArtalkComment
2024-09-09.21-36-21.mp4

結果後面試了一下 html 改 lang 也沒用

後端
image

@qwqcode
Copy link
Member

qwqcode commented Sep 10, 2024

你好!一般情況下,只需要設置環境變數 ATK_LOCALE 即可切換語言,無需其他操作。

你的 Artalk 後端伺服器是自行編譯的嗎?還是使用官方提供的二進制版本?如果是本地自行編譯,可以嘗試執行腳本 ./scripts/build-frontend.sh 來預先編譯語言包,然後重新啟動 Artalk 的 Golang 後端伺服器,執行 make dev

我簡單測試了一下,似乎沒有發現問題。我看到你影片中的問題,原因可能是前端沒有引入 i18n/zh-TW.js 語言包,導致無法切換到繁體中文。

預設情況下,語言包會自動從後端伺服器引入,像是 https://artalk.xxx/i18n/zh-TW.js。你也可以嘗試手動引入:

import ArtalkZhTW from 'artalk/i18n/zh-TW'

Artalk.init({
    locale: ArtalkZhTW,
})

另外,我注意到 zh-TW 的控制台設定介面顯示的是英文,這是因為 /conf/ 目錄下的 artalk.example.yml 檔案還沒有繁體中文翻譯,後續更新時我會補充上這部分。感謝你的反饋,也歡迎繼續提出問題!

2024-09-10.11-16-13.mp4

@sao-coding
Copy link
Contributor Author

謝謝你的回答
我是用官方提供
另外我嘗試部屬後發現
部屬後是正常顯示的,本地端也有跑js不確定是甚麼問題給你參考

2024-09-10.20-50-31.mp4

qwqcode added a commit that referenced this issue Oct 18, 2024
- Introduce a service dependency container for better management (#1006).
  - Replace original `services` definitions with `provide` and `inject` methods.
  - Recommend calling `inject` at the beginning of `ArtalkPlugin` to explicitly inject required dependencies.
- Replace `load` with `mount` for improved lifecycle handling.
  - Track local config.
  - Fix potential language setting not working issue. (Fixes #973)
- Refine Type definitions for clarity and maintainability.
  - See [TypeDoc](https://artalk.js.org/typedoc/) for updates.
- Enhance config logic with `ConfigManager`.
  - Deprecate `ctx.conf` and `ctx.$root`; use `getConf()` and `getEl()` instead.
  - Update client default config settings. (Fixes #1001)
- Improve event handling with `EventManager` refactor.
- Update plugin and editor architecture for greater flexibility.
  - Further eliminate global variables and avoid directly passing the `Context` interface as a function parameter. Instead, use more explicit and specific types and parameters.
- Remove deprecated and redundant code for a cleaner structure.

BREAKING CHANGE: This update changes the UI client's export Types. Although we aim to maintain backward compatibility, it may still affect downstream UI programs. Please refer to the [TypeDoc](https://artalk.js.org/typedoc/).
qwqcode added a commit that referenced this issue Oct 18, 2024
- Introduce a service dependency container for better management (#1006).
  - Replace original `services` definitions with `provide` and `inject` methods.
  - Recommend calling `inject` at the beginning of `ArtalkPlugin` to explicitly inject required dependencies.
- Replace `load` with `mount` for improved lifecycle handling.
  - Track local config.
  - Fix potential language setting not working issue. (Fixes #973)
- Refine Type definitions for clarity and maintainability.
  - See [TypeDoc](https://artalk.js.org/typedoc/) for updates.
- Enhance config logic with `ConfigManager`.
  - Deprecate `ctx.conf` and `ctx.$root`; use `getConf()` and `getEl()` instead.
  - Update client default config settings. (Fixes #1001)
- Improve event handling with `EventManager` refactor.
- Update plugin and editor architecture for greater flexibility.
  - Further eliminate global variables and avoid directly passing the `Context` interface as a function parameter. Instead, use more explicit and specific types and parameters.
- Remove deprecated and redundant code for a cleaner structure.

BREAKING CHANGE: This update changes the UI client's export Types. Although we aim to maintain backward compatibility, it may still affect downstream UI programs. Please refer to the [TypeDoc](https://artalk.js.org/typedoc/).
qwqcode added a commit that referenced this issue Oct 18, 2024
- Introduce a service dependency container for better management (#1006).
  - Replace original `services` definitions with `provide` and `inject` methods.
  - Recommend calling `inject` at the beginning of `ArtalkPlugin` to explicitly inject required dependencies.
- Replace `load` with `mount` for improved lifecycle handling.
  - Track local config.
  - Fix potential language setting not working issue. (Fixes #973)
- Refine Type definitions for clarity and maintainability.
  - See [TypeDoc](https://artalk.js.org/typedoc/) for updates.
- Enhance config logic with `ConfigManager`.
  - Deprecate `ctx.conf` and `ctx.$root`; use `getConf()` and `getEl()` instead.
  - Update client default config settings. (Fixes #1001)
- Improve event handling with `EventManager` refactor.
- Update plugin and editor architecture for greater flexibility.
  - Further eliminate global variables and avoid directly passing the `Context` interface as a function parameter. Instead, use more explicit and specific types and parameters.
- Remove deprecated and redundant code for a cleaner structure.

BREAKING CHANGE: This update changes the UI client's export Types. Although we aim to maintain backward compatibility, it may still affect downstream UI programs. Please refer to the [TypeDoc](https://artalk.js.org/typedoc/).
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

Successfully merging a pull request may close this issue.

2 participants