Skip to content

Commit 759152f

Browse files
authored
Merge pull request #378 from embedpdf/feature/chinese-translation
Feature/chinese translation
2 parents b367de0 + 41b989c commit 759152f

12 files changed

Lines changed: 265 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@embedpdf/snippet': patch
3+
---
4+
5+
- Add Simplified Chinese (zh-CN) translations for all UI elements
6+
- Add i18n support for annotation type labels in comment sidebar with translation keys and fallbacks
7+
- Fix rimraf command to use `--glob` flag for compatibility with rimraf v4+

viewers/snippet/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"scripts": {
1313
"dev": "rollup --watch --config rollup.config.js",
14-
"prebuild": "rimraf dist/*",
14+
"prebuild": "rimraf --glob dist/*",
1515
"build": "rollup --config rollup.config.js"
1616
},
1717
"dependencies": {

viewers/snippet/src/components/app.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ import {
128128
germanTranslations,
129129
frenchTranslations,
130130
spanishTranslations,
131+
simplifiedChineseTranslations,
131132
} from '@/config';
132133
import { ThemeConfig } from '@/config/theme';
133134
import { IconsConfig } from '@/config/icon-registry';
@@ -269,6 +270,7 @@ const DEFAULTS = {
269270
germanTranslations,
270271
frenchTranslations,
271272
spanishTranslations,
273+
simplifiedChineseTranslations,
272274
],
273275
paramResolvers: defaultParamResolvers,
274276
} as I18nPluginConfig,

viewers/snippet/src/components/comment-sidebar/annotation-card.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ export const AnnotationCard = ({
6868
>
6969
<div className="p-4">
7070
<div className="flex items-start space-x-3">
71-
<AnnotationIcon annotation={annotation} config={config} className="h-8 w-8" />
71+
<AnnotationIcon
72+
annotation={annotation}
73+
config={config}
74+
title={translate(config.labelKey, { fallback: config.label })}
75+
className="h-8 w-8"
76+
/>
7277
<div className="min-w-0 flex-1">
7378
<div className="flex items-center justify-between">
7479
<div className="leading-none">

viewers/snippet/src/components/comment-sidebar/annotation-icon.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ export const AnnotationIcon = ({
77
annotation,
88
config,
99
className = '',
10+
title,
1011
}: {
1112
annotation: TrackedAnnotation;
1213
config: AnnotationConfig;
1314
className?: string;
15+
title: string;
1416
}) => {
1517
const iconProps = config.iconProps(annotation.object);
1618

1719
return (
1820
<div
1921
className={`bg-bg-surface-alt flex items-center justify-center rounded-full ${className}`}
20-
title={config.label}
22+
title={title}
2123
>
2224
<Icon icon={config.icon} {...iconProps} />
2325
</div>

viewers/snippet/src/components/comment-sidebar/config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
// Annotation type configuration
99
export interface AnnotationConfig {
1010
label: string;
11+
labelKey: string;
1112
icon: string;
1213
iconProps: (annotation: PdfAnnotationObject) => {
1314
primaryColor?: string;
@@ -20,13 +21,15 @@ export interface AnnotationConfig {
2021
export const annotationConfigs: Record<SidebarSubtype, AnnotationConfig> = {
2122
[PdfAnnotationSubtype.HIGHLIGHT]: {
2223
label: 'Highlight',
24+
labelKey: 'annotation.highlight',
2325
icon: 'highlight',
2426
iconProps: (annotation: any) => ({
2527
primaryColor: annotation.color || '#ffff00',
2628
}),
2729
},
2830
[PdfAnnotationSubtype.CIRCLE]: {
2931
label: 'Circle',
32+
labelKey: 'annotation.circle',
3033
icon: 'circle',
3134
iconProps: (annotation: any) => ({
3235
primaryColor: annotation.strokeColor || '#000000',
@@ -35,6 +38,7 @@ export const annotationConfigs: Record<SidebarSubtype, AnnotationConfig> = {
3538
},
3639
[PdfAnnotationSubtype.SQUARE]: {
3740
label: 'Square',
41+
labelKey: 'annotation.square',
3842
icon: 'square',
3943
iconProps: (annotation: any) => ({
4044
primaryColor: annotation.strokeColor || '#000000',
@@ -43,48 +47,55 @@ export const annotationConfigs: Record<SidebarSubtype, AnnotationConfig> = {
4347
},
4448
[PdfAnnotationSubtype.LINE]: {
4549
label: 'Line',
50+
labelKey: 'annotation.line',
4651
icon: 'line',
4752
iconProps: (annotation: any) => ({
4853
primaryColor: annotation.strokeColor || '#000000',
4954
}),
5055
},
5156
[PdfAnnotationSubtype.UNDERLINE]: {
5257
label: 'Underline',
58+
labelKey: 'annotation.underline',
5359
icon: 'underline',
5460
iconProps: (annotation: any) => ({
5561
primaryColor: annotation.color || '#000000',
5662
}),
5763
},
5864
[PdfAnnotationSubtype.SQUIGGLY]: {
5965
label: 'Squiggly',
66+
labelKey: 'annotation.squiggly',
6067
icon: 'squiggly',
6168
iconProps: (annotation: any) => ({
6269
primaryColor: annotation.color || '#000000',
6370
}),
6471
},
6572
[PdfAnnotationSubtype.STRIKEOUT]: {
6673
label: 'Strikethrough',
74+
labelKey: 'annotation.strikeout',
6775
icon: 'strikethrough',
6876
iconProps: (annotation: any) => ({
6977
primaryColor: annotation.color || '#000000',
7078
}),
7179
},
7280
[PdfAnnotationSubtype.INK]: {
7381
label: 'Ink',
82+
labelKey: 'annotation.ink',
7483
icon: 'pencilMarker',
7584
iconProps: (annotation: any) => ({
7685
primaryColor: annotation.color || '#000000',
7786
}),
7887
},
7988
[PdfAnnotationSubtype.FREETEXT]: {
8089
label: 'Text',
90+
labelKey: 'annotation.freeText',
8191
icon: 'text',
8292
iconProps: (annotation: any) => ({
8393
primaryColor: annotation.fontColor || '#000000',
8494
}),
8595
},
8696
[PdfAnnotationSubtype.POLYGON]: {
8797
label: 'Polygon',
98+
labelKey: 'annotation.polygon',
8899
icon: 'polygon',
89100
iconProps: (annotation: any) => ({
90101
primaryColor: annotation.strokeColor || '#000000',
@@ -93,13 +104,15 @@ export const annotationConfigs: Record<SidebarSubtype, AnnotationConfig> = {
93104
},
94105
[PdfAnnotationSubtype.POLYLINE]: {
95106
label: 'Polyline',
107+
labelKey: 'annotation.polyline',
96108
icon: 'zigzag',
97109
iconProps: (annotation: any) => ({
98110
primaryColor: annotation.strokeColor || '#000000',
99111
}),
100112
},
101113
[PdfAnnotationSubtype.STAMP]: {
102114
label: 'Stamp',
115+
labelKey: 'annotation.stamp',
103116
icon: 'deviceFloppy',
104117
iconProps: () => ({
105118
primaryColor: '#dc2626',

viewers/snippet/src/config/translations.ts

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,203 @@ export const spanishTranslations: Locale = {
989989
},
990990
};
991991

992+
export const simplifiedChineseTranslations: Locale = {
993+
code: 'zh-CN',
994+
name: '简体中文',
995+
translations: {
996+
search: {
997+
placeholder: '搜索',
998+
caseSensitive: '大小写敏感',
999+
wholeWord: '全词匹配',
1000+
resultsFound: '{count} 个结果',
1001+
page: '第{page}页',
1002+
},
1003+
zoom: {
1004+
in: '放大',
1005+
out: '缩小',
1006+
fitWidth: '适合宽度',
1007+
fitPage: '适合页面',
1008+
marquee: '选框缩放',
1009+
menu: '缩放菜单',
1010+
level: '缩放比例 ({level}%)',
1011+
},
1012+
pan: {
1013+
toggle: '拖动模式',
1014+
},
1015+
pointer: {
1016+
toggle: '光标模式',
1017+
},
1018+
capture: {
1019+
screenshot: '截图',
1020+
},
1021+
document: {
1022+
menu: '文件选项',
1023+
open: '打开',
1024+
close: '关闭',
1025+
print: '打印',
1026+
export: '导出',
1027+
fullscreen: '全屏',
1028+
loading: '文件加载中...',
1029+
},
1030+
emptyState: {
1031+
title: '尚无打开的文件',
1032+
description: '请点击“+ 打开文件”按钮选择并打开一个PDF文件。',
1033+
descriptionMulti: '您可以使用标签页同时打开多个文件。',
1034+
openButton: '打开文件',
1035+
supportedFormats: '支持的文件格式为: PDF',
1036+
},
1037+
passwordPrompt: {
1038+
title: '请输入密码',
1039+
required: '该文件设置有密码保护,要打开文件请输入密码。',
1040+
incorrect: '你输入的密码错误,请重新输入。',
1041+
incorrectWarning: '密码错误,请检查后重新输入。',
1042+
label: '密码',
1043+
placeholder: '请输入文件密码',
1044+
open: '打开',
1045+
opening: '打开中...',
1046+
cancel: '取消',
1047+
close: '关闭',
1048+
},
1049+
documentError: {
1050+
title: '文件加载出错',
1051+
unknown: '未知错误',
1052+
errorCode: '错误码: {code}',
1053+
close: '关闭文件',
1054+
},
1055+
panel: {
1056+
sidebar: '大纲与书签',
1057+
search: '搜索',
1058+
comment: '评论',
1059+
thumbnails: '缩略图',
1060+
outline: '大纲',
1061+
annotationStyle: '批注样式',
1062+
},
1063+
menu: {
1064+
viewControls: '视图控件',
1065+
zoomControls: '缩放控件',
1066+
moreOptions: '更多选项',
1067+
},
1068+
outline: {
1069+
title: '大纲',
1070+
loading: '大纲加载中...',
1071+
noOutline: '没有大纲',
1072+
noBookmarks: '该文件不含书签',
1073+
},
1074+
page: {
1075+
settings: '页面设置',
1076+
single: '单页视图',
1077+
twoOdd: '双页视图',
1078+
twoEven: '书籍视图',
1079+
vertical: '垂直滚动',
1080+
horizontal: '水平滚动',
1081+
spreadMode: '跨页模式',
1082+
scrollLayout: '滚动布局',
1083+
rotation: '页面转向',
1084+
next: '下一页',
1085+
previous: '上一页',
1086+
},
1087+
rotate: {
1088+
clockwise: '顺时针旋转',
1089+
counterClockwise: '逆时针旋转',
1090+
},
1091+
selection: {
1092+
copy: '复制',
1093+
},
1094+
mode: {
1095+
view: '阅读',
1096+
annotate: '批注',
1097+
shapes: '形状',
1098+
redact: '遮蔽',
1099+
},
1100+
annotation: {
1101+
text: '任意文本',
1102+
highlight: '高亮',
1103+
strikeout: '删除线',
1104+
underline: '下划线',
1105+
squiggly: '下划曲线',
1106+
rectangle: '矩形',
1107+
circle: '圆形',
1108+
line: '直线',
1109+
arrow: '带箭头直线',
1110+
polygon: '多边形',
1111+
polyline: '多段线',
1112+
ink: '自由绘制',
1113+
stamp: '印章',
1114+
freeText: '任意文本',
1115+
square: '矩形',
1116+
styles: '{type} 样式',
1117+
defaults: '{type} 默认值',
1118+
// Sidebar labels
1119+
color: '颜色',
1120+
opacity: '透明度',
1121+
blendMode: '混合模式',
1122+
strokeWidth: '线条宽度',
1123+
strokeColor: '线条颜色',
1124+
borderStyle: '线条样式',
1125+
fillColor: '填充色',
1126+
fontSize: '字号',
1127+
fontFamily: '字体',
1128+
textAlign: '左右对齐',
1129+
verticalAlign: '上下对齐',
1130+
lineEnding: '行尾',
1131+
lineStart: '线条起点',
1132+
lineEnd: '线条结尾',
1133+
font: '字体',
1134+
fontColor: '字色',
1135+
backgroundColor: '背景色',
1136+
noStyles: '该批注无需设置样式。',
1137+
noStylesStamp: '印章无需设置样式。',
1138+
selectAnnotation: '在此处查看选中批注的样式。',
1139+
deleteSelected: '删除选中的批注',
1140+
moreTools: '更多工具',
1141+
},
1142+
redaction: {
1143+
area: '遮蔽区域',
1144+
text: '遮蔽文本',
1145+
applyAll: '全部应用',
1146+
clearAll: '全部取消',
1147+
deleteSelected: '取消遮蔽',
1148+
commitSelected: '应用遮蔽',
1149+
},
1150+
history: {
1151+
undo: '撤销',
1152+
redo: '恢复',
1153+
},
1154+
comments: {
1155+
page: '第{page}页',
1156+
commentCount: '{count}条评论',
1157+
commentCountPlural: '{count}条评论',
1158+
addComment: '新增评论...',
1159+
addReply: '新增回复...',
1160+
save: '保存',
1161+
cancel: '取消',
1162+
edit: '编辑',
1163+
delete: '删除',
1164+
showMore: '展开',
1165+
showLess: '收起',
1166+
emptyState: '添加批注后,可以在这里对批注进行评论。',
1167+
},
1168+
blendMode: {
1169+
normal: '正常',
1170+
multiply: '正片',
1171+
screen: '屏幕',
1172+
overlay: '叠加',
1173+
darken: '变暗',
1174+
lighten: '变亮',
1175+
colorDodge: '色彩减淡',
1176+
colorBurn: '颜色加深',
1177+
hardLight: '强光',
1178+
softLight: '柔光',
1179+
difference: '差值',
1180+
exclusion: '排除',
1181+
hue: '色相',
1182+
saturation: '饱和度',
1183+
color: '颜色',
1184+
luminosity: '亮度',
1185+
},
1186+
},
1187+
};
1188+
9921189
export const paramResolvers: ParamResolvers<State> = {
9931190
'zoom.level': ({ state, documentId }) => {
9941191
const zoomLevel = documentId

0 commit comments

Comments
 (0)