Skip to content

Commit

Permalink
Issues/214 (#338)
Browse files Browse the repository at this point in the history
* feat: set language based on browser setting

* feat: update image
  • Loading branch information
plutoless authored Oct 17, 2024
1 parent e1cf48e commit 9659896
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
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

0 comments on commit 9659896

Please sign in to comment.