Merge pull request #702 from toeverything/feat/language-to-localstorage
feat: language local storage support
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import i18next, { Resource } from 'i18next';
|
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 { LOCALES } from './resources/index.js';
|
||||||
import type en_US from './resources/en.json';
|
import type en_US from './resources/en.json';
|
||||||
|
|
||||||
@@ -21,9 +21,9 @@ declare module 'react-i18next' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// const STORAGE_KEY = 'i18n_lng';
|
const STORAGE_KEY = 'i18n_lng';
|
||||||
|
|
||||||
export { i18n, useTranslation, LOCALES };
|
export { Trans, i18n, useTranslation, LOCALES };
|
||||||
|
|
||||||
const resources = LOCALES.reduce<Resource>(
|
const resources = LOCALES.reduce<Resource>(
|
||||||
(acc, { tag, res }) => ({ ...acc, [tag]: { translation: res } }),
|
(acc, { tag, res }) => ({ ...acc, [tag]: { translation: res } }),
|
||||||
@@ -33,17 +33,26 @@ const resources = LOCALES.reduce<Resource>(
|
|||||||
const fallbackLng = LOCALES[0].tag;
|
const fallbackLng = LOCALES[0].tag;
|
||||||
const standardizeLocale = (language: string) => {
|
const standardizeLocale = (language: string) => {
|
||||||
if (LOCALES.find(locale => locale.tag === language)) return language;
|
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()))
|
if (LOCALES.find(locale => locale.tag === language.slice(0, 2).toLowerCase()))
|
||||||
return language;
|
return language;
|
||||||
return fallbackLng;
|
return fallbackLng;
|
||||||
};
|
};
|
||||||
|
let language = 'en';
|
||||||
|
|
||||||
const language = standardizeLocale(
|
if (typeof window !== 'undefined') {
|
||||||
// localStorage.getItem(STORAGE_KEY) ??
|
const localStorageLanguage = localStorage.getItem(STORAGE_KEY);
|
||||||
// (typeof navigator !== 'undefined' ? navigator.language : 'en')
|
if (localStorageLanguage) {
|
||||||
'en'
|
language = standardizeLocale(localStorageLanguage);
|
||||||
);
|
} else {
|
||||||
|
language = standardizeLocale(navigator.language);
|
||||||
|
}
|
||||||
|
}
|
||||||
const i18n = i18next.createInstance();
|
const i18n = i18next.createInstance();
|
||||||
i18n.use(initReactI18next).init({
|
i18n.use(initReactI18next).init({
|
||||||
lng: language,
|
lng: language,
|
||||||
@@ -55,8 +64,8 @@ i18n.use(initReactI18next).init({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
i18n.on('languageChanged', () => {
|
i18n.on('languageChanged', lng => {
|
||||||
// localStorage.setItem(STORAGE_KEY, lng);
|
localStorage.setItem(STORAGE_KEY, lng);
|
||||||
});
|
});
|
||||||
|
|
||||||
// const I18nProvider = I18nextProvider;
|
// const I18nProvider = I18nextProvider;
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
{
|
{
|
||||||
"Quick search": "Quick search",
|
"Quick search": "Quick search",
|
||||||
|
"Quick search placeholder": "Quick Search...",
|
||||||
|
"Quick search placeholder2": "Search in {{workspace}}",
|
||||||
"All pages": "All pages",
|
"All pages": "All pages",
|
||||||
"Favourites": "Favourites",
|
"Favourites": "Favourites",
|
||||||
"No item": "No item",
|
"No item": "No item",
|
||||||
|
"Settings": "Settings",
|
||||||
"Import": "Import",
|
"Import": "Import",
|
||||||
"Trash": "Trash",
|
"Trash": "Trash",
|
||||||
"New Page": "New Page",
|
"New Page": "New Page",
|
||||||
@@ -54,7 +57,7 @@
|
|||||||
"Strikethrough": "Strikethrough",
|
"Strikethrough": "Strikethrough",
|
||||||
"Inline code": "Inline code",
|
"Inline code": "Inline code",
|
||||||
"Code block": "Code block",
|
"Code block": "Code block",
|
||||||
"Link": "Hyperlink(with selected text)",
|
"Link": "Hyperlink (with selected text)",
|
||||||
"Body text": "Body text",
|
"Body text": "Body text",
|
||||||
"Heading": "Heading {{number}}",
|
"Heading": "Heading {{number}}",
|
||||||
"Increase indent": "Increase indent",
|
"Increase indent": "Increase indent",
|
||||||
@@ -75,5 +78,66 @@
|
|||||||
"Restore it": "Restore it",
|
"Restore it": "Restore it",
|
||||||
"TrashButtonGroupTitle": "Permanently delete",
|
"TrashButtonGroupTitle": "Permanently delete",
|
||||||
"TrashButtonGroupDescription": "Once deleted, you can't undo this action. Do you confirm?",
|
"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</1> 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}}</1>) cannot be undone, please proceed with caution. along with all its content.",
|
||||||
|
"Delete Workspace Description2": "Deleting (<1>{{workspace}}</1>) 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}}</1> 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}}</1> 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"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user