mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 10:29:19 +08:00
fix: 修复 jssdk 不支持其它语言问题 (#2637)
This commit is contained in:
parent
fa87057236
commit
c7f460a373
4
build.sh
4
build.sh
@ -29,6 +29,10 @@ cp ./lib/helper.css.map sdk/helper.css.map
|
||||
cp examples/static/iconfont.css sdk/
|
||||
cp examples/static/iconfont.eot sdk/
|
||||
|
||||
mkdir sdk/locale
|
||||
|
||||
node scripts/generate-sdk-locale.js src/locale/de-DE.ts > sdk/locale/de-DE.js
|
||||
|
||||
# 生成 .d.ts 文件
|
||||
./node_modules/.bin/tsc --declaration --emitDeclarationOnly --outDir ./lib --project ./tsconfig-for-declaration.json
|
||||
|
||||
|
@ -40,6 +40,42 @@ let amisScoped = amis.embed(
|
||||
);
|
||||
```
|
||||
|
||||
如果是其它语言,比如目前德语,需要单独引入文件
|
||||
|
||||
```html
|
||||
<script src="sdk.js"></script>
|
||||
<script src="locale/de-DE.js"></script>
|
||||
<script type="text/javascript">
|
||||
(function () {
|
||||
let amis = amisRequire('amis/embed');
|
||||
// 通过替换下面这个配置来生成不同页面
|
||||
let amisJSON = {
|
||||
type: 'page',
|
||||
body: {
|
||||
type: 'form',
|
||||
mode: 'horizontal',
|
||||
api: '/saveForm',
|
||||
body: [
|
||||
{
|
||||
label: 'Name',
|
||||
type: 'input-text',
|
||||
name: 'name'
|
||||
},
|
||||
{
|
||||
label: 'Email',
|
||||
type: 'input-email',
|
||||
name: 'email'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
let amisScoped = amis.embed('#root', amisJSON, {
|
||||
locale: 'de-DE'
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
```
|
||||
|
||||
### React
|
||||
|
||||
React 版本中没有内置英文翻译,需要自己 import,使用如下方法:
|
||||
@ -89,8 +125,6 @@ import 'amis/lib/locale/en-US';
|
||||
|
||||
如果想扩展其他语言,首先参考 `https://github.com/baidu/amis/blob/master/src/locale/en-US.ts` 文件,然后参考后面的示例注册新语言,未翻译的文字都将使用中文。
|
||||
|
||||
> 目前这种方式将会在未来修改,为了支持更多语言而不再使用中文为 key
|
||||
|
||||
### JS SDK 扩展方法
|
||||
|
||||
```javascript
|
||||
|
16
scripts/generate-sdk-locale.js
Normal file
16
scripts/generate-sdk-locale.js
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 用于生成 sdk 里的多语言,目前只有德语
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
try {
|
||||
const localeFile = fs.readFileSync(process.argv[2], 'utf8');
|
||||
console.log(
|
||||
localeFile
|
||||
.replace(`import {register} from '../locale';`, '')
|
||||
.replace('register(', `amisRequire('amis').registerLocale(`)
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
Loading…
Reference in New Issue
Block a user