opt.: l10n & fix: write script (#514)

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-08-03 22:44:21 +08:00
committed by GitHub
parent 610f46da0d
commit 9db04a60c2
55 changed files with 686 additions and 2201 deletions

View File

@@ -57,7 +57,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
context.pop();
},
),
title: Text(l10n.files),
title: Text(libL10n.file),
actions: [
IconButton(
icon: const Icon(Icons.downloading),
@@ -72,7 +72,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
return [
PopupMenuItem(
value: _SortType.name,
child: Text(l10n.name),
child: Text(libL10n.name),
),
PopupMenuItem(
value: _SortType.size,
@@ -111,7 +111,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
OmitStartText(_path?.path ?? l10n.loadingFiles),
OmitStartText(_path?.path ?? '...'),
_buildBtns(),
],
),
@@ -203,7 +203,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
context.pop();
_showRenameDialog(file);
},
title: Text(l10n.rename),
title: Text(libL10n.rename),
leading: const Icon(Icons.abc),
),
ListTile(
@@ -211,7 +211,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
context.pop();
_showDeleteDialog(file);
},
title: Text(l10n.delete),
title: Text(libL10n.delete),
leading: const Icon(Icons.delete),
),
],
@@ -223,17 +223,15 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
final fileName = file.path.split('/').last;
if (widget.isPickFile) {
await context.showRoundDialog(
title: l10n.pickFile,
child: Text(fileName),
actions: [
TextButton(
onPressed: () {
context.pop();
context.pop(file.path);
},
child: Text(l10n.ok),
),
]);
title: libL10n.file,
child: Text(fileName),
actions: [
Btn.ok(onTap: (c) {
context.pop();
context.pop(file.path);
}),
],
);
return;
}
context.showRoundDialog(
@@ -242,13 +240,13 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
children: [
ListTile(
leading: const Icon(Icons.edit),
title: Text(l10n.edit),
title: Text(libL10n.edit),
onTap: () async {
context.pop();
final stat = await file.stat();
if (stat.size > Miscs.editorMaxSize) {
context.showRoundDialog(
title: l10n.attention,
title: libL10n.attention,
child: Text(l10n.fileTooLarge(fileName, stat.size, '1m')),
);
return;
@@ -264,7 +262,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
),
ListTile(
leading: const Icon(Icons.abc),
title: Text(l10n.rename),
title: Text(libL10n.rename),
onTap: () {
context.pop();
_showRenameDialog(file);
@@ -272,7 +270,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
),
ListTile(
leading: const Icon(Icons.delete),
title: Text(l10n.delete),
title: Text(libL10n.delete),
onTap: () {
context.pop();
_showDeleteDialog(file);
@@ -285,7 +283,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
context.pop();
final spi = await context.showPickSingleDialog<ServerPrivateInfo>(
title: l10n.choose,
title: libL10n.select,
items: Pros.server.serverOrder
.map((e) => Pros.server.pick(id: e)?.spi)
.toList(),
@@ -325,7 +323,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
void _showRenameDialog(FileSystemEntity file) {
final fileName = file.path.split('/').last;
context.showRoundDialog(
title: l10n.rename,
title: libL10n.rename,
child: Input(
autoFocus: true,
controller: TextEditingController(text: fileName),
@@ -336,7 +334,7 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
try {
file.renameSync(newPath);
} catch (e) {
context.showSnackBar('${l10n.failed}:\n$e');
context.showSnackBar('${libL10n.fail}:\n$e');
return;
}
@@ -349,27 +347,20 @@ class _LocalStoragePageState extends State<LocalStoragePage> {
void _showDeleteDialog(FileSystemEntity file) {
final fileName = file.path.split('/').last;
context.showRoundDialog(
title: l10n.delete,
child: Text(l10n.askContinue('${l10n.delete} $fileName')),
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text(l10n.cancel),
),
TextButton(
onPressed: () {
context.pop();
try {
file.deleteSync(recursive: true);
} catch (e) {
context.showSnackBar('${l10n.failed}:\n$e');
return;
}
setState(() {});
},
child: Text(l10n.ok),
),
],
title: libL10n.delete,
child: Text(libL10n.askContinue('${libL10n.delete} $fileName')),
actions: Btn.ok(
onTap: (c) {
context.pop();
try {
file.deleteSync(recursive: true);
} catch (e) {
context.showSnackBar('${libL10n.fail}:\n$e');
return;
}
setState(() {});
},
).toList,
);
}
}

View File

@@ -69,7 +69,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
itemBuilder: (context) {
final currentSelectedOption = _sortOption.value;
final options = [
(_SortType.name, l10n.name),
(_SortType.name, libL10n.name),
(_SortType.size, l10n.size),
(_SortType.time, l10n.time),
];
@@ -142,7 +142,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
OmitStartText(_status.path?.path ?? l10n.loadingFiles),
OmitStartText(_status.path?.path ?? '...'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: children,
@@ -232,12 +232,12 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
children: [
ListTile(
leading: const Icon(Icons.folder),
title: Text(l10n.createFolder),
title: Text(libL10n.folder),
onTap: _mkdir,
),
ListTile(
leading: const Icon(Icons.insert_drive_file),
title: Text(l10n.createFile),
title: Text(libL10n.file),
onTap: _newFile,
),
],
@@ -369,12 +369,12 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
final children = [
ListTile(
leading: const Icon(Icons.delete),
title: Text(l10n.delete),
title: Text(libL10n.delete),
onTap: () => _delete(file),
),
ListTile(
leading: const Icon(Icons.abc),
title: Text(l10n.rename),
title: Text(libL10n.rename),
onTap: () => _rename(file),
),
ListTile(
@@ -413,12 +413,12 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
children.addAll([
ListTile(
leading: const Icon(Icons.edit),
title: Text(l10n.edit),
title: Text(libL10n.edit),
onTap: () => _edit(file),
),
ListTile(
leading: const Icon(Icons.download),
title: Text(l10n.download),
title: Text(libL10n.download),
onTap: () => _download(file),
),
// Only show decompress option when the file is a compressed file
@@ -490,12 +490,12 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
void _download(SftpName name) {
context.showRoundDialog(
title: l10n.attention,
title: libL10n.attention,
child: Text('${l10n.dl2Local(name.filename)}\n${l10n.keepForeground}'),
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text(l10n.cancel),
child: Text(libL10n.cancel),
),
TextButton(
onPressed: () async {
@@ -513,7 +513,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
context.pop();
},
child: Text(l10n.download),
child: Text(libL10n.download),
)
],
);
@@ -525,15 +525,15 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
var useRmr = Stores.setting.sftpRmrDir.fetch();
final text = () {
if (isDir && !useRmr) {
return l10n.askContinue('${l10n.delete} ${file.filename}');
return libL10n.askContinue('${libL10n.delete} ${file.filename}');
}
return l10n.askContinue('${l10n.delete} ${file.filename}');
return libL10n.askContinue('${libL10n.delete} ${file.filename}');
}();
// Most users don't know that SFTP can't delete a directory which is not
// empty, so we provide a checkbox to let user choose to use `rm -r` or not
context.showRoundDialog(
title: l10n.attention,
title: libL10n.attention,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -560,7 +560,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text(l10n.cancel),
child: Text(libL10n.cancel),
),
TextButton(
onPressed: () async {
@@ -583,7 +583,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
_listDir();
},
child: Text(l10n.delete, style: UIs.textRed),
child: Text(libL10n.delete, style: UIs.textRed),
),
],
);
@@ -596,13 +596,8 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
void onSubmitted() async {
if (textController.text.isEmpty) {
context.showRoundDialog(
child: Text(l10n.fieldMustNotEmpty),
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text(l10n.ok),
),
],
child: Text(libL10n.empty),
actions: Btnx.oks,
);
return;
}
@@ -621,25 +616,19 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
}
context.showRoundDialog(
title: l10n.createFolder,
title: libL10n.folder,
child: Input(
autoFocus: true,
icon: Icons.folder,
controller: textController,
label: l10n.name,
label: libL10n.name,
suggestion: true,
onSubmitted: (_) => onSubmitted(),
),
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text(l10n.cancel),
),
TextButton(
onPressed: onSubmitted,
child: Text(l10n.ok, style: UIs.textRed),
),
],
actions: Btn.ok(
onTap: (c) => onSubmitted(),
red: true,
).toList,
);
}
@@ -650,14 +639,11 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
void onSubmitted() async {
if (textController.text.isEmpty) {
context.showRoundDialog(
title: l10n.attention,
child: Text(l10n.fieldMustNotEmpty),
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text(l10n.ok),
),
],
title: libL10n.attention,
child: Text(libL10n.empty),
actions: Btn.ok(
onTap: (c) => context.pop(),
).toList,
);
return;
}
@@ -676,21 +662,19 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
}
context.showRoundDialog(
title: l10n.createFile,
title: libL10n.file,
child: Input(
autoFocus: true,
icon: Icons.insert_drive_file,
controller: textController,
label: l10n.name,
label: libL10n.name,
suggestion: true,
onSubmitted: (_) => onSubmitted(),
),
actions: [
TextButton(
onPressed: onSubmitted,
child: Text(l10n.ok, style: UIs.textRed),
),
],
actions: Btn.ok(
onTap: (c) => onSubmitted(),
red: true,
).toList,
);
}
@@ -701,14 +685,11 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
void onSubmitted() async {
if (textController.text.isEmpty) {
context.showRoundDialog(
title: l10n.attention,
child: Text(l10n.fieldMustNotEmpty),
actions: [
TextButton(
onPressed: () => context.pop(),
child: Text(l10n.ok),
),
],
title: libL10n.attention,
child: Text(libL10n.empty),
actions: Btn.ok(
onTap: (c) => context.pop(),
).toList,
);
return;
}
@@ -727,20 +708,20 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
}
context.showRoundDialog(
title: l10n.rename,
title: libL10n.rename,
child: Input(
autoFocus: true,
icon: Icons.abc,
controller: textController,
label: l10n.name,
label: libL10n.name,
suggestion: true,
onSubmitted: (_) => onSubmitted(),
),
actions: [
TextButton(onPressed: () => context.pop(), child: Text(l10n.cancel)),
TextButton(onPressed: () => context.pop(), child: Text(libL10n.cancel)),
TextButton(
onPressed: onSubmitted,
child: Text(l10n.rename, style: UIs.textRed),
child: Text(libL10n.rename, style: UIs.textRed),
),
],
);
@@ -752,7 +733,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
final cmd = _getDecompressCmd(absPath);
if (cmd == null) {
context.showRoundDialog(
title: l10n.error,
title: libL10n.error,
child: Text('Unsupport file: ${name.filename}'),
actions: [Btn.ok()],
);
@@ -760,7 +741,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
}
final confirm = await context.showRoundDialog(
title: l10n.attention,
title: libL10n.attention,
child: SimpleMarkdown(data: '```sh\n$cmd\n```'),
actions: [
Btn.cancel(onTap: (c) => c.pop(false)),

View File

@@ -28,9 +28,7 @@ class _SftpMissionPageState extends State<SftpMissionPage> {
Widget _buildBody() {
return Consumer<SftpProvider>(builder: (__, pro, _) {
if (pro.status.isEmpty) {
return Center(
child: Text(l10n.noTask),
);
return Center(child: Text(libL10n.empty));
}
return ListView.builder(
padding: const EdgeInsets.all(11),
@@ -48,10 +46,10 @@ class _SftpMissionPageState extends State<SftpMissionPage> {
if (err != null) {
return _wrapInCard(
status: status,
subtitle: l10n.error,
subtitle: libL10n.error,
trailing: IconButton(
onPressed: () => context.showRoundDialog(
title: l10n.error,
title: libL10n.error,
child: Text(err.toString()),
),
icon: const Icon(Icons.error),
@@ -81,7 +79,7 @@ class _SftpMissionPageState extends State<SftpMissionPage> {
subtitle: l10n.unknown,
trailing: IconButton(
onPressed: () => context.showRoundDialog(
title: l10n.error,
title: libL10n.error,
child: Text((status.error ?? l10n.unknown).toString()),
),
icon: const Icon(Icons.error),
@@ -109,9 +107,9 @@ class _SftpMissionPageState extends State<SftpMissionPage> {
Widget _buildFinished(SftpReqStatus status) {
final time = status.spentTime.toString();
final str = '${l10n.finished} ${l10n.spentTime(
final str = l10n.spentTime(
time == 'null' ? l10n.unknown : (time.substring(0, time.length - 7)),
)}';
);
final btns = Row(
mainAxisSize: MainAxisSize.min,
@@ -161,19 +159,17 @@ class _SftpMissionPageState extends State<SftpMissionPage> {
Widget _buildDelete(String name, int id) {
return IconButton(
onPressed: () => context.showRoundDialog(
title: l10n.attention,
child: Text(l10n.askContinue(
'${l10n.delete} ${l10n.mission}($name)',
)),
actions: [
TextButton(
onPressed: () {
Pros.sftp.cancel(id);
context.pop();
},
child: Text(l10n.ok),
),
]),
title: libL10n.attention,
child: Text(libL10n.askContinue(
'${libL10n.delete} ${l10n.mission}($name)',
)),
actions: Btn.ok(
onTap: (c) {
Pros.sftp.cancel(id);
context.pop();
},
).toList,
),
icon: const Icon(Icons.delete),
);
}