com.synconset.imagepicker
插件是telerik团队开发提供。
使用命令安装 ionic cordova plugin add cordova-plugin-image-picker
安装后需要修改中文支持。
Android
multiimagechooser_strings_en.xml文件修改
1 2 3 4 5 6 7 8 9 10 11 12
| <?xml version="1.0" encoding="utf-8"?> <resources> <string name="multi_app_name">图片选择器</string> <string name="free_version_label">还可以选择 %d 张图片</string> <string name="error_database">打开图像数据库时出错,请反馈问题.</string> <string name="requesting_thumbnails">请求缩略图,请耐心等待</string> <string name="multi_image_picker_processing_images_title">正在处理...</string> <string name="multi_image_picker_processing_images_message">请稍等...</string> <string name="discard" translatable="false">取消</string> <string name="done" translatable="false">确定</string> </resources>
|
直接用上边代码覆盖xx_project\plugins\com.synconset.imagepicker\src\android\Library\res\values\multiimagechooser_strings_en.xml
文件中的东西。
MultiImageChooserActivity.java 弹窗汉化修改
工程\plugins\com.synconset.imagepicker\src\android\Library\src\MultiImageChooserActivity.java
用下边代码覆盖方法onItemClick
中的对应代码(Line 199):
1 2 3 4 5 6 7 8 9 10 11
| new AlertDialog.Builder(this) .setTitle("提示") .setMessage("您只能选择" + maxImageCount + " 张图片") .setPositiveButton("知道了", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create() .show();
|
IOS
新增文件ImagePicker/src/ios/GMImagePicker/zh-Hans.lproj/GMImagePicker.strings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| /* Cancel */ "picker.navigation.cancel-button" = "取消"; /* Done */ "picker.navigation.done-button" = "完成"; /* Navigation bar default title */ "picker.navigation.title" = "我的相册"; /* %@ Items Selected */ "picker.selection.multiple-items" = "已选中 %@ 项"; /* %@ Photos Selected */ "picker.selection.multiple-photos" = "已选中 %@ 张照片"; /* %@ Videos Selected */ "picker.selection.multiple-videos" = "已选中 %@ 个视频"; /* 1 Photo Selected */ "picker.selection.single-photo" = "已选中 1 张照片"; /* 1 Video Selected */ "picker.selection.single-video" = "已选中 1 个视频"; /* All photos */ "picker.table.all-photos-label" = "相机胶卷"; /* Smart Albums */ "picker.table.smart-albums-header" = "智能相册"; /* Albums */ "picker.table.user-albums-header" = "相册";
|
./plugin.xml
文件中添加上边文件引入
1 2 3 4 5 6 7 8 9
| <resource-file src="src/ios/GMImagePicker/fr.lproj" /> <resource-file src="src/ios/GMImagePicker/it.lproj" /> <resource-file src="src/ios/GMImagePicker/pt.lproj" /> + <resource-file src="src/ios/GMImagePicker/zh-Hans.lproj" /> <framework src="Accelerate.framework" /> <framework src="Security.framework" /> <framework src="Photos.framework" />
|
新版本IOS不支持图片张数限制,具体见官方说明。http://plugins.telerik.com/cordova/plugin/imagepicker
总结
注意的是每次移除plugins重新安装插件的话都要修改一次。比较麻烦。其实可以将插件源码修改自己发布插件,这样就不用每次修改了。
github可以搜到别人汉化重新发布的插件,但是是两年前的,一直未更新,质量不敢保证,不怕麻烦就自己动手了。