feat: extract i18n into a package

This commit is contained in:
JimmFly
2023-01-09 14:55:38 +08:00
parent 20e2984c04
commit 047537101c
22 changed files with 172 additions and 170 deletions

View File

@@ -10,6 +10,7 @@
},
"dependencies": {
"@affine/datacenter": "workspace:*",
"@affine/i18n": "workspace:*",
"@blocksuite/blocks": "0.3.1-20230109032243-37ad3ba",
"@blocksuite/editor": "0.3.1-20230109032243-37ad3ba",
"@blocksuite/icons": "^2.0.2",
@@ -27,7 +28,6 @@
"cmdk": "^0.1.20",
"css-spring": "^4.1.0",
"dayjs": "^1.11.7",
"i18next": "^21.9.1",
"lit": "^2.3.1",
"next": "13.1.0",
"next-debug-local": "^0.1.5",
@@ -36,7 +36,6 @@
"quill-cursors": "^4.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-i18next": "^11.18.4",
"yjs": "^13.5.44"
},
"devDependencies": {

View File

@@ -1,66 +0,0 @@
import i18next, { Resource } from 'i18next';
import {
I18nextProvider,
initReactI18next,
useTranslation,
} from 'react-i18next';
import { LOCALES } from './resources';
import type en_US from './resources/en.json';
// const localStorage = {
// getItem() {
// return undefined;
// },
// setItem() {},
// };
// See https://react.i18next.com/latest/typescript
declare module 'react-i18next' {
interface CustomTypeOptions {
// custom namespace type if you changed it
// defaultNS: 'ns1';
// custom resources type
resources: {
en: typeof en_US;
};
}
}
// const STORAGE_KEY = 'i18n_lng';
export { i18n, useTranslation, I18nProvider, LOCALES };
const resources = LOCALES.reduce<Resource>(
(acc, { tag, res }) => ({ ...acc, [tag]: { translation: res } }),
{}
);
const fallbackLng = LOCALES[0].tag;
const standardizeLocale = (language: string) => {
if (LOCALES.find(locale => locale.tag === language)) return language;
if (LOCALES.find(locale => locale.tag === language.slice(0, 2).toLowerCase()))
return language;
return fallbackLng;
};
const language = standardizeLocale(
// localStorage.getItem(STORAGE_KEY) ??
// (typeof navigator !== 'undefined' ? navigator.language : 'en')
'en'
);
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.on('languageChanged', () => {
// localStorage.setItem(STORAGE_KEY, lng);
});
const I18nProvider = I18nextProvider;

View File

@@ -1,22 +0,0 @@
{
"// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.": "",
"Add A Below Block": "নীচে একটি ব্লক যোগ করুন",
"WarningTips": {
"IsNotfsApiSupported": "অ্যাফাইন ডেমোতে স্বাগতম। পরিবর্তনগুলি সংরক্ষণ করা শুরু করতে আপনি Chrome/Edge এর মতো ক্রোমিয়াম ভিত্তিক ব্রাউজারের সর্বশেষ সংস্করণের মাধ্যমে ডিস্কে ডেটা সিঙ্ক করতে পারেন",
"DoNotStore": "অ্যাফাইন সক্রিয় ডেভেলপমেন্ট এর অধীনে এবং বর্তমান সংস্করণটি অস্থিতিশীল। দয়া করে কোন তথ্য বা ডেটা সঞ্চয় করবেন না"
},
"Language": "ভাষা",
"Settings": "সেটিংস",
"Share": "শেয়ার করুন",
"Comment": "মন্তব্য",
"Delete": "মুছে ফেলুন",
"Copy Page Link": "পেজ লিংক কপি করুন",
"Duplicate Page": "সদৃশ পৃষ্ঠা তৈরি করুন",
"Logout": "লগআউট",
"Divide Here As A New Group": "একটি নতুন গ্রুপ হিসেবে বিভক্ত করুন",
"ComingSoon": "লেআউট সেটিংস শীঘ্রই আসছে...",
"Clear Workspace": "ওয়ার্কস্পেস পরিষ্কার করুন",
"Layout": "লেআউট",
"Turn into": "রূপান্তর করুন",
"Sync to Disk": "ডিস্ক এ সিঙ্ক করুন"
}

View File

@@ -1,65 +0,0 @@
{
"Quick search": "Quick search",
"All pages": "All pages",
"Favourites": "Favourites",
"No item": "No item",
"Import": "Import",
"Trash": "Trash",
"New Page": "New Page",
"New Keyword Page": "New '{{query}}' page",
"Find 0 result": "Find 0 result",
"Find results": "Find {{number}} results",
"Collapse sidebar": "Collapse sidebar",
"Expand sidebar": "Expand sidebar",
"Removed from Favourites": "Removed from Favourites",
"Remove from favourites": "Remove from favourites",
"Added to Favourites": "Added to Favourites",
"Add to favourites": "Add to favourites",
"Paper": "Paper",
"Edgeless": "Edgeless",
"Switch to": "Switch to",
"Convert to ": "Convert to ",
"Page": "Page",
"Export": "Export",
"Export to HTML": "Export to HTML",
"Export to Markdown": "Export to Markdown",
"Delete": "Delete",
"Title": "Title",
"Untitled": "Untitled",
"Created": "Created",
"Updated": "Updated",
"Open in new tab": "Open in new tab",
"Favourite": "Favourite",
"Favourited": "Favourited",
"Delete page?": "Delete page?",
"Delete permanently?": "Delete permanently?",
"will be moved to Trash": "{{title}} will be moved to Trash",
"Once deleted, you can't undo this action.": "Once deleted,you can't undo this action.",
"Moved to Trash": "Moved to Trash",
"Permanently deleted": "Permanently deleted",
"restored": "{{title}} restored",
"Cancel": "Cancel",
"Keyboard Shortcuts": "Keyboard Shortcuts",
"Contact Us": "Contact Us",
"Official Website": "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",
"Hyperlink(with selected text)": "Hyperlink(with selected text)",
"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"
}

View File

@@ -1,29 +0,0 @@
{
"// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.": "",
"ComingSoon": "Bientôt disponible",
"Duplicate Page": "Dupliquer la page",
"Copy Page Link": "Copier le lien de la page",
"Delete": "Supprimer",
"Comment": "Commentaire",
"Export As HTML": "Exporter en HTML",
"Export As Markdown": "Exporter en Markdown",
"Export As PDF (Unsupported)": "exporter en PDF (non supporté)",
"Logout": "Déconnexion",
"Export Workspace": "Exporter l'espace de travail",
"Import Workspace": "Importer l'espace de travail",
"Language": "Langue",
"Last edited by": "Dernière édition par {{name}}",
"Layout": "Mise en forme",
"Settings": "Réglages",
"Share": "Partager",
"Sync to Disk": "Synchroniser sur le disque",
"Turn into": "Transformer en",
"WarningTips": {
"DoNotStore": "Affine est en développement actif ; la version actuelle est INSTABLE. Veuillez NE PAS stocker d'informations ou de données",
"IsNotLocalWorkspace": "Bienvenue sur la démo d'AFFiNE. Pour commencer à sauvegarder vos modifications, vous pouvez SYNCHRONISER SUR LE DISQUE",
"IsNotfsApiSupported": "Bienvenue sur la démo d'AFFiNE. Pour commencer à sauvegarder vos modifications, vous pouvez SYNCHRONISER SUR LE DISQUE\navec la dernière version d'un navigateur basé sur Chromium tel que Chrome ou Edge."
},
"Add A Below Block": "Ajouter un bloc en-dessous",
"Divide Here As A New Group": "Séparer ici en un nouveau groupe",
"Clear Workspace": "Vider l'espace de travail"
}

View File

@@ -1,72 +0,0 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
// Run `pnpm run download-resources` to regenerate.
// To overwrite this, please overwrite download.ts
import en from './en.json';
import zh_Hans from './zh-Hans.json';
import zh_Hant from './zh-Hant.json';
import sr from './sr.json';
import fr from './fr.json';
import bn from './bn.json';
export const LOCALES = [
{
id: 1000016008,
name: 'English',
tag: 'en',
originalName: 'English',
flagEmoji: '🇬🇧',
base: true,
completeRate: 1,
res: en,
},
{
id: 1000016009,
name: 'Simplified Chinese',
tag: 'zh-Hans',
originalName: '简体中文',
flagEmoji: '🇨🇳',
base: false,
completeRate: 1,
res: zh_Hans,
},
{
id: 1000016012,
name: 'Traditional Chinese',
tag: 'zh-Hant',
originalName: '繁體中文',
flagEmoji: '🇭🇰',
base: false,
completeRate: 1,
res: zh_Hant,
},
{
id: 1000034005,
name: 'Serbian',
tag: 'sr',
originalName: 'српски',
flagEmoji: '🇷🇸',
base: false,
completeRate: 0.9166666666666666,
res: sr,
},
{
id: 1000034008,
name: 'French',
tag: 'fr',
originalName: 'français',
flagEmoji: '🇫🇷',
base: false,
completeRate: 1,
res: fr,
},
{
id: 1000034010,
name: 'Bangla',
tag: 'bn',
originalName: 'বাংলা',
flagEmoji: '🇧🇩',
base: false,
completeRate: 0.7083333333333334,
res: bn,
},
] as const;

View File

@@ -1,27 +0,0 @@
{
"// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.": "",
"Clear Workspace": "Očisti radni prostor",
"ComingSoon": "Podešavanja za izgled dolaze",
"Comment": "Komentar",
"Copy Page Link": "Kopiraj link stranice",
"Delete": "Obriši",
"Duplicate Page": "Dupliraj stranicu",
"Export As HTML": "Izvezi kao HTML",
"Export As Markdown": "Izvezi kao Markdown",
"Export As PDF (Unsupported)": "Izvezi kao PDF (nepodržano)",
"Export Workspace": "Izvezi radnu površinu",
"Import Workspace": "Poboljšaj radnu površinu",
"Language": "Jezik",
"Last edited by": "Zadnju promenu uradio {{ime}}",
"Layout": "Izgled",
"Logout": "Odjava",
"Settings": "Podešavanja",
"Share": "Podeli",
"Sync to Disk": "Sinhroniziraj sa diskom",
"Turn into": "Promeni u",
"WarningTips": {
"DoNotStore": "AFFiNE je u stanju aktivnog razvoja i trenutna verzija je NESTABILNA. Molimo vas, NEMOJTE čuvati informacije ili podatke.",
"IsNotLocalWorkspace": "Dobrodošli u AFFiNE demo. Da bi započeli proces čuvanja promena možete kliknuti SINHRONIZUJ SA DISKOM.",
"IsNotfsApiSupported": "Dobrodošli u AFFiNE demo. Da bi započeli proces čuvanja promena možete SINHRONIZOVATI NA DISK sa poslednjom verzijom pretraživača tipa Chromium, kao što su Chrome/Edge."
}
}

View File

@@ -1,29 +0,0 @@
{
"// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.": "",
"Sync to Disk": "同步到磁盘",
"Share": "分享",
"WarningTips": {
"IsNotfsApiSupported": "欢迎来到AFFiNE 的演示界面。您可以使用最新版本的基于Chrome的浏览器如Chrome/Edge将数据同步到磁盘来进行保存",
"IsNotLocalWorkspace": "欢迎来到AFFiNE 的演示界面,您可以同步到磁盘来进行保存操作。",
"DoNotStore": "AFFiNE 正在积极开发中,当前版本不稳定。请不要存储信息或数据。"
},
"ComingSoon": "布局设置即将到来",
"Layout": "布局",
"Comment": "评论",
"Settings": "设置",
"Duplicate Page": "复制页面",
"Copy Page Link": "复制页面链接",
"Language": "当前语言",
"Clear Workspace": "清空工作区域",
"Export As Markdown": "导出 markdown",
"Export As HTML": "导出 HTML",
"Export As PDF (Unsupported)": "导出 PDF (暂不支持)",
"Import Workspace": "导入 Workspace",
"Export Workspace": "导出 Workspace",
"Last edited by": "最后编辑者为 {{name}}",
"Logout": "退出登录",
"Delete": "删除",
"Turn into": "转换为",
"Add A Below Block": "在下方添加一个新块",
"Divide Here As A New Group": "从这里划分一个新组"
}

View File

@@ -1,29 +0,0 @@
{
"// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.": "",
"Add A Below Block": "在下方新添塊",
"Clear Workspace": "清空工作區",
"ComingSoon": "自定義佈局功能即將與您見面",
"Comment": "評論",
"Copy Page Link": "拷貝頁面鏈接",
"Delete": "刪除",
"Divide Here As A New Group": "從此地劃分成新組",
"Duplicate Page": "複製界面",
"Export As HTML": "導出 HTML",
"Export As Markdown": "以 Markdown 導出",
"Export As PDF (Unsupported)": "導出為 PDF即將可用",
"Export Workspace": "導出 Workspace",
"Import Workspace": "導入 Workspace",
"Language": "語言",
"Last edited by": "最後編輯者為 {{name}}",
"Layout": "佈局",
"Logout": "退出登錄",
"Settings": "設置",
"Share": "分享",
"Sync to Disk": "同步到磁盤",
"Turn into": "轉換為",
"WarningTips": {
"DoNotStore": "我們正在積極開發 AFFiNE目前版本尚不穩定請避免存儲信息或數據。",
"IsNotLocalWorkspace": "歡迎來到 AFFiNE 演示界面。您可以通過「同步到磁盤」來保存更改。",
"IsNotfsApiSupported": "歡迎進入AFFiNE演示使用最新版本的基於 Chromium 內核的瀏覽器如Chrome/Edge您可以通過「同步到磁盤」來保存更改"
}
}