From dc4a69593bbd4dff4659219c74a58422e3950104 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:11:28 +0800 Subject: [PATCH 1/7] feat: export Trans component --- packages/i18n/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/i18n/src/index.ts b/packages/i18n/src/index.ts index a3fd46a1d2..cef066bb29 100644 --- a/packages/i18n/src/index.ts +++ b/packages/i18n/src/index.ts @@ -1,5 +1,5 @@ import i18next, { Resource } from 'i18next'; -import { initReactI18next, useTranslation } from 'react-i18next'; +import { Trans, initReactI18next, useTranslation } from 'react-i18next'; import { LOCALES } from './resources/index.js'; import type en_US from './resources/en.json'; @@ -23,7 +23,7 @@ declare module 'react-i18next' { // const STORAGE_KEY = 'i18n_lng'; -export { i18n, useTranslation, LOCALES }; +export { Trans, i18n, useTranslation, LOCALES }; const resources = LOCALES.reduce( (acc, { tag, res }) => ({ ...acc, [tag]: { translation: res } }), From d0da2a16c3105b47e4d9f85d3ba45665b3b2c1f6 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:14:17 +0800 Subject: [PATCH 2/7] feat: init languageDetector --- packages/i18n/package.json | 1 + packages/i18n/src/index.ts | 22 +++++++++++++--------- pnpm-lock.yaml | 8 ++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/i18n/package.json b/packages/i18n/package.json index cc559528e3..d4754700fb 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -19,6 +19,7 @@ }, "dependencies": { "i18next": "^21.9.1", + "i18next-browser-languagedetector": "^7.0.1", "prettier": "^2.7.1", "react-i18next": "^11.18.4" }, diff --git a/packages/i18n/src/index.ts b/packages/i18n/src/index.ts index cef066bb29..4095c417ad 100644 --- a/packages/i18n/src/index.ts +++ b/packages/i18n/src/index.ts @@ -1,5 +1,6 @@ import i18next, { Resource } from 'i18next'; import { Trans, initReactI18next, useTranslation } from 'react-i18next'; +import detector from 'i18next-browser-languagedetector'; import { LOCALES } from './resources/index.js'; import type en_US from './resources/en.json'; @@ -45,15 +46,18 @@ const language = standardizeLocale( ); const i18n = i18next.createInstance(); -i18n.use(initReactI18next).init({ - lng: language, - fallbackLng, - debug: false, - resources, - interpolation: { - escapeValue: false, // not needed for react as it escapes by default - }, -}); +i18n + .use(detector) + .use(initReactI18next) + .init({ + lng: language, + fallbackLng, + debug: false, + resources, + interpolation: { + escapeValue: false, // not needed for react as it escapes by default + }, + }); i18n.on('languageChanged', () => { // localStorage.setItem(STORAGE_KEY, lng); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76ec8caa50..f37413be2d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -162,11 +162,13 @@ importers: specifiers: '@types/prettier': ^2.7.2 i18next: ^21.9.1 + i18next-browser-languagedetector: ^7.0.1 prettier: ^2.7.1 react-i18next: ^11.18.4 typescript: ^4.8.4 dependencies: i18next: 21.10.0 + i18next-browser-languagedetector: 7.0.1 prettier: 2.7.1 react-i18next: 11.18.6_i18next@21.10.0 devDependencies: @@ -5610,6 +5612,12 @@ packages: hasBin: true dev: true + /i18next-browser-languagedetector/7.0.1: + resolution: {integrity: sha512-Pa5kFwaczXJAeHE56CHG2aWzFBMJNUNghf0Pm4SwSrEMps/PTKqW90EYWlIvhuYStf3Sn1K0vw+gH3+TLdkH1g==} + dependencies: + '@babel/runtime': 7.20.7 + dev: false + /i18next/21.10.0: resolution: {integrity: sha512-YeuIBmFsGjUfO3qBmMOc0rQaun4mIpGKET5WDwvu8lU7gvwpcariZLNtL0Fzj+zazcHUrlXHiptcFhBMFaxzfg==} dependencies: From b3e703b6562d3ffed59098e7a829a94f37ca95aa Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:45:48 +0800 Subject: [PATCH 3/7] chore: remove language detector --- packages/i18n/package.json | 1 - pnpm-lock.yaml | 8 -------- 2 files changed, 9 deletions(-) diff --git a/packages/i18n/package.json b/packages/i18n/package.json index d4754700fb..cc559528e3 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -19,7 +19,6 @@ }, "dependencies": { "i18next": "^21.9.1", - "i18next-browser-languagedetector": "^7.0.1", "prettier": "^2.7.1", "react-i18next": "^11.18.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f37413be2d..76ec8caa50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -162,13 +162,11 @@ importers: specifiers: '@types/prettier': ^2.7.2 i18next: ^21.9.1 - i18next-browser-languagedetector: ^7.0.1 prettier: ^2.7.1 react-i18next: ^11.18.4 typescript: ^4.8.4 dependencies: i18next: 21.10.0 - i18next-browser-languagedetector: 7.0.1 prettier: 2.7.1 react-i18next: 11.18.6_i18next@21.10.0 devDependencies: @@ -5612,12 +5610,6 @@ packages: hasBin: true dev: true - /i18next-browser-languagedetector/7.0.1: - resolution: {integrity: sha512-Pa5kFwaczXJAeHE56CHG2aWzFBMJNUNghf0Pm4SwSrEMps/PTKqW90EYWlIvhuYStf3Sn1K0vw+gH3+TLdkH1g==} - dependencies: - '@babel/runtime': 7.20.7 - dev: false - /i18next/21.10.0: resolution: {integrity: sha512-YeuIBmFsGjUfO3qBmMOc0rQaun4mIpGKET5WDwvu8lU7gvwpcariZLNtL0Fzj+zazcHUrlXHiptcFhBMFaxzfg==} dependencies: From d0d0955c0e811ce951640cc7ec0e82ef64ff6276 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:47:13 +0800 Subject: [PATCH 4/7] feat: add language local storage --- packages/i18n/src/index.ts | 49 +++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/i18n/src/index.ts b/packages/i18n/src/index.ts index 4095c417ad..714cc40f31 100644 --- a/packages/i18n/src/index.ts +++ b/packages/i18n/src/index.ts @@ -1,6 +1,5 @@ import i18next, { Resource } from 'i18next'; import { Trans, initReactI18next, useTranslation } from 'react-i18next'; -import detector from 'i18next-browser-languagedetector'; import { LOCALES } from './resources/index.js'; import type en_US from './resources/en.json'; @@ -22,7 +21,7 @@ declare module 'react-i18next' { } } -// const STORAGE_KEY = 'i18n_lng'; +const STORAGE_KEY = 'i18n_lng'; export { Trans, i18n, useTranslation, LOCALES }; @@ -34,33 +33,39 @@ const resources = LOCALES.reduce( const fallbackLng = LOCALES[0].tag; const standardizeLocale = (language: string) => { if (LOCALES.find(locale => locale.tag === language)) return language; + if (language === 'zh-CN' || language === 'zh') { + return 'zh-Hans'; + } + if (language.slice(0, 2).toLowerCase() === 'zh') { + return 'zh-Hant'; + } if (LOCALES.find(locale => locale.tag === language.slice(0, 2).toLowerCase())) return language; return fallbackLng; }; +let language = 'en'; -const language = standardizeLocale( - // localStorage.getItem(STORAGE_KEY) ?? - // (typeof navigator !== 'undefined' ? navigator.language : 'en') - 'en' -); - +if (typeof window !== 'undefined') { + const localStorageLanguage = localStorage.getItem(STORAGE_KEY); + if (localStorageLanguage) { + language = standardizeLocale(localStorageLanguage); + } else { + language = standardizeLocale(navigator.language); + } +} const i18n = i18next.createInstance(); -i18n - .use(detector) - .use(initReactI18next) - .init({ - lng: language, - fallbackLng, - debug: false, - resources, - interpolation: { - escapeValue: false, // not needed for react as it escapes by default - }, - }); +i18n.use(initReactI18next).init({ + lng: language, + fallbackLng, + debug: false, + resources, + interpolation: { + escapeValue: false, // not needed for react as it escapes by default + }, +}); -i18n.on('languageChanged', () => { - // localStorage.setItem(STORAGE_KEY, lng); +i18n.on('languageChanged', lng => { + localStorage.setItem(STORAGE_KEY, lng); }); // const I18nProvider = I18nextProvider; From 7860c563c73193f527b42ea40da029bf05299b56 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:49:04 +0800 Subject: [PATCH 5/7] chore: update i18n json --- packages/i18n/src/resources/en.json | 68 +++++++++++++++++++++++- packages/i18n/src/resources/zh-Hans.json | 66 +---------------------- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index 78dcb2fb28..49a6bf3ab1 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -1,8 +1,11 @@ { "Quick search": "Quick search", + "Quick search placeholder": "Quick Search...", + "Quick search placeholder2": "Search in {{workspace}}", "All pages": "All pages", "Favourites": "Favourites", "No item": "No item", + "Settings": "Settings", "Import": "Import", "Trash": "Trash", "New Page": "New Page", @@ -54,7 +57,7 @@ "Strikethrough": "Strikethrough", "Inline code": "Inline code", "Code block": "Code block", - "Link": "Hyperlink(with selected text)", + "Hyperlink(with selected text)": "Hyperlink(with selected text)", "Body text": "Body text", "Heading": "Heading {{number}}", "Increase indent": "Increase indent", @@ -75,5 +78,66 @@ "Restore it": "Restore it", "TrashButtonGroupTitle": "Permanently delete", "TrashButtonGroupDescription": "Once deleted, you can't undo this action. Do you confirm?", - "Delete permanently": "Delete permanently" + "Delete permanently": "Delete permanently", + "recommendBrowser": " We recommend the <1>Chrome browser for optimal experience.", + "upgradeBrowser": "Please upgrade to the latest version of Chrome for the best experience.", + "Invite Members": "Invite Members", + "Invite placeholder": "Search mail (Gmail support only)", + "Non-Gmail": "Non-Gmail is not supported", + "Invite": "Invite", + "Loading": "Loading...", + "NotLoggedIn": "Currently not logged in", + "ClearData": "Clear local data", + "Continue with Google": "Continue with Google", + "Set up an AFFiNE account to sync data": "Set up an AFFiNE account to sync data", + "Stay logged out": "Stay logged out", + "All changes are saved locally": "All changes are saved locally", + "Ooops!": "Ooops!", + "mobile device": "Looks like you are browsing on a mobile device.", + "mobile device description": "We are still working on mobile support and recommend you use a desktop device.", + "Got it": "Got it", + "emptyAllPages": "This workspace is empty. Create a new page to begin editing.", + "emptyFavourite": "Click Add to Favourites and the page will appear here.", + "emptyTrash": "Click Add to Trash and the page will appear here.", + "still designed": "(This page is still being designed.)", + "My Workspaces": "My Workspaces", + "Create Or Import": "Create Or Import", + "Tips": "Tips: ", + "login success": "Login success", + "Sign in": "Sign in AFFiNE Cloud", + "Sign out": "Sign out of AFFiNE Cloud", + "Delete Workspace": "Delete Workspace", + "Delete Workspace Description": "Deleting (<1>{{workspace}}) cannot be undone, please proceed with caution. along with all its content.", + "Delete Workspace Description2": "Deleting (<1>{{workspace}}) will delete both local and cloud data, this operation cannot be undone, please proceed with caution.", + "Delete Workspace placeholder": "Please type “Delete” to confirm", + "Leave Workspace": "Leave Workspace", + "Leave Workspace Description": "After you leave, you will not be able to access all the contents of this workspace.", + "Leave": "Leave", + "Workspace Icon": "Workspace Icon", + "Workspace Name": "Workspace Name", + "Workspace Type": "Workspace Type", + "Export Workspace": "Export Workspace <1>{{workspace}} Is Coming", + "Users": "Users", + "Access level": "Access level", + "Pending": "Pending", + "Collaboration Description": "Collaborating with other members requires AFFiNE Cloud service.", + "Enable AFFiNE Cloud": "Enable AFFiNE Cloud", + "Enable AFFiNE Cloud Description": "If enabled, the data in this workspace will be backed up and synchronised via AFFiNE Cloud.", + "Enable": "Enable", + "Sign in and Enable": "Sign in and Enable", + "Skip": "Skip", + "Publishing": "Publishing to web requires AFFiNE Cloud service.", + "Share with link": "Share with link", + "Copy Link": "Copy Link", + "Publishing Description": "After publishing to the web, everyone can view the content of this workspace through the link.", + "Stop publishing": "Stop publishing", + "Publish to web": "Publish to web", + "Sync Description": "{{workspaceName}} is Local Workspace. All data is stored on the current device. You can enable AFFiNE Cloud for this workspace to keep data in sync with the cloud.", + "Sync Description2": "<1>{{workspaceName}} is Cloud Workspace. All data will be synchronized and saved to the AFFiNE", + "Download data to device": "Download {{CoreOrAll}} data to device", + "General": "General", + "Sync": "Sync", + "Collaboration": "Collaboration", + "Publish": "Publish", + "Workspace Settings": "Workspace Settings" } diff --git a/packages/i18n/src/resources/zh-Hans.json b/packages/i18n/src/resources/zh-Hans.json index 47095233d9..0967ef424b 100644 --- a/packages/i18n/src/resources/zh-Hans.json +++ b/packages/i18n/src/resources/zh-Hans.json @@ -1,65 +1 @@ -{ - "Quick search": "快速搜索", - "All pages": "全部页面", - "Favourites": "收藏夹", - "No item": "没有项目", - "Import": "导入", - "Trash": "回收站", - "New Page": "新建文章", - "New Keyword Page": "新建 '{{query}}' 为标题的文章", - "Find 0 result": "找到 0 个结果", - "Find results": "找到 {{number}} 个结果", - "Collapse sidebar": "关闭侧边栏", - "Expand sidebar": "展开侧边栏", - "Removed from Favourites": "已从收藏中移除", - "Remove from favourites": "从收藏中移除", - "Added to Favourites": "已添加到收藏", - "Add to favourites": "添加到收藏", - "Paper": "文章", - "Edgeless": "无边模式", - "Switch to": "跳转到", - "Convert to ": "转换成 ", - "Page": "文章", - "Export": "导出", - "Export to HTML": "导出到 HTML", - "Export to Markdown": "导出到 Markdown", - "Delete": "删除", - "Title": "标题", - "Untitled": "无标题", - "Created": "创建时间", - "Updated": "更新时间", - "Open in new tab": "在新页面打开", - "Favourite": "收藏", - "Favourited": "已收藏", - "Delete page?": "删除文章?", - "Delete permanently?": "永久删除?", - "will be moved to Trash": "{{title}} 将被移动到回收站", - "Once deleted, you can't undo this action.": "一次性删除,无法恢复。", - "Moved to Trash": "已移动到回收站", - "Permanently deleted": "已永久删除", - "restored": "{{title}} 已恢复", - "Cancel": "取消", - "Keyboard Shortcuts": "快捷键", - "Contact Us": "联系我们", - "Official Website": "官网", - "Get in touch!": "Get in touch!", - "AFFiNE Community": "AFFiNE Community", - "How is AFFiNE Alpha different?": "How is AFFiNE Alpha different?", - "Shortcuts": "Shortcuts", - "Undo": "Undo", - "Redo": "Redo", - "Bold": "Bold", - "Italic": "Italic", - "Underline": "Underline", - "Strikethrough": "Strikethrough", - "Inline code": "Inline code", - "Code block": "Code block", - "Link": "Link", - "Body text": "Body text", - "Heading": "Heading {{number}}", - "Increase indent": "Increase indent", - "Reduce indent": "Reduce indent", - "Markdown Syntax": "Markdown Syntax", - "Divider": "Divider", - "404 - Page Not Found": "404 - Page Not Found" -} +{} From 5189086c1b663d59fe32fd2ad4bf0ae9ef96fa73 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 19:03:20 +0800 Subject: [PATCH 6/7] chore: update keys --- packages/i18n/src/resources/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index 49a6bf3ab1..635c083af3 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -57,7 +57,7 @@ "Strikethrough": "Strikethrough", "Inline code": "Inline code", "Code block": "Code block", - "Hyperlink(with selected text)": "Hyperlink(with selected text)", + "Link": "Hyperlink(with selected text)", "Body text": "Body text", "Heading": "Heading {{number}}", "Increase indent": "Increase indent", From c8ac8c5738342b87c7bafd71cbe5ee35fafae2e7 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 19:05:55 +0800 Subject: [PATCH 7/7] chore: update json --- packages/i18n/src/resources/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index 635c083af3..761f649c18 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -57,7 +57,7 @@ "Strikethrough": "Strikethrough", "Inline code": "Inline code", "Code block": "Code block", - "Link": "Hyperlink(with selected text)", + "Link": "Hyperlink (with selected text)", "Body text": "Body text", "Heading": "Heading {{number}}", "Increase indent": "Increase indent",