国际化
通过传递 locale
参数,可以设置语言,主要作用于插件里的文字,支持中文和英文,也可以自行拓展其他语言。
设置语言
给 locale
参数传递 en-US
或 zh-CN
来设置语言。
import { ICraftPlayer } from "@icraft/player-react";
const style = {
width: "100%",
height: "100%",
position: "relative" as const,
overflow: "hidden" as const,
};
export default () => {
return (
<div style={style}>
<ICraftPlayer
src='/templates/NetworkArchitectureSpecial.iplayer'
addons={["CameraBar", "EnterSubScene", "ExitSubScene", "ZoomBar"]}
locale='en-US'
/>
</div>
);
};
自定义语言
可以通过设置 locale 为 Record<string, LocaleInterface>
来自定义语言。
import { ICraftPlayer, LocaleInterface } from "@icraft/player-react";
const style = {
width: "100%",
height: "100%",
position: "relative" as const,
overflow: "hidden" as const,
};
const locale: Record<string, LocaleInterface> = {
en_US: {
cameraBar: {
speed: "Speed",
orthographicCamera: "Orthographic Camera",
perspectiveCamera: "Perspective Camera",
autoRotate: "Auto Rotate",
},
playerBar: {
replay: "Replay",
pause: "Pause",
play: "Play",
prev: "Previous",
next: "Next",
loop: "Loop",
reset: "Reset",
},
enterSubScene: "Enter Sub-scene",
exitSubScene: "Exit Sub-scene",
zoomBar: {
zoomIn: "Zoom In",
zoomOut: "Zoom Out",
resetCamera: "Reset Camera",
},
},
};
export default () => {
return (
<div style={style}>
<ICraftPlayer
src='/templates/NetworkArchitectureSpecial.iplayer'
addons={["CameraBar", "EnterSubScene", "ExitSubScene", "ZoomBar"]}
locale={locale}
/>
</div>
);
};
API
Name | description | type | default | required |
---|---|---|---|---|
locale | 国际化 | 'zh-CN' | 'en-US' | Record<string,LocaleInterface> | 'en-US' | false |
LocaleInterface
interface LocaleInterface {
cameraBar: {
speed: string;
orthographicCamera: string;
perspectiveCamera: string;
autoRotate: string;
};
playerBar: {
replay: string;
pause: string;
play: string;
prev: string;
next: string;
loop: string;
reset: string;
};
enterSubScene: string;
exitSubScene: string;
zoomBar: {
zoomIn: string;
zoomOut: string;
resetCamera: string;
};
}