Notion-Translate

Truns Notion to local language

  1. // ==UserScript==
  2. // @name Notion-Translate
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.1
  5. // @description Truns Notion to local language
  6. // @author L1n3
  7. // @match *://www.notion.so/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function I18N() {
  15. this.lang = 'en';
  16. }
  17.  
  18. I18N.prototype.install = function(langName, keymap){
  19. if (this[langName] === undefined) {
  20. this[langName] = keymap;
  21. }
  22. };
  23.  
  24. const I18n = new I18N();
  25.  
  26. I18n.install('zh', {
  27. // 工作区选择
  28. 'Free Plan' : '免费套餐',
  29. "Personal (Education) Plan" : '个人(教育)套餐',
  30. 'Create or Join Workspace': '创建或加入工作区',
  31. "Windows App" : 'Windows应用',
  32. "Mobile App" : '移动端应用',
  33. "Web Clipper" : '网页剪藏',
  34. 'Log Out (': '注销',
  35.  
  36. // -----------------
  37. // 左栏
  38. 'Quick Find': '快速查找',
  39. 'All Updates': '所有的更新',
  40. // 所有的更新中
  41. 'Followed': '已关注',
  42. 'Mentions': '提到我的',
  43. 'Open notifications settings': '打开消息设置',
  44. // 消息
  45. "created" : "创建",
  46. "view" : "页面",
  47. "property" : "属性",
  48. "edited" : "编辑",
  49. "in" : "在",
  50. "Learn about page updates" : "学习如何修改页面",
  51. 'Settings & Members': '设置 & 成员',
  52.  
  53. // -----------------
  54. 'Share': '分享',
  55. 'Updates': '更新',
  56. 'Favorite': '收藏',
  57. 'Templates': '模板',
  58. 'Import': '导入',
  59. 'Trash': '垃圾桶',
  60. // -----------------
  61. 'New Page': '新建页面',
  62. // -----------------
  63. 'Add a Page': '添加一个页面',
  64. 'All workspace members can access these pages': '所有在工作空间中的用户都能访问这个页面',
  65. 'Quickly add a page inside': '快速添加一个页面',
  66. 'Delete, duplicate, and more': '删除,复制或是更多操作',
  67. // -----------------
  68. "Filter...": "搜索...",
  69. "people": "人物",
  70. "animals and nature": "动物与自然",
  71. "food and drink": "食物与饮品",
  72. "activity": "活动",
  73. "travel and places": "交通工具与地点",
  74. "objects": "物品",
  75. "symbols": "符号",
  76. "flags": "标志",
  77. // -----------------
  78. 'Link': '链接',
  79. // -----------------
  80. 'Upload an Image': '上传图片',
  81. "Choose an Image": "选择图片",
  82. "Recommended size is 280 × 280 pixels": "推荐大小为280 x 280 像素",
  83. "The maximum size per file is ": "文件最大大小为",
  84. // -----------------
  85. "Paste an image link...": "输入图片链接",
  86. "Submit" : "提交",
  87. "Works with any image from the web" : "只要在网络上能访问到的图片都可以",
  88. // -----------------
  89. 'Remove': '移除',
  90. // -----------------
  91. 'No Pages Inside' : '没有更多页面',
  92. // -----------------
  93. 'Default View': '默认视图',
  94. // -----------------
  95. 'Copy Link to View' : '复制页面链接',
  96. 'Properties' : '属性',
  97. 'Group by ' : '基于',
  98. 'Filter' : '过滤',
  99. 'Sort' : '排序',
  100. 'Search' : '搜索',
  101. 'New' : '新增',
  102. 'Empty Page' : '空页面',
  103. 'New Template' : '新的模版',
  104. 'Edit' : '编辑',
  105. // 块选项
  106. 'Hide': '隐藏',
  107. 'Create new page': '创建',
  108. 'Untitled': '未命名',
  109. 'Type a name...': '输入一个名字...',
  110. 'Drag': '拖动',
  111. 'Add Icon': '添加图标',
  112. 'Add Cover': '添加封面',
  113. 'Add Discussion': '添加议题',
  114. 'Drag': '拖动',
  115. 'Click': '点击',
  116. 'to move': '来移动行',
  117. 'to open menu': '打开菜单',
  118. 'to add a block below': '在下方添加一个编辑块',
  119. 'Rename, delete, and more...': '重命名,删除,及更多...',
  120. 'Change icon': '改变图标',
  121. 'Delete': '删除',
  122. 'Duplicate': '重复',
  123. 'Turn Into': '换成',
  124. 'Style': '风格',
  125. 'Small Text': '更小的字体',
  126. 'Full Width': '更宽的编辑区',
  127. 'Page Lock': '锁定页面',
  128. 'Add to Favorites': '添加至收藏',
  129. 'Open in Windows App': '在客户端中打开',
  130. 'Undo': '撤销',
  131. 'Page History': '历史修改',
  132. 'Show Deleted Pages':'显示已经删除的页面',
  133. 'Copy Link': '复制链接',
  134. 'Rename': '重命名',
  135. 'Move To': '移动到',
  136. 'Word Count: ':"字数统计",
  137.  
  138. 'Edit Property': '编辑属性',
  139. 'Comment': '评论',
  140. 'Color': '颜色',
  141.  
  142. // 设置
  143. // 设置 => 我的账户
  144. 'Me': '我',
  145. // -----------------
  146. 'My Account': '我的账户',
  147. 'Changes to account settings will apply to all of your workspaces.': '帐户设置的更改将应用于您的所有工作区。',
  148. 'Learn more.': '了解更多',
  149. 'Photo': '相片',
  150. 'Upload Photo': '上传相片',
  151. 'Personal Info': '个人信息',
  152. 'Email': '邮箱',
  153. 'Change Email': '更改邮箱',
  154. 'Given Name': '名',
  155. 'Family Name': '姓',
  156. 'Password': '密码',
  157. 'You can set a permanent password if you don\'t want to use temporary login codes.': '如果您不想使用临时登录码,则可以设置永久密码。',
  158. 'Change Password': '更改密码',
  159. 'Remove Password': '移除密码',
  160. 'Calendar': '日历',
  161. 'Start week on Monday': '一周从星期一开始',
  162. 'This will change how all calendars in your app look.': '这将会更改您应用中所有日历的外观。',
  163. 'Danger Zone': '危险操作',
  164. 'Delete My Account': '删除我的账户',
  165. 'Update': '更新',
  166. 'Cancel': '取消',
  167. // -----------------
  168. // 设置 => 通知
  169. 'My Notifications': '通知',
  170. 'Learn about mobile and desktop notifications.': '了解有关手机和桌面通知的消息。',
  171. 'Mobile Push Notifications': '向手机推送通知',
  172. 'Receive push notifications on mentions and comments immediately via your mobile apps.': '立即通过您的移动应用接收有关提及和评论的推送通知。',
  173. 'Email Notifications': '邮件通知',
  174. 'Receive email updates on mentions, comments, and edit digests for all the pages you have followed.': '接收有关您关注的所有页面的提及,评论和编辑摘要的电子邮件更新。',
  175. // -----------------
  176. 'My Connected Apps': '已关联的应用',
  177. 'Learn more about embedding content in Notion.': '了解更多',
  178. 'Connect': '连接',
  179. 'Find and embed your files': '查找和嵌入你的文件',
  180. 'Import notebooks': '导入笔记',
  181. 'Import your boards': '导入你的看板',
  182. 'Import tasks from boards and lists': '从看板和列表导入任务',
  183. // -----------------
  184. 'Earn Credit': '获取奖励',
  185. 'Learn how to earn and apply credits.': '学习更多',
  186. "Credit Balance" : "获取奖励",
  187. 'Your current credit balance is': '已获取奖励为',
  188. 'That\\\'s equivalent to': '这相当于',
  189. 'month': '个月',
  190. 'of free Notion.': '的免费使用',
  191. 'Upgrade for free': '免费升级套餐',
  192. 'Invite Friends and Earn Credit': '邀请和奖励',
  193. 'You’ll receive': '你将获得',
  194. 'in Notion credit when the person you invite signs up for a Notion account, and they’ll also get': '在Notion中,并且你的朋友也会获取',
  195. 'in credits to get started.': '的奖励',
  196. 'Enter email address...': '输入邮箱地址...',
  197. 'Invite': '邀请',
  198. 'Other Ways to Earn Credit': '其他方式的奖励',
  199. 'Log in on the Web': '首次登陆Web端',
  200. 'Sign in to Notion from any web browser': '使用任意浏览器登陆Notion',
  201. 'Log in on the Desktop App': '首次登陆客户端',
  202. 'Download the desktop app and sign in': '下载客户端并登陆账户',
  203. 'Log in on the Mobile App': '首次登陆移动端',
  204. 'Download the mobile app and sign in': '下载移动端并登陆账户',
  205. 'Import from Evernote': '从Evernote国际版导入',
  206. 'Import your notes and notebooks': '导入你的笔记和笔记本',
  207. 'Use the Web Clipper': '首次使用剪藏',
  208. 'Download the Chrome Extension and save a link': '下载Chrome插件并保存链接',
  209. 'Use the iOS or Android System Share Menu': '使用移动设备分享',
  210. 'Use the share menu to save a link into Notion': '使用手机系统分享链接至Notion',
  211. 'Total credit earned': '获取奖励总额',
  212. // -----------------
  213. 'Workspace': '工作空间',
  214. // -----------------
  215. 'Settings': '设置',
  216. 'Name': '名称',
  217. 'You can use your name or the name of your team. Keep it simple.': '您可以使用您的名字或团队的名字,来保持简单化。',
  218. 'Icon': '图标',
  219. 'Upload an image or pick an emoji. It will show up in your sidebar and notifications.': '上传图片或选择表情符号。 它将显示在侧边栏和通知中。',
  220. 'Domain': '域名',
  221. 'Share the link ': '分享这个链接 ',
  222. ' to add anyone with an allowed email domain to your workspace.': ' 来添加任何来自该域下拥有邮箱账号的用户到你的工作空间',
  223. 'Allowed Email Domains': '允许的电子邮箱域',
  224. 'Anyone with email addresses at these domains can automatically join your workspace.': '在这些域中拥有电子邮件地址的任何人都可以自动加入您的工作区。',
  225. 'Export Content': '导出',
  226. 'Export All Workspace Content': '导出整个工作区',
  227. 'Learn about exporting workspaces.': '了解更多关于导出工作空间',
  228. 'Export Members' : '导出用户',
  229. 'Export Members as CSV' : '导出用户表为CSV格式',
  230. 'Learn about exporting members.' : '了解更多关于导出用户',
  231. 'Export Members' : '导出用户',
  232. 'Danger Zone': '危险操作',
  233. 'Delete Entire Workspace': '删除整个工作区',
  234. 'Learn about deleting workspaces.': '了解更多关于删除工作区',
  235. // -----------------
  236. "Member" : '成员',
  237. "Members" : '所有成员',
  238. "Groups" : '分组',
  239. "Manage members here, or" : '在此管理成员,或是',
  240. "set up a domain" : '设置一个域名',
  241. ", so everyone with allowed email domain can join the workspace automatically." : '如果电子邮件在设置的域名下则会自动加入该工作空间',
  242. "Add a Member" : '添加成员',
  243. "User" : '用户',
  244. "Access Level" : '访问级别',
  245. "Admin" : '管理员',
  246. "Can change workspace settings and invite new members to the workspace." : '可以更改工作空间设置并邀请新成员加入工作空间。',
  247. "Cannot change workspace settings or invite new members to the workspace." : '无法更改工作空间设置或邀请新成员加入工作空间。',
  248. "Leave Team" : '退出团队',
  249. "Guests (" : '访客 (',
  250. "Convert to " : '转换为',
  251. "This guest can access these pages" : '他可以访问这些页面',
  252. "Page" : '个页面',
  253. // -----------------
  254. 'Upgrade': '升级',
  255. 'Plans':'方案',
  256. 'Free' : '免费',
  257. 'Personal' : '个人',
  258. 'Team' : '团队',
  259. 'Enterprise' : '企业',
  260. 'Usage': '使用对象',
  261. 'Guests': '访客',
  262. 'Blocks': '块数量',
  263. 'File uploads': '上传限制',
  264. 'Version history': '版本历史',
  265. 'Features': '功能',
  266. 'Web, desktop, & mobile apps': 'Web端,客户端以及移动端使用',
  267. '40+ block types & embeds': '40多种嵌入式块类型',
  268. '50+ designer templates': '50多个精心设计的模版',
  269. 'Databases with 5 views': '具有5个视图的数据库',
  270. 'Admin & security features': '管理和安全功能',
  271. 'Admin tools': '管理员工具',
  272. 'Advanced permissions': '高级权限控制',
  273. 'Bulk PDF export': '批量导出PDF',
  274. 'Access new features early': '尽早享受新功能',
  275. 'Support': '升级',
  276. 'Priority support': '升级',
  277. 'Dedicated manager': '升级',
  278. 'Custom contract & invoicing': '升级',
  279. 'Current Plan': '当前计划',
  280. 'Upgrade': '升级',
  281. 'Security & SAML': '安全 & SAML',
  282. 'Dark Mode': '夜间模式',
  283. // 新建页面
  284. 'Open as Page': '作为页面打开',
  285. 'Navigate to this page': '导航到这个页面',
  286. 'Add to': '添加到',
  287. 'Press Enter': '按下 Enter 键',
  288. ' to continue with an empty page': '以空白页继续',
  289. ', or pick a template': ',或者选择一个模板',
  290. ' (↑↓ to select)': ' (↑↓ 键选择)',
  291. 'Empty With Icon': '空白有图标',
  292. 'Empty': '空白',
  293. 'Database': '数据库',
  294. 'Table': '表格',
  295. 'Board': '看板',
  296. 'List': '列表',
  297. 'Calendar': '日历',
  298. 'Gallery': '图库'
  299. });
  300.  
  301.  
  302.  
  303. const NotionApp = window.document.getElementById('notion-app');
  304.  
  305. function getTextNode(node) {
  306. const sentences = [];
  307.  
  308. const _getTextNode = function(node) {
  309. for (let childNode of node.childNodes) {
  310. if (childNode instanceof window.Text) {
  311. if (childNode.data.replace(/[' ']*/, '')) {
  312. sentences.push(childNode);
  313. }
  314. } else if (childNode.placeholder) {
  315.  
  316. }
  317. _getTextNode(childNode);
  318. }
  319. };
  320. _getTextNode(node);
  321. return sentences;
  322. }
  323.  
  324. function translate(node) {
  325. const sentences = getTextNode(node);
  326. for (let text of sentences) {
  327. const string = text.data;
  328. if (I18n.zh[string]) {
  329. text.parentNode.replaceChild(new window.Text(I18n.zh[string]), text);
  330. }
  331. }
  332. }
  333.  
  334. setTimeout(() => {
  335. window.requestIdleCallback(() => {
  336. translate(NotionApp);
  337.  
  338. const observer = new MutationObserver(function(mutationsList) {
  339. return window.requestIdleCallback(function() {
  340. mutationsList = mutationsList.filter(MutationRecord => {
  341. return MutationRecord.addedNodes.length !== 0;
  342. }).map(MutationRecord => {
  343. return MutationRecord.addedNodes;
  344. });
  345.  
  346. for (let nodeList of mutationsList) {
  347. for (let node of nodeList) {
  348. translate(node);
  349. }
  350. }
  351. });
  352. });
  353.  
  354. observer.observe(NotionApp, {
  355. childList: true,
  356. subtree: true
  357. });
  358. });
  359. });
  360. })();
  361.