Skip to content

Commit

Permalink
feat: export to zip, more locales info
Browse files Browse the repository at this point in the history
  • Loading branch information
Gorniv committed May 10, 2020
1 parent 3e60e98 commit 29b66c7
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 9 deletions.
23 changes: 21 additions & 2 deletions lib/project/project_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:convert';

import 'package:archive/archive_io.dart';
import 'package:doppio_dev_ixn/core/index.dart';
import 'package:doppio_dev_ixn/main.dart';
import 'package:doppio_dev_ixn/project_setting/index.dart';
Expand All @@ -7,6 +10,7 @@ import 'package:doppio_dev_ixn/project/index.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pedantic/pedantic.dart';
import 'package:uuid/uuid.dart';
import 'package:file_manager/file_manager.dart' as manager;

class ProjectPage extends StatefulWidget {
static const String routeName = '/project';
Expand Down Expand Up @@ -94,7 +98,7 @@ class _ProjectPageState extends State<ProjectPage> {
Spacer(),
IconButton(
onPressed: () async {
await _export();
await _export(projectModel);
},
tooltip: 'Export',
icon: Icon(Icons.file_upload),
Expand Down Expand Up @@ -144,8 +148,23 @@ class _ProjectPageState extends State<ProjectPage> {
});
}

Future _export() async {
Future _export(ProjectModel projectModel) async {
try {
var encoder = ZipEncoder();
final archive = Archive();
for (var locale in projectModel.locales) {
final mapWord = <String, String>{};
final result = <String, String>{};
projectModel.words.where((c) => c.locale == locale).map((e) => mapWord[e.keyId] = e.value).toList();
for (var item in projectModel.keys) {
result['"${item.value}"'] = '"${mapWord[item.id]}"';
}
final bytes = Utf8Codec().encode(result.toString());
final archiveFile = ArchiveFile('$locale.json', bytes.length, bytes);
archive.addFile(archiveFile);
}
final bytesZip = encoder.encode(archive);
await manager.saveFile('${projectModel.name}-ixn.zip', binaryData: bytesZip);
// projectScreen.import(filesData);
} catch (_, stackTrace) {
log(_?.toString(), name: 'ProjectsPage', error: _, stackTrace: stackTrace);
Expand Down
4 changes: 2 additions & 2 deletions lib/project_setting/project_setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ProjectSettingScreenState extends State<ProjectSettingScreen> {
void initState() {
locales = kMaterialSupportedLanguages.toList();
locales.sort();
localesList = {for (var code in locales) code: '$code - ${TranslateService.localesCountry[code]}'};
localesList = {for (var code in locales) code: '$code - ${TranslateService.localeCountryName[code]}'};
super.initState();
}

Expand Down Expand Up @@ -171,7 +171,7 @@ class ProjectSettingScreenState extends State<ProjectSettingScreen> {
),
Expanded(
child: Text(
'$code - ${TranslateService.localesCountry[code]}',
'$code - ${TranslateService.localeCountryName[code]}',
overflow: TextOverflow.clip,
),
)
Expand Down
Loading

0 comments on commit 29b66c7

Please sign in to comment.