Skip to content

Commit

Permalink
[ Edit ] edited the config file model class and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anasfik committed Dec 6, 2023
1 parent 84716b6 commit d429cd4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/src/commands/start_command/start_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class StartCommand extends Command<int> {
logger
..info('\n')
..info(
'Generating localization files: ${asConfig.langsJsonFiles.join(", ")}.',
'Generating localization files: ${asConfig.langsJsonFiles().join(", ")}.',
);

final outputList =
Expand Down
4 changes: 4 additions & 0 deletions lib/src/etc/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ extension FileSystemEntityExt on FileSystemEntity {
String get fileNameOnly => basename(path);
}

extension IterbaleExt on LangSyncConfig {
List<String> langsJsonFiles() => langs.map((e) => '$e.json').toList();
}

extension StringExt on String {
String tr() {
return this;
Expand Down
1 change: 1 addition & 0 deletions lib/src/etc/models/api_key_res.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:equatable/equatable.dart';

///! Scheduled for removal.
class APIKeyResponse extends Equatable {
const APIKeyResponse({
required this.username,
Expand Down
18 changes: 16 additions & 2 deletions lib/src/etc/models/config.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:equatable/equatable.dart';
import 'package:yaml/yaml.dart';

/// {@template langsync_config}
/// The LangSync config model, it holds possible configurations that relates to the config file reference that will be read or/and write to.
/// {@endtemplate}
class LangSyncConfig extends Equatable {
/// {@macro langsync_config}
const LangSyncConfig({
required this.sourceFile,
required this.outputDir,
Expand All @@ -10,6 +14,7 @@ class LangSyncConfig extends Equatable {
this.instruction,
});

/// Creates a [LangSyncConfig] from a [Map].
factory LangSyncConfig.fromMap(Map<dynamic, dynamic> map) {
final langsyncMapField = map['langsync'] as Map;

Expand All @@ -33,22 +38,31 @@ class LangSyncConfig extends Equatable {
);
}

/// The source localization file path.
final String sourceFile;

/// The output directory path.
final String outputDir;

/// The target languages to generate localizations for.
final Iterable<String> langs;

/// The maximum language localization can take to be generated in seconds, if a language localization takes more than this value, it will be skipped.
final int? languageLocalizationMaxDelay;
final String? instruction;

List<String> get langsJsonFiles => langs.map((e) => '$e.json').toList();
/// The AI instruction to generate localizations, if any.
final String? instruction;

@override
List<Object?> get props => [
sourceFile,
outputDir,
langs,
languageLocalizationMaxDelay,
instruction,
];

/// Converts the [LangSyncConfig] to a [Map].
Map<String, dynamic> toMap() {
return {
'source': sourceFile,
Expand Down

0 comments on commit d429cd4

Please sign in to comment.