Skip to content

Commit

Permalink
feat: locale for cn
Browse files Browse the repository at this point in the history
  • Loading branch information
linyibing committed Mar 5, 2024
1 parent 4c0aa1f commit 58cb15f
Show file tree
Hide file tree
Showing 13 changed files with 300 additions and 120 deletions.
8 changes: 4 additions & 4 deletions src/component/CreateNote/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
}

.ant-form-item {
.ant-form-item-label > label {
height: 39.09px;
}

.ant-picker {
visibility: hidden;
}
Expand Down Expand Up @@ -52,6 +48,10 @@
line-height: 30px;
}
}

.ant-input-affix-wrapper {
padding: 0 11px;
}
}
}

Expand Down
44 changes: 32 additions & 12 deletions src/component/CreateNote/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
AutoComplete,
ConfigProvider,
theme,
Tooltip,
} from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import reduceCSSCalc from 'reduce-css-calc';
import dayjs from 'dayjs';
import {
Expand All @@ -28,15 +29,20 @@ import {
MONTHLY,
QUARTERLY,
YEARLY,
ERROR_MESSAGES,
LOCALE_MAP,
TAG,
FOLDER,
INDEX,
ERROR_MESSAGE,
} from '../../constant';
import { createFile, createPeriodicFile, isDarkTheme } from '../../util';
import {
createFile,
createPeriodicFile,
isDarkTheme,
openOfficialSite,
} from '../../util';
import type { PluginSettings } from '../../type';
import './index.less';
import { I18N_MAP } from '../../i18n';

export const CreateNote = (props: { width: number }) => {
const { app, settings, locale } = useApp() || {};
Expand All @@ -48,13 +54,15 @@ export const CreateNote = (props: { width: number }) => {
const [type, setType] = useState(defaultType);
const [form] = Form.useForm();
const today = dayjs(new Date());
const localeMap =
LOCALE_MAP[locale?.locale || 'en-us'] || LOCALE_MAP['en-us'];
const localeKey = locale?.locale || 'en';
const localeMap = I18N_MAP[localeKey] || I18N_MAP['en'];
const SubmitButton = (
<Form.Item
style={{
width: '100%',
textAlign: 'end',
position: 'relative',
top: -18,
}}
>
<Button
Expand Down Expand Up @@ -86,14 +94,15 @@ export const CreateNote = (props: { width: number }) => {
INDEX = values[`${paraActiveTab}Index`]; // values.archiveIndex;

if (!tag) {
return new Notice(ERROR_MESSAGES.TAGS_MUST_INPUT);
return new Notice(localeMap[`${ERROR_MESSAGE}TAGS_MUST_INPUT`]);
}

folder = `${path}/${key}`;
file = `${folder}/${INDEX}`;
templateFile = `${path}/Template.md`;

await createFile(app, {
locale: localeKey,
templateFile,
folder,
file,
Expand Down Expand Up @@ -171,7 +180,14 @@ export const CreateNote = (props: { width: number }) => {
algorithm: isDark ? theme.darkAlgorithm : theme.defaultAlgorithm,
}}
>
<Tooltip title={localeMap.HELP}>
<QuestionCircleOutlined
onClick={() => openOfficialSite(localeKey)}
style={{ position: 'fixed', right: 16 }}
/>
</Tooltip>
<Form
requiredMark="optional"
style={{
display: 'flex',
justifyContent: 'center',
Expand All @@ -187,6 +203,7 @@ export const CreateNote = (props: { width: number }) => {
}}
form={form}
onFinish={createPARAFile}
layout="vertical"
>
{settings?.usePARANotes && settings?.usePeriodicNotes && (
<Radio.Group
Expand Down Expand Up @@ -278,10 +295,11 @@ export const CreateNote = (props: { width: number }) => {
<Form.Item
label={localeMap[TAG]}
name={`${para}Tag`}
tooltip={localeMap[`${TAG}ToolTip`]}
rules={[
{
required: true,
message: 'Tag is required',
message: localeMap[`${TAG}Required`],
},
{
pattern: /^[^\s]*$/,
Expand All @@ -297,19 +315,20 @@ export const CreateNote = (props: { width: number }) => {
<Input
onChange={() => handleTagInput(para)}
allowClear
placeholder={`${para} Tag, eg: ${
placeholder={
para === PROJECT ? 'PKM/LifeOS' : 'PKM' // 引导用户,项目一般属于某个领域
}`}
}
/>
</AutoComplete>
</Form.Item>
<Form.Item
label={localeMap[FOLDER]}
name={`${para}Folder`}
tooltip={localeMap[`${FOLDER}ToolTip`]}
rules={[
{
required: true,
message: 'Folder is required',
message: localeMap[`${FOLDER}Required`],
},
]}
>
Expand All @@ -322,10 +341,11 @@ export const CreateNote = (props: { width: number }) => {
<Form.Item
label={localeMap[INDEX]}
name={`${para}Index`}
tooltip={localeMap[`${INDEX}ToolTip`]}
rules={[
{
required: true,
message: 'Index is required',
message: localeMap[`${INDEX}Required`],
},
]}
>
Expand Down
55 changes: 2 additions & 53 deletions src/constant.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
export const ERROR_MESSAGES = {
NO_FRONT_MATTER_TAG: 'Please add the tags field for frontMatter!',
NO_DATAVIEW_INSTALL: 'You need to install dataview first!',
FAILED_DATAVIEW_API: 'Dataview API enable failed!',
NO_VIEW_PROVIDED: 'Please provide a view name!',
NO_VIEW_EXISTED: 'There is no this view in periodic PARA plugin',
NO_INDEX_FILE_EXIST: 'There is no Index file exists(README.md/xxx.README.md/',
NO_TEMPLATE_EXIST: 'There is no template file exist: ',
TAGS_MUST_INPUT: 'Please input tags!',
DAILY_RECORD_FETCH_FAILED: 'Fetch daily record failed: ',
RESOURCE_FETCH_FAILED: 'Fetch resource failed: ',
NO_DAILY_RECORD_HEADER:
'Please set daily record header in Periodic PARA plugin',
NO_DAILY_RECORD_API: 'Please set daily record API in Periodic PARA plugin',
NO_DAILY_RECORD_TOKEN:
'Please set daily record access token in Periodic PARA plugin',
NO_DAILY_FILE_EXIST: 'Daily file not exists, please create it first: ',
};
export const ERROR_MESSAGE = 'ERROR_MESSAGE';
export const MESSAGE = 'MESSAGE';

export const PARA = 'PARA Notes';
export const PROJECT = 'Project';
Expand All @@ -41,38 +25,3 @@ export const QUARTERLY_REG = /^\d{4}-Q(\d{1,2})/;
export const YEARLY_REG = /(^\d{4})/;

export const LIFE_OS_OFFICIAL_SITE = 'https://obsidian-life-os.netlify.app';

export const LOCALE_MAP: Record<string, Record<string, string>> = {
'en-us': {
[PERIODIC]: 'Periodic Notes',
[DAILY]: 'Day',
[WEEKLY]: 'Week',
[MONTHLY]: 'Month',
[QUARTERLY]: 'Quarter',
[YEARLY]: 'Year',
[PARA]: 'PARA Notes',
[PROJECT]: 'Project',
[AREA]: 'Area',
[RESOURCE]: 'Resource',
[ARCHIVE]: 'Archive',
[TAG]: 'Tag',
[FOLDER]: 'Folder',
[INDEX]: 'Index'
},
'zh-cn': {
[PERIODIC]: '周期笔记',
[DAILY]: '日记',
[WEEKLY]: '周记',
[MONTHLY]: '月记',
[QUARTERLY]: '季记',
[YEARLY]: '年记',
[PARA]: 'PARA 笔记',
[PROJECT]: '项目',
[AREA]: '领域',
[RESOURCE]: '资源',
[ARCHIVE]: '存档',
[TAG]: '标签',
[FOLDER]: '目录',
[INDEX]: '索引'
},
};
135 changes: 135 additions & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import {
ARCHIVE,
AREA,
DAILY,
ERROR_MESSAGE,
FOLDER,
INDEX,
MESSAGE,
MONTHLY,
PARA,
PERIODIC,
PROJECT,
QUARTERLY,
RESOURCE,
TAG,
WEEKLY,
YEARLY,
} from './constant';

const EN = {
HELP: 'Go to the website and ask for help',

[PERIODIC]: 'Periodic Notes',
[DAILY]: 'Day',
[WEEKLY]: 'Week',
[MONTHLY]: 'Month',
[QUARTERLY]: 'Quarter',
[YEARLY]: 'Year',

[PARA]: 'PARA Notes',
[PROJECT]: 'Project',
[AREA]: 'Area',
[RESOURCE]: 'Resource',
[ARCHIVE]: 'Archive',

[TAG]: 'Tag',
[FOLDER]: 'Folder',
[INDEX]: 'Index',

[`${TAG}ToolTip`]:
'Tags in PARA notes serve as the unique identifiers for indexing tasks, notes, and files',
[`${FOLDER}ToolTip`]:
'The folder where PARA notes are located, is used to store notes related to the corresponding theme',
[`${INDEX}ToolTip`]:
'The index filename of PARA notes is used to index tasks, records, and files scattered across various locations. The required formats are LifeOS.README.md/README.md, or the same as the name of the folder it resides in',
[`${TAG}Required`]: 'A unique id tag is required',
[`${TAG}Required2`]: `The unique id can't contain spaces`,
[`${FOLDER}Required`]: 'The folder is required',
[`${INDEX}Required`]: 'The index file name is required',

[`${MESSAGE}START_SYNC_USEMEMOS`]: 'Start sync usememos',
[`${MESSAGE}END_SYNC_USEMEMOS`]: 'End sync usememos',

[`${ERROR_MESSAGE}NO_FRONT_MATTER_TAG`]:
'Please add the tags field for properties !',
[`${ERROR_MESSAGE}NO_DATAVIEW_INSTALL`]:
'You need to install dataview first!',
[`${ERROR_MESSAGE}FAILED_DATAVIEW_API`]: 'Dataview API enable failed!',
[`${ERROR_MESSAGE}NO_VIEW_PROVIDED`]:
'Please provide the name of the view you want to query!',
[`${ERROR_MESSAGE}NO_VIEW_EXISTED`]:
'There is no this view in periodic PARA plugin',
[`${ERROR_MESSAGE}NO_INDEX_FILE_EXIST`]:
'There is no Index file exists(README.md/xxx.README.md/the same as the name of the folder it resides in)',
[`${ERROR_MESSAGE}NO_TEMPLATE_EXIST`]: 'There is no template file exist',
[`${ERROR_MESSAGE}TAGS_MUST_INPUT`]: 'Please input tags!',
[`${ERROR_MESSAGE}DAILY_RECORD_FETCH_FAILED`]: 'Fetch usememos failed',
[`${ERROR_MESSAGE}RESOURCE_FETCH_FAILED`]: 'Fetch resource failed',
[`${ERROR_MESSAGE}NO_DAILY_RECORD_HEADER`]:
'Please set which header the usememos need insert to in Periodic PARA plugin',
[`${ERROR_MESSAGE}NO_DAILY_RECORD_API`]:
'Please set daily usememos API in Periodic PARA plugin',
[`${ERROR_MESSAGE}NO_DAILY_RECORD_TOKEN`]:
'Please set usememos token in Periodic PARA plugin',
[`${ERROR_MESSAGE}NO_DAILY_FILE_EXIST`]:
'Daily file not exists, please create it first: ',
};

const ZH = {
HELP: '打开官网,寻求帮助',

[PERIODIC]: '周期笔记',
[DAILY]: '日记',
[WEEKLY]: '周记',
[MONTHLY]: '月记',
[QUARTERLY]: '季记',
[YEARLY]: '年记',

[PARA]: 'PARA 笔记',
[PROJECT]: '项目',
[AREA]: '领域',
[RESOURCE]: '资源',
[ARCHIVE]: '存档',

[TAG]: '标签',
[FOLDER]: '目录',
[INDEX]: '索引',
[`${TAG}ToolTip`]: 'PARA 笔记的标签,作为索引任务、记录、文件的唯一标识',
[`${FOLDER}ToolTip`]: 'PARA 笔记所在的文件夹,用于存放对应主题的笔记',
[`${INDEX}ToolTip`]:
'PARA 笔记的索引文件名,用于索引散落在各处的任务、记录、文件,要求格式为 LifeOS.README.md/README.md,或与所在目录同名',
[`${TAG}Required`]: '唯一标识标签为必填项',
[`${TAG}Required2`]: '唯一标识标签不允许存在空格符',
[`${FOLDER}Required`]: '所在目录为必填项',
[`${INDEX}Required`]: '索引文件名为必填项',

[`${MESSAGE}START_SYNC_USEMEMOS`]: '开始同步 usememos',
[`${MESSAGE}END_SYNC_USEMEMOS`]: '结束同步 usememos',

[`${ERROR_MESSAGE}NO_FRONT_MATTER_TAG`]: '请为 Properties 添加 tags 字段!',
[`${ERROR_MESSAGE}NO_DATAVIEW_INSTALL`]: '请先安装 dataview!',
[`${ERROR_MESSAGE}FAILED_DATAVIEW_API`]: 'Dataview API 开启失败!',
[`${ERROR_MESSAGE}NO_VIEW_PROVIDED`]: '请提供所需要查询的视图名!',
[`${ERROR_MESSAGE}NO_VIEW_EXISTED`]: 'Periodic PARA 插件中不存在此视图',
[`${ERROR_MESSAGE}NO_INDEX_FILE_EXIST`]:
'索引文件不存在(README.md/xxx.README.md/所在文件夹同名文件)',
[`${ERROR_MESSAGE}NO_TEMPLATE_EXIST`]: '模版文件不存在',
[`${ERROR_MESSAGE}TAGS_MUST_INPUT`]: '请输入 tags!',
[`${ERROR_MESSAGE}DAILY_RECORD_FETCH_FAILED`]: '拉取 usememos 失败',
[`${ERROR_MESSAGE}RESOURCE_FETCH_FAILED`]: '拉取资源失败',
[`${ERROR_MESSAGE}NO_DAILY_RECORD_HEADER`]:
'请在 Periodic PARA 插件中设置 usememos 需要存储在哪个标题之下',
[`${ERROR_MESSAGE}NO_DAILY_RECORD_API`]:
'请在 Periodic PARA 插件中设置 usememos 的 API',
[`${ERROR_MESSAGE}NO_DAILY_RECORD_TOKEN`]:
'请在 Periodic PARA 插件中设置 usememos 的 Token',
[`${ERROR_MESSAGE}NO_DAILY_FILE_EXIST`]: '日记文件不存在,请先创建:',
};

export const I18N_MAP: Record<string, Record<string, string>> = {
'en-us': EN,
en: EN,
'zh-cn': ZH,
zh: ZH,
};

0 comments on commit 58cb15f

Please sign in to comment.