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

Issues/214 #338

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion demo/src/app/home/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use client"

import AuthInitializer from "@/components/authInitializer"
import { isMobile } from "@/common"
import { getBrowserLanguage, isMobile, useAppDispatch } from "@/common"
import dynamic from 'next/dynamic'
import { useEffect, useState } from "react"
import { setLanguage } from "@/store/reducers/global"

const PCEntry = dynamic(() => import('@/platform/pc/entry'), {
ssr: false,
Expand All @@ -15,9 +16,12 @@ const MobileEntry = dynamic(() => import('@/platform/mobile/entry'), {

export default function Home() {
const [mobile, setMobile] = useState<boolean | null>(null);
const dispatch = useAppDispatch()


useEffect(() => {
setMobile(isMobile())
dispatch(setLanguage(getBrowserLanguage().value))
})

return (
Expand Down
32 changes: 31 additions & 1 deletion demo/src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LanguageOptionItem } from "@/types"

export const genRandomString = (length: number = 10) => {
let result = '';
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
Expand Down Expand Up @@ -56,4 +58,32 @@ export const genUUID = () => {

export const isMobile = () => {
return /Mobile|iPhone|iPad|Android|Windows Phone/i.test(navigator.userAgent)
}
}


export const getBrowserLanguage = (): LanguageOptionItem => {
const lang = navigator.language;

switch (true) {
case lang.startsWith("zh"):
return {
label: "Chinese",
value: "zh-CN"
};
case lang.startsWith("ko"):
return {
label: "Korean",
value: "ko-KR"
};
case lang.startsWith("ja"):
return {
label: "Japanese",
value: "ja-JP"
};
default:
return {
label: "English",
value: "en-US"
};
}
};
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
- AGENT_SERVER_URL=http://ten_agent_dev:8080
- TEN_DEV_SERVER_URL=http://ten_agent_dev:49483
ten_agent_demo:
image: ghcr.io/ten-framework/agent_demo
image: ghcr.io/ten-framework/ten_agent_demo:0.5.0-43-ga6ea980
container_name: ten_agent_demo
restart: always
ports:
Expand Down