Skip to content

Commit

Permalink
Merge branch 'main' into renovate/tslib-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
easy1090 authored Nov 5, 2024
2 parents 9b4f855 + c3a64ca commit 208c711
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 71 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/cli",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/client",
"version": "0.4.7",
"version": "0.4.8",
"main": "dist/index.html",
"repository": {
"type": "git",
Expand Down Expand Up @@ -43,7 +43,7 @@
"normalize.css": "8.0.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-error-boundary": "^4.0.13",
"react-error-boundary": "^4.1.2",
"react-router-dom": "6.4.3",
"serve-static": "1.16.2",
"typescript": "^5.2.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/components",
"version": "0.4.7",
"version": "0.4.8",
"main": "./dist/index.js",
"license": "MIT",
"module": "dist/index.js",
Expand Down Expand Up @@ -81,7 +81,7 @@
"react-markdown": "^9.0.1",
"react-router-dom": "6.4.3",
"socket.io-client": "4.6.1",
"terser": "^5.34.1",
"terser": "^5.36.0",
"typescript": "^5.2.2",
"url-parse": "1.5.10"
},
Expand Down
27 changes: 23 additions & 4 deletions packages/components/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { PropsWithChildren, useContext, useEffect } from 'react';
import { FloatButton, Layout as L } from 'antd';
import { MAIN_BG, Size } from '../../constants';
import { Language, MAIN_BG, Size } from '../../constants';
import { Header } from './header';
import { useLocale, useI18n } from '../../utils';
import {
useLocale,
useI18n,
getFirstVisitFromStorage,
setFirstVisitToStorage,
getLanguage,
} from '../../utils';
import { Progress } from './progress';
import { ConfigContext } from '../../config';

Expand All @@ -16,8 +22,21 @@ export const Layout = (props: PropsWithChildren<LayoutProps>): JSX.Element => {
const { children } = props;

useEffect(() => {
if (i18n.language !== locale) {
i18n.changeLanguage(locale);
let currentLocale = locale;
// Check if the user is visiting the site for the first time
const visited = getFirstVisitFromStorage();
if (!visited) {
setFirstVisitToStorage('1');
const targetLang = window.navigator.language.split('-')[0];
const userLang = getLanguage(targetLang);

if (Object.values(Language).includes(userLang)) {
currentLocale = userLang;
}
}

if (i18n.language !== currentLocale) {
i18n.changeLanguage(currentLocale);
}
}, [locale]);

Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/utils/locale.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import cn from 'antd/es/locale/zh_CN';
import en from 'antd/es/locale/en_GB';
import type { Locale } from 'antd/es/locale';
import { Language } from '../constants';

export function getLocale(locale: string): Locale {
const res = locale === 'cn' || locale === 'zh-CN' ? cn : en;
return res;
}

export function getLanguage(locale: string): Language {
const res = locale === 'cn' || locale === 'zh' ? Language.Cn : Language.En;
return res;
}
9 changes: 9 additions & 0 deletions packages/components/src/utils/storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum Keys {
Locale = 'LOCALE',
ViewMode = 'VIEWMODE',
APILoaderMode4Dev = 'APILOADERMODE_DEV',
FirstVisit = 'FIRST_VISIT'
}

export function getStorage(key: string): string | null {
Expand Down Expand Up @@ -67,3 +68,11 @@ export function setAPILoaderModeToStorage(mode: APILoaderMode4Dev) {
export function getAPILoaderModeFromStorage() {
return getStorage(Keys.APILoaderMode4Dev) || APILoaderMode4Dev.Default;
}

export function getFirstVisitFromStorage() {
return getStorage(Keys.FirstVisit);
}

export function setFirstVisitToStorage(value: '1') {
setStorage(Keys.FirstVisit, value);
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/core",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/document/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/docs",
"version": "0.4.7",
"version": "0.4.8",
"scripts": {
"dev": "rspress dev",
"build": "rspress build",
Expand Down
2 changes: 1 addition & 1 deletion packages/graph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/graph",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/rspack-plugin",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/sdk",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/types",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/utils",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/webpack-plugin",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
Loading

0 comments on commit 208c711

Please sign in to comment.