uni-app 打包WGT后 plus.gallery.pick与uni.chooseImage弹出的相册不能被国际化
uni-app 打包WGT后 plus.gallery.pick与uni.chooseImage弹出的相册不能被国际化
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Windows | Windows 10 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Windows
PC开发环境操作系统版本号:Windows 10
HBuilderX类型:正式
HBuilderX版本号:3.8.12
手机系统:全部
页面类型:vue
vue版本:vue3
打包方式:离线
项目创建方式:HBuilderX
测试过的手机:
- iPhone 14 ProMAX:iOS17.2.1
- iphone X:iOS15.6.1
- OPPO A8:Android 9
- Pixel 3:Android 12
- Pixel 5:Android 14
示例代码:
{
"name": "XXXXXX",
"appid": "__UNI__XXXXXX",
"description": "",
"versionName": "1.0.0",
"versionCode": 100,
"transformPx": false,
"fallbackLocale": "en",
"app-plus": {
"locales": {
"en": {
"name": "XXXXXX",
"android": {
"strings": {
"dcloud_gallery_library_name": "test_string",
"dcloud_gallery_all_dir_name": "test_string",
"dcloud_gallery_all_video": "test_string",
"dcloud_gallery_all_image": "test_string",
"dcloud_gallery_select_title": "test_string",
"dcloud_gallery_select_video_title": "test_string",
"dcloud_gallery_select_image_title": "test_string",
"dcloud_gallery_video_dir_name": "test_string",
"dcloud_gallery_msg_amount_limit": "test_string",
"dcloud_gallery_msg_size_limit": "test_string",
"dcloud_gallery_select_null": "test_string",
"dcloud_gallery_done": "test_string",
"dcloud_gallery_count_string": "test_string",
"dcloud_gallery_preview": "test_string",
"dcloud_gallery_select": "test_string",
"dcloud_gallery_video": "test_string",
"dcloud_gallery_cant_play_video": "test_string",
"dcloud_gallery_read_external_storage": "test_string"
}
},
"ios": {
"privacyDescription": {
"NSPhotoLibraryUsageDescription": "test"
},
"infoPlist": {
"dcloud_gallery_library_name": "test_string",
"dcloud_gallery_all_dir_name": "test_string",
"dcloud_gallery_all_video": "test_string",
"dcloud_gallery_all_image": "test_string",
"dcloud_gallery_select_title": "test_string",
"dcloud_gallery_select_video_title": "test_string",
"dcloud_gallery_select_image_title": "test_string",
"dcloud_gallery_video_dir_name": "test_string",
"dcloud_gallery_msg_amount_limit": "test_string",
"dcloud_gallery_msg_size_limit": "test_string",
"dcloud_gallery_select_null": "test_string",
"dcloud_gallery_done": "test_string",
"dcloud_gallery_count_string": "test_string",
"dcloud_gallery_preview": "test_string",
"dcloud_gallery_select": "test_string",
"dcloud_gallery_video": "test_string",
"dcloud_gallery_cant_play_video": "test_string",
"dcloud_gallery_read_external_storage": "test_string"
}
}
},
"zh": {
"name": "XXXXXX",
"android": {
"strings": {
"dcloud_gallery_library_name": "test_string",
"dcloud_gallery_all_dir_name": "test_string",
"dcloud_gallery_all_video": "test_string",
"dcloud_gallery_all_image": "test_string",
"dcloud_gallery_select_title": "test_string",
"dcloud_gallery_select_video_title": "test_string",
"dcloud_gallery_select_image_title": "test_string",
"dcloud_gallery_video_dir_name": "test_string",
"dcloud_gallery_msg_amount_limit": "test_string",
"dcloud_gallery_msg_size_limit": "test_string",
"dcloud_gallery_select_null": "test_string",
"dcloud_gallery_done": "test_string",
"dcloud_gallery_count_string": "test_string",
"dcloud_gallery_preview": "test_string",
"dcloud_gallery_select": "test_string",
"dcloud_gallery_video": "test_string",
"dcloud_gallery_cant_play_video": "test_string",
"dcloud_gallery_read_external_storage": "test_string"
}
},
"ios": {
"privacyDescription": {
"NSPhotoLibraryUsageDescription": "test"
},
"infoPlist": {
"dcloud_gallery_library_name": "test_string",
"dcloud_gallery_all_dir_name": "test_string",
"dcloud_gallery_all_video": "test_string",
"dcloud_gallery_all_image": "test_string",
"dcloud_gallery_select_title": "test_string",
"dcloud_gallery_select_video_title": "test_string",
"dcloud_gallery_select_image_title": "test_string",
"dcloud_gallery_video_dir_name": "test_string",
"dcloud_gallery_msg_amount_limit": "test_string",
"dcloud_gallery_msg_size_limit": "test_string",
"dcloud_gallery_select_null": "test_string",
"dcloud_gallery_done": "test_string",
"dcloud_gallery_count_string": "test_string",
"dcloud_gallery_preview": "test_string",
"dcloud_gallery_select": "test_string",
"dcloud_gallery_video": "test_string",
"dcloud_gallery_cant_play_video": "test_string",
"dcloud_gallery_read_external_storage": "test_string"
}
}
}
},
"compilerVersion": 3,
"compatible": {
"ignoreVersion": true
},
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
},
"modules": {},
"distribute": {
"android": {
"permissions": [
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
"ios": {},
"sdkConfigs": {},
"screenOrientation": [
"portrait-primary"
]
}
},
"uniStatistics": {
"enable": false
},
"vueVersion": "3"
}
操作步骤:
在HbuilderX中或cli中新建项目,使用本文中代码作为manifest.json,index.vue中使用下面的代码,打包为WGT:
<template>
<button [@click](/user/click)="handleClick">Test</button>
</template>
<script setup lang="ts">
const handleClick = () => {
uni.chooseImage({
count: 6,
sizeType: ['original', 'compressed'],
sourceType: ['album'],
success: function (res) {
console.log(JSON.stringify(res.tempFilePaths));
}
});
}
</script>
更多关于uni-app 打包WGT后 plus.gallery.pick与uni.chooseImage弹出的相册不能被国际化的实战教程也可以访问 https://www.itying.com/category-93-b0.html
更多关于uni-app 打包WGT后 plus.gallery.pick与uni.chooseImage弹出的相册不能被国际化的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在 uni-app 中,打包为 WGT 后,plus.gallery.pick 和 uni.chooseImage 弹出的相册界面可能无法被国际化,这是因为这些组件的界面是由原生系统控制的,而不是由 uni-app 直接控制的。因此,它们的语言和地区设置通常取决于设备的系统语言设置,而不是 uni-app 应用的语言设置。
不过,你可以通过以下几种方式来尝试解决或缓解这个问题:
1. 设置设备的系统语言
- 你可以引导用户将设备的系统语言设置为与应用一致的语言。这样,原生组件(如相册)也会显示为相应的语言。
- 这种方法依赖于用户的操作,无法在代码中直接控制。
2. 使用 uni.chooseImage 替代 plus.gallery.pick
uni.chooseImage是uni-app提供的 API,它可能会更好地支持国际化,尤其是在某些平台上。- 虽然在某些情况下
uni.chooseImage的界面仍然依赖于系统语言,但它通常比plus.gallery.pick更可控。
3. 自定义相册选择器
- 如果你对用户体验有较高的要求,可以考虑自己实现一个相册选择器,或者使用第三方插件。
- 通过自定义实现,你可以完全控制界面的语言和样式。
4. 使用 plus.gallery.pick 的回调处理
- 虽然无法直接控制
plus.gallery.pick的界面语言,但你可以在回调中处理选中的图片,并根据应用的语言设置进行相应的提示或操作。
5. 使用插件或扩展
- 你可以寻找是否有支持国际化的第三方插件或扩展,或者自己开发一个插件来替代
plus.gallery.pick。
6. 与原生开发结合
- 如果应用对国际化有严格要求,可以考虑与原生开发结合,通过原生代码来控制相册选择器的语言和界面。
7. 反馈给官方
- 如果你认为这是一个重要的功能缺失,可以向
uni-app官方反馈,请求他们在未来的版本中增加对plus.gallery.pick和uni.chooseImage的国际化支持。
示例代码:使用 uni.chooseImage
uni.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
// 处理选中的图片
},
fail: function (err) {
console.log(err);
}
});

