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

dify-web got Invalid languages error #9925

Closed
5 tasks done
seikyo-cho-lvgs opened this issue Oct 28, 2024 · 1 comment · Fixed by #9928
Closed
5 tasks done

dify-web got Invalid languages error #9925

seikyo-cho-lvgs opened this issue Oct 28, 2024 · 1 comment · Fixed by #9928
Labels
🐞 bug Something isn't working

Comments

@seikyo-cho-lvgs
Copy link
Contributor

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.10.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I deploy dify on Kubernetes with helm chart. This error always happen in the dify-web pod:

01:00:10 1|dify-web  | Invalid languages: *
01:00:10 1|dify-web  | Invalid languages: *
01:00:10 1|dify-web  | Invalid languages: *

I can find the locale cookie is en in the browser cache.
But it got * in frontend application.

Source:

dify/web/i18n/server.ts

Lines 41 to 53 in b674c59

if (!languages.length) {
// Negotiator expects plain object so we need to transform headers
const negotiatorHeaders: Record<string, string> = {}
headers().forEach((value, key) => (negotiatorHeaders[key] = value))
// Use negotiator and intl-localematcher to get best locale
languages = new Negotiator({ headers: negotiatorHeaders }).languages()
}
// Validate languages
if (!Array.isArray(languages) || languages.length === 0 || !languages.every(lang => typeof lang === 'string' && /^[\w-]+$/.test(lang))) {
console.error(`Invalid languages: ${languages}`)
languages = [i18n.defaultLocale]
}

✔️ Expected Behavior

No error.

❌ Actual Behavior

The error happened every minute.

@dosubot dosubot bot added the 🐞 bug Something isn't working label Oct 28, 2024
Copy link

dosubot bot commented Oct 28, 2024

I found a similar unsolved discussion regarding the "Invalid languages" error in the Dify repository. You can check it out here: dify-web got Invalid languages error [1].

Regarding the issue you're facing, the error message "Invalid languages: " suggests that the languages array is being populated with an invalid entry, specifically the '' character. This typically happens when the locale is not correctly set or recognized.

Here are a few things you might want to check:

  1. Locale Cookie: Ensure that the locale cookie is correctly set to a valid language code. The expected format should match one of the supported languages, such as en-US or zh-Hans [2].

  2. Helm Chart Configuration: Verify the i18n.locale setting in your Helm chart configuration. It should be set to a supported language, like en or zh-CN [3].

  3. Server Code: In the server.ts file, the languages array is populated from cookies and request headers. If the locale is not correctly set in the cookie, the Negotiator library will attempt to determine the preferred languages from the request headers. Ensure that the headers are correctly configured and that the Negotiator is functioning as expected [4].

By addressing these areas, you should be able to resolve the "Invalid languages" error. If the issue persists, further investigation into the server-side handling of locales might be necessary.

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant