Skip to content

Commit

Permalink
[ Add, Edit ] 0.8.0 version, new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anasfik committed Oct 4, 2023
1 parent 55e1371 commit d1f4fad
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 73 deletions.
Binary file modified bin/langsync.exe
Binary file not shown.
5 changes: 2 additions & 3 deletions lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import 'package:langsync/src/version.dart';
import 'package:mason_logger/mason_logger.dart';
import 'package:pub_updater/pub_updater.dart';

import 'commands/start_command/start_command.dart';
import 'package:langsync/src/commands/start_command/start_command.dart';

const executableName = 'langsync';
const packageName = 'langsync';
const description =
'''
const description = '''
An AI powered Command Line Interface (CLI) tool that helps you process your original language-specific files such translations, strings & texts.. and generates the corresponding translated files in the target language(s).
Expand Down
2 changes: 0 additions & 2 deletions lib/src/commands/account_command/account_command.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:async';

import 'package:args/command_runner.dart';
import 'package:langsync/src/commands/account_command/sub_commands/api_key_command.dart';
import 'package:langsync/src/commands/account_command/sub_commands/auth_command.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ApiKeyCommand extends Command<int> {
@override
FutureOr<int>? run() async {
final userSure = logger.confirm(
"You're about to create a brand new unique API key, do you want to continue?");
"You're about to create a brand new unique API key, do you want to continue?",
);
if (!userSure) {
logger.info('Aborted!');
return 0;
Expand All @@ -30,7 +31,8 @@ class ApiKeyCommand extends Command<int> {
logger.info('\n');

final userName = logger.prompt(
'Please enter your desired username (will be used to identify you): ');
'Please enter your desired username (will be used to identify you): ',
);

if (userName.isEmpty) {
logger.err("Username can't be empty!");
Expand Down Expand Up @@ -72,9 +74,11 @@ class ApiKeyCommand extends Command<int> {
commandName: name,
);

logger.warn(
'\nThis error has been reported to the LangSync team, we will definitely look into it!',
);
logger
..info('\n')
..warn(
'This error has been reported to the LangSync team, we will definitely look into it!',
);
} catch (e) {}

return ExitCode.software.code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ class AuthCommand extends Command<int> {
commandName: name,
);

logger.warn(
'\nThis error has been reported to the LangSync team, we will definitely look into it!',
);
logger
..info('\n')
..warn(
'This error has been reported to the LangSync team, we will definitely look into it!',
);
} catch (e) {}

return ExitCode.ioError.code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:args/command_runner.dart';
import 'package:hive/hive.dart';
import 'package:langsync/src/etc/extensions.dart';
import 'package:langsync/src/etc/networking/client.dart';
import 'package:langsync/src/etc/utils.dart';
import 'package:mason_logger/mason_logger.dart';

class InfoCommand extends Command<int> {
Expand Down Expand Up @@ -79,8 +78,9 @@ class InfoCommand extends Command<int> {
commandName: name,
);

logger.info('\n');
logger.warn(
'\nThis error has been reported to the LangSync team, we will definitely look into it!',
'This error has been reported to the LangSync team, we will definitely look into it!',
);
} catch (e) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LogoutCommand extends Command<int> {

return ExitCode.success.code;
} else {
final confirm = await logger.confirm(
final confirm = logger.confirm(
'Are you sure you want to logout from the current account?',
);

Expand Down Expand Up @@ -59,9 +59,10 @@ class LogoutCommand extends Command<int> {
stacktrace: stacktrace,
commandName: name,
);
logger.info('\n');

logger.warn(
'\nThis error has been reported to the LangSync team, we will definitely look into it!',
'This error has been reported to the LangSync team, we will definitely look into it!',
);
} catch (e) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:args/command_runner.dart';
import 'package:langsync/src/etc/controllers/yaml.dart';
import 'package:langsync/src/etc/extensions.dart';
import 'package:langsync/src/etc/networking/client.dart';
import 'package:langsync/src/etc/utils.dart';
import 'package:mason_logger/mason_logger.dart';

class ConfigCreateCommand extends Command<int> {
Expand Down Expand Up @@ -160,8 +159,9 @@ class ConfigCreateCommand extends Command<int> {
commandName: name,
);

logger.info('\n');
logger.warn(
'\nThis error has been reported to the LangSync team, we will definitely look into it!',
'This error has been reported to the LangSync team, we will definitely look into it!',
);
} catch (e) {}

Expand Down
57 changes: 35 additions & 22 deletions lib/src/commands/start_command/start_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class StartCommand extends Command<int> {

return ExitCode.config.code;
}

configFilesValidationProgress.update('Parsing langsync.yaml file..');

final parsedYaml = await YamlController.parsedYaml;
Expand All @@ -72,9 +73,11 @@ class StartCommand extends Command<int> {
commandName: name,
);

logger.warn(
'\nThis error has been reported to the LangSync team, we will definitely look into it!',
);
logger
..info('\n')
..warn(
'This error has been reported to the LangSync team, we will definitely look into it!',
);
} catch (e) {}

return ExitCode.config.code;
Expand All @@ -98,7 +101,7 @@ class StartCommand extends Command<int> {
.complete('Your source file has been saved successfully.');

logger
// ..info("\n")
..info('\n')
..warn(
'The ID of this operation is: ${jsonPartitionRes.partitionId}. in case of any issues, please contact us providing this ID so we can help.',
)
Expand All @@ -119,11 +122,11 @@ class StartCommand extends Command<int> {
'Localization operation is completed successfully.',
);

logger.info('\n');

logger.info(
'Generating localization files: ${asConfig.langsJsonFiles.join(", ")}:',
);
logger
..info('\n')
..info(
'Generating localization files: ${asConfig.langsJsonFiles.join(", ")}.',
);

final outputList =
await NetClient.instance.retrieveJsonPartitionWithOutput(
Expand Down Expand Up @@ -153,9 +156,11 @@ class StartCommand extends Command<int> {
commandName: name,
);

logger.warn(
'\nThis error has been reported to the LangSync team, we will definitely look into it!',
);
logger
..info('\n')
..warn(
'This error has been reported to the LangSync team, we will definitely look into it!',
);
} catch (e) {}

return ExitCode.software.code;
Expand Down Expand Up @@ -190,6 +195,7 @@ class StartCommand extends Command<int> {
final current = outputList[index];

final isError = current.jsonFormattedResponse['error'] != null;

if (isError) {
final fileName = '${current.lang}.error.json';

Expand All @@ -208,18 +214,23 @@ class StartCommand extends Command<int> {
await file.writeAsString(
const JsonEncoder.withIndent(' ').convert(
{
...current.jsonFormattedResponse,
'partitionId': partitionId,
'lang': current.lang,
'LocalizationTryDate': current.localizedAt,
'message':
'if you need guide on this, please contact us with the content of this file.',
'Please, if you think that this is an unexpected bug in LangSync, contact us so we can help',
'partitionId': partitionId,
'processedResponse': current.jsonFormattedResponse.toString(),
'target_language': current.lang,
'success_file_name': '${current.lang}.json',
'LocalizationTryDate': {
'human_readable_format': current.localizedAt.toHumanReadable(),
'ISO_8601_format': current.localizedAt.toIso8601String(),
},
'contact_link': 'https://langsync.app/#contact',
},
),
);

progress.complete(
'file $fileName is created successfully, ${file.path}',
'file $fileName is created successfully, ${file.path.replaceAll("//", "/")}',
);
} else {
final fileName = '${current.lang}.json';
Expand All @@ -233,11 +244,13 @@ class StartCommand extends Command<int> {
.convert(current.jsonFormattedResponse),
);

progress
.complete('file $fileName is created successfully, ${file.path}');
progress.complete(
'file $fileName is created successfully, ${file.path.replaceAll("//", "/")}',
);
}

logger.success('All files are created successfully.');
}
logger
..info('\n')
..success('All files are created successfully.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ class SupportedLangsCommand extends Command<int> {
commandName: name,
);

logger.info('\n');
logger.warn(
'\nThis error has been reported to the LangSync team, we will definitely look into it!',
'This error has been reported to the LangSync team, we will definitely look into it!',
);
} catch (e) {}

Expand Down
13 changes: 10 additions & 3 deletions lib/src/etc/extensions.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'dart:math';

import 'package:langsync/src/etc/models/config.dart';
Expand Down Expand Up @@ -62,7 +61,9 @@ extension LoggerExt on Logger {
required String update,
required Object error,
}) {
const isDebugMode = true;
const isDebugMode = false;

info('\n');

if (isDebugMode) {
progress.fail(error.toString());
Expand All @@ -83,7 +84,7 @@ extension LoggerExt on Logger {
}
}

extension MapExtension on Map {
extension MapExtension on Map<dynamic, dynamic> {
LangSyncConfig toConfigModeled() {
return LangSyncConfig.fromMap(this);
}
Expand All @@ -94,3 +95,9 @@ extension JsonMapExtension on Map<String, dynamic> {
return const JsonEncoder.withIndent(' ').convert(this);
}
}

extension DateExt on DateTime {
String toHumanReadable() {
return '${day.toString().padLeft(2, '0')}/${month.toString().padLeft(2, '0')}/${year.toString().padLeft(2, '0')} ${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}:${second.toString().padLeft(2, '0')}';
}
}
26 changes: 13 additions & 13 deletions lib/src/etc/models/Localization_doc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,6 @@ class LocalizationDoc extends Equatable {
this.outputLangs,
});

final DateTime createdAt;
final String partitionId;
final int jsonPartsLength;
final List<String>? outputLangs;

@override
List<Object?> get props => [
createdAt,
partitionId,
jsonPartsLength,
outputLangs,
];

factory LocalizationDoc.fromJson(Map<String, dynamic> json) {
return LocalizationDoc(
createdAt: DateTime.parse(json['createdAt'] as String),
Expand All @@ -35,4 +22,17 @@ class LocalizationDoc extends Equatable {
: null,
);
}

final DateTime createdAt;
final String partitionId;
final int jsonPartsLength;
final List<String>? outputLangs;

@override
List<Object?> get props => [
createdAt,
partitionId,
jsonPartsLength,
outputLangs,
];
}
2 changes: 1 addition & 1 deletion lib/src/etc/models/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LangSyncConfig extends Equatable {
final String outputDir;
final Iterable<String> langs;

List<String> get langsJsonFiles => langs.map((e) => "$e.json").toList();
List<String> get langsJsonFiles => langs.map((e) => '$e.json').toList();

@override
List<Object?> get props => [
Expand Down
2 changes: 2 additions & 0 deletions lib/src/etc/models/lang_output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:equatable/equatable.dart';
class LangOutput extends Equatable {
final String lang;
final DateTime localizedAt;

final Map<String, dynamic> jsonFormattedResponse;

const LangOutput({
Expand All @@ -20,6 +21,7 @@ class LangOutput extends Equatable {
json['jsonDecodedResponse'] as Map<String, dynamic>,
);
}

@override
List<Object?> get props => [
lang,
Expand Down
5 changes: 3 additions & 2 deletions lib/src/etc/models/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class UserInfo extends Equatable {
? userJson['apiKeysLength'] as int
: int.parse(userJson['apiKeysLength'] as String),
localizationDocs: (userJson['localizationDocs'] as List<dynamic>)
.map((dynamic e) =>
LocalizationDoc.fromJson(e as Map<String, dynamic>))
.map(
(dynamic e) => LocalizationDoc.fromJson(e as Map<String, dynamic>),
)
.toList(),
);
}
Expand Down
Loading

0 comments on commit d1f4fad

Please sign in to comment.