Compare commits
3 Commits
ad0d329b3b
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7781fcd17a | |||
| 6e1b5c2de0 | |||
| cf2826c1cf |
@@ -2,6 +2,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_common/upload_image/ossUtil.dart';
|
import 'package:flutter_common/upload_image/ossUtil.dart';
|
||||||
|
import 'package:flutter_common/utils/asset_picker_localization.dart';
|
||||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
@@ -34,22 +35,6 @@ class _ImageCompressionTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class UploadImagesTool {
|
class UploadImagesTool {
|
||||||
static String _assetPathNameBuilder(AssetPathEntity path) {
|
|
||||||
final locale =
|
|
||||||
Get.locale ?? WidgetsBinding.instance.platformDispatcher.locale;
|
|
||||||
if (locale.languageCode.toLowerCase() != 'zh') {
|
|
||||||
return path.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
const systemPathNameMap = {
|
|
||||||
'Recent': '最近项目',
|
|
||||||
'Camera': '相机',
|
|
||||||
'Screenshots': '截屏',
|
|
||||||
'Downloads': '下载',
|
|
||||||
};
|
|
||||||
return systemPathNameMap[path.name] ?? path.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uploadImagesTool({
|
static uploadImagesTool({
|
||||||
String? oSSAccessKeyId,
|
String? oSSAccessKeyId,
|
||||||
String? policy,
|
String? policy,
|
||||||
@@ -312,7 +297,8 @@ class UploadImagesTool {
|
|||||||
pickerConfig: AssetPickerConfig(
|
pickerConfig: AssetPickerConfig(
|
||||||
maxAssets: 1,
|
maxAssets: 1,
|
||||||
requestType: RequestType.video,
|
requestType: RequestType.video,
|
||||||
pathNameBuilder: _assetPathNameBuilder,
|
pathNameBuilder: (AssetPathEntity path) =>
|
||||||
|
AssetPickerLocalization.pathName(Get.context!, path),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final File? video = await result?.first.file;
|
final File? video = await result?.first.file;
|
||||||
@@ -335,7 +321,8 @@ class UploadImagesTool {
|
|||||||
Get.context!,
|
Get.context!,
|
||||||
pickerConfig: AssetPickerConfig(
|
pickerConfig: AssetPickerConfig(
|
||||||
maxAssets: max ?? 50,
|
maxAssets: max ?? 50,
|
||||||
pathNameBuilder: _assetPathNameBuilder,
|
pathNameBuilder: (AssetPathEntity path) =>
|
||||||
|
AssetPickerLocalization.pathName(Get.context!, path),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export 'video_batch_upload_config.dart';
|
export 'video_batch_upload_config.dart';
|
||||||
|
export 'video_batch_upload_service.dart';
|
||||||
export 'video_batch_upload_task.dart';
|
export 'video_batch_upload_task.dart';
|
||||||
export 'video_batch_uploader.dart';
|
export 'video_batch_uploader.dart';
|
||||||
export 'video_batch_upload_widgets.dart';
|
export 'video_batch_upload_widgets.dart';
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'dart:io';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_common/utils/asset_picker_localization.dart';
|
||||||
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
||||||
|
|
||||||
import 'video_batch_upload_config.dart';
|
import 'video_batch_upload_config.dart';
|
||||||
@@ -42,6 +43,8 @@ class VideoBatchUploadPicker {
|
|||||||
pickerConfig: AssetPickerConfig(
|
pickerConfig: AssetPickerConfig(
|
||||||
maxAssets: maxAssets,
|
maxAssets: maxAssets,
|
||||||
requestType: _requestType(assetType),
|
requestType: _requestType(assetType),
|
||||||
|
pathNameBuilder: (AssetPathEntity path) =>
|
||||||
|
AssetPickerLocalization.pathName(context, path),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (assets == null || assets.isEmpty) {
|
if (assets == null || assets.isEmpty) {
|
||||||
|
|||||||
@@ -0,0 +1,243 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
||||||
|
|
||||||
|
abstract final class AssetPickerLocalization {
|
||||||
|
static final RegExp _separatorPattern = RegExp(r'[._-]+');
|
||||||
|
static final RegExp _whitespacePattern = RegExp(r'\s+');
|
||||||
|
|
||||||
|
static const Map<String, String> _systemPathNames = <String, String>{
|
||||||
|
'recent': '最近项目',
|
||||||
|
'recents': '最近项目',
|
||||||
|
'all': '全部',
|
||||||
|
'all photos': '所有照片',
|
||||||
|
'all images': '所有图片',
|
||||||
|
'all videos': '所有视频',
|
||||||
|
'camera': '相机',
|
||||||
|
'camera roll': '相机胶卷',
|
||||||
|
'dcim': '相机',
|
||||||
|
'screenshot': '截屏',
|
||||||
|
'screenshots': '截屏',
|
||||||
|
'screen shot': '截屏',
|
||||||
|
'screen shots': '截屏',
|
||||||
|
'screen recording': '屏幕录制',
|
||||||
|
'screen recordings': '屏幕录制',
|
||||||
|
'screen recorder': '屏幕录制',
|
||||||
|
'recordings': '录制内容',
|
||||||
|
'recording': '录制内容',
|
||||||
|
'pictures': '图片',
|
||||||
|
'picture': '图片',
|
||||||
|
'images': '图片',
|
||||||
|
'image': '图片',
|
||||||
|
'photos': '照片',
|
||||||
|
'photo': '照片',
|
||||||
|
'videos': '视频',
|
||||||
|
'video': '视频',
|
||||||
|
'movies': '影片',
|
||||||
|
'movie': '影片',
|
||||||
|
'downloads': '下载',
|
||||||
|
'download': '下载',
|
||||||
|
'documents': '文档',
|
||||||
|
'document': '文档',
|
||||||
|
'saved pictures': '已保存的图片',
|
||||||
|
'saved images': '已保存的图片',
|
||||||
|
'saved photos': '已保存的照片',
|
||||||
|
'edited': '已编辑',
|
||||||
|
'edited photos': '已编辑照片',
|
||||||
|
'edited images': '已编辑图片',
|
||||||
|
'cropped': '已裁剪',
|
||||||
|
'cropped images': '已裁剪图片',
|
||||||
|
'collage': '拼图',
|
||||||
|
'collages': '拼图',
|
||||||
|
'restored': '已恢复',
|
||||||
|
'favorites': '收藏',
|
||||||
|
'favourites': '收藏',
|
||||||
|
'favorite': '收藏',
|
||||||
|
'favourite': '收藏',
|
||||||
|
'hidden': '已隐藏',
|
||||||
|
'trash': '回收站',
|
||||||
|
'recycle bin': '回收站',
|
||||||
|
'recently deleted': '最近删除',
|
||||||
|
'panorama': '全景照片',
|
||||||
|
'panoramas': '全景照片',
|
||||||
|
'portrait': '人像',
|
||||||
|
'portraits': '人像',
|
||||||
|
'selfie': '自拍',
|
||||||
|
'selfies': '自拍',
|
||||||
|
'live photo': '实况照片',
|
||||||
|
'live photos': '实况照片',
|
||||||
|
'raw': 'RAW 照片',
|
||||||
|
'raw photos': 'RAW 照片',
|
||||||
|
'gif': '动图',
|
||||||
|
'gifs': '动图',
|
||||||
|
'animated': '动图',
|
||||||
|
'animated images': '动图',
|
||||||
|
'burst': '连拍快照',
|
||||||
|
'bursts': '连拍快照',
|
||||||
|
'slow motion': '慢动作',
|
||||||
|
'slo mo': '慢动作',
|
||||||
|
'time lapse': '延时摄影',
|
||||||
|
'long screenshot': '长截屏',
|
||||||
|
'long screenshots': '长截屏',
|
||||||
|
'wallpaper': '壁纸',
|
||||||
|
'wallpapers': '壁纸',
|
||||||
|
'bluetooth': '蓝牙',
|
||||||
|
'nearby share': '附近分享',
|
||||||
|
'received files': '接收的文件',
|
||||||
|
'scanner': '扫描件',
|
||||||
|
'scans': '扫描件',
|
||||||
|
'mishare': '小米互传',
|
||||||
|
'huawei share': '华为分享',
|
||||||
|
'honor share': '荣耀分享',
|
||||||
|
'shareit': '茄子快传',
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Map<String, String> _appPathNames = <String, String>{
|
||||||
|
'facebook messenger': 'Messenger',
|
||||||
|
'photoshop express': 'Photoshop Express',
|
||||||
|
'baidu netdisk': '百度网盘',
|
||||||
|
'baidunetdisk': '百度网盘',
|
||||||
|
'tencent qq': 'QQ',
|
||||||
|
'qqfile recv': 'QQ 接收文件',
|
||||||
|
'micro msg': '微信',
|
||||||
|
'micromsg': '微信',
|
||||||
|
'com tencent mm': '微信',
|
||||||
|
'wei xin': '微信',
|
||||||
|
'weixin': '微信',
|
||||||
|
'wechat': '微信',
|
||||||
|
'wechat work': '企业微信',
|
||||||
|
'wecom': '企业微信',
|
||||||
|
'wework': '企业微信',
|
||||||
|
'wxwork': '企业微信',
|
||||||
|
'qq': 'QQ',
|
||||||
|
'dingtalk': '钉钉',
|
||||||
|
'ding talk': '钉钉',
|
||||||
|
'feishu': '飞书',
|
||||||
|
'lark': '飞书',
|
||||||
|
'sina weibo': '微博',
|
||||||
|
'weibo': '微博',
|
||||||
|
'douyin': '抖音',
|
||||||
|
'aweme': '抖音',
|
||||||
|
'tiktok': 'TikTok',
|
||||||
|
'kuaishou': '快手',
|
||||||
|
'kwai': '快手',
|
||||||
|
'xiaohongshu': '小红书',
|
||||||
|
'xhs': '小红书',
|
||||||
|
'red': '小红书',
|
||||||
|
'bilibili': '哔哩哔哩',
|
||||||
|
'zhihu': '知乎',
|
||||||
|
'baidu': '百度',
|
||||||
|
'alipay': '支付宝',
|
||||||
|
'taobao': '淘宝',
|
||||||
|
'tmall': '天猫',
|
||||||
|
'jingdong': '京东',
|
||||||
|
'jd': '京东',
|
||||||
|
'wps': 'WPS',
|
||||||
|
'ucdownloads': 'UC 下载',
|
||||||
|
'qqbrowser': 'QQ 浏览器',
|
||||||
|
'quark': '夸克',
|
||||||
|
'netdisk': '网盘',
|
||||||
|
'whatsapp': 'WhatsApp',
|
||||||
|
'whatsapp business': 'WhatsApp Business',
|
||||||
|
'telegram': 'Telegram',
|
||||||
|
'instagram': 'Instagram',
|
||||||
|
'facebook': 'Facebook',
|
||||||
|
'messenger': 'Messenger',
|
||||||
|
'twitter': 'Twitter',
|
||||||
|
'snapchat': 'Snapchat',
|
||||||
|
'line': 'LINE',
|
||||||
|
'discord': 'Discord',
|
||||||
|
'reddit': 'Reddit',
|
||||||
|
'pinterest': 'Pinterest',
|
||||||
|
'signal': 'Signal',
|
||||||
|
'viber': 'Viber',
|
||||||
|
'capcut': '剪映',
|
||||||
|
'jianying': '剪映',
|
||||||
|
'meitu': '美图',
|
||||||
|
'picsart': 'PicsArt',
|
||||||
|
'canva': 'Canva',
|
||||||
|
'lightroom': 'Lightroom',
|
||||||
|
'inshot': 'InShot',
|
||||||
|
'kinemaster': 'KineMaster',
|
||||||
|
'google photos': 'Google 相册',
|
||||||
|
'onedrive': 'OneDrive',
|
||||||
|
'dropbox': 'Dropbox',
|
||||||
|
};
|
||||||
|
|
||||||
|
static const Map<String, String> _mediaSuffixNames = <String, String>{
|
||||||
|
'image': '图片',
|
||||||
|
'images': '图片',
|
||||||
|
'picture': '图片',
|
||||||
|
'pictures': '图片',
|
||||||
|
'photo': '照片',
|
||||||
|
'photos': '照片',
|
||||||
|
'video': '视频',
|
||||||
|
'videos': '视频',
|
||||||
|
'movie': '影片',
|
||||||
|
'movies': '影片',
|
||||||
|
'audio': '音频',
|
||||||
|
'audios': '音频',
|
||||||
|
'music': '音乐',
|
||||||
|
'document': '文档',
|
||||||
|
'documents': '文档',
|
||||||
|
'doc': '文档',
|
||||||
|
'docs': '文档',
|
||||||
|
'file': '文件',
|
||||||
|
'files': '文件',
|
||||||
|
'download': '下载',
|
||||||
|
'downloads': '下载',
|
||||||
|
'received': '接收文件',
|
||||||
|
'received files': '接收文件',
|
||||||
|
'animated gif': '动图',
|
||||||
|
'animated gifs': '动图',
|
||||||
|
'gif': '动图',
|
||||||
|
'gifs': '动图',
|
||||||
|
};
|
||||||
|
|
||||||
|
static String pathName(
|
||||||
|
BuildContext context,
|
||||||
|
AssetPathEntity path,
|
||||||
|
) {
|
||||||
|
final Locale locale = Localizations.maybeLocaleOf(context) ??
|
||||||
|
WidgetsBinding.instance.platformDispatcher.locale;
|
||||||
|
return pathNameForLocale(locale, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String pathNameForLocale(Locale locale, AssetPathEntity path) {
|
||||||
|
if (locale.languageCode.toLowerCase() != 'zh') {
|
||||||
|
return path.name;
|
||||||
|
}
|
||||||
|
if (path.isAll) {
|
||||||
|
return '最近项目';
|
||||||
|
}
|
||||||
|
|
||||||
|
final String normalizedName = _normalize(path.name);
|
||||||
|
final String? systemName = _systemPathNames[normalizedName];
|
||||||
|
if (systemName != null) {
|
||||||
|
return systemName;
|
||||||
|
}
|
||||||
|
final String? appName = _appPathNames[normalizedName];
|
||||||
|
if (appName != null) {
|
||||||
|
return appName;
|
||||||
|
}
|
||||||
|
for (final MapEntry<String, String> app in _appPathNames.entries) {
|
||||||
|
final String prefix = '${app.key} ';
|
||||||
|
if (!normalizedName.startsWith(prefix)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final String suffix = normalizedName.substring(prefix.length);
|
||||||
|
final String? translatedSuffix = _mediaSuffixNames[suffix];
|
||||||
|
if (translatedSuffix != null) {
|
||||||
|
return '${app.value} $translatedSuffix';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String _normalize(String name) {
|
||||||
|
return name
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.replaceAll(_separatorPattern, ' ')
|
||||||
|
.replaceAll(_whitespacePattern, ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_common/utils/asset_picker_localization.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
AssetPathEntity path(String name, {bool isAll = false}) {
|
||||||
|
return AssetPathEntity(id: name, name: name, isAll: isAll);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('localizes the Android all-assets path', () {
|
||||||
|
expect(
|
||||||
|
AssetPickerLocalization.pathNameForLocale(
|
||||||
|
const Locale('zh', 'CN'),
|
||||||
|
path('Recent', isAll: true),
|
||||||
|
),
|
||||||
|
'最近项目',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('localizes common system albums', () {
|
||||||
|
expect(
|
||||||
|
AssetPickerLocalization.pathNameForLocale(
|
||||||
|
const Locale('zh', 'CN'),
|
||||||
|
path('screen_recordings'),
|
||||||
|
),
|
||||||
|
'屏幕录制',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
AssetPickerLocalization.pathNameForLocale(
|
||||||
|
const Locale('zh', 'CN'),
|
||||||
|
path('Live Photos'),
|
||||||
|
),
|
||||||
|
'实况照片',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('localizes application albums and media suffixes', () {
|
||||||
|
expect(
|
||||||
|
AssetPickerLocalization.pathNameForLocale(
|
||||||
|
const Locale('zh', 'CN'),
|
||||||
|
path('WeiXin'),
|
||||||
|
),
|
||||||
|
'微信',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
AssetPickerLocalization.pathNameForLocale(
|
||||||
|
const Locale('zh', 'CN'),
|
||||||
|
path('WhatsApp_Images'),
|
||||||
|
),
|
||||||
|
'WhatsApp 图片',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('keeps unknown and non-Chinese album names unchanged', () {
|
||||||
|
expect(
|
||||||
|
AssetPickerLocalization.pathNameForLocale(
|
||||||
|
const Locale('zh', 'CN'),
|
||||||
|
path('My Family'),
|
||||||
|
),
|
||||||
|
'My Family',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
AssetPickerLocalization.pathNameForLocale(
|
||||||
|
const Locale('en', 'US'),
|
||||||
|
path('Camera'),
|
||||||
|
),
|
||||||
|
'Camera',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user