244 lines
6.8 KiB
Dart
244 lines
6.8 KiB
Dart
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, ' ');
|
|
}
|
|
}
|