Skip to content

Commit 22c13e7

Browse files
committed
feat: improve Localizely configuration parsing and error handling
1 parent 19aa813 commit 22c13e7

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

lib/src/commands/resources/processors/translation_processor.dart

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,34 @@ class TranslationProcessor {
2828
return;
2929
}
3030

31-
final config = loadYaml(await configFile.readAsString());
32-
final localeCodes = (config['download']['files'] as List).map((e) => e['locale_code']).toSet();
31+
final localeCodes = <String>{};
32+
33+
try {
34+
final yamlString = await configFile.readAsString();
35+
final config = loadYaml(yamlString) as YamlMap;
36+
final downloadConfig = config['download'] as YamlMap;
37+
final filesConfig = downloadConfig['files'] as YamlList;
38+
39+
for (final item in filesConfig.cast<YamlMap>()) {
40+
final localeCode = item['locale_code'] as String?;
41+
if (localeCode != null && localeCode.isNotEmpty) {
42+
localeCodes.add(localeCode);
43+
} else {
44+
logger.warn('Skipping file entry: missing or invalid "locale_code".');
45+
}
46+
}
47+
} on YamlException catch (e) {
48+
logger.err('Failed to parse localizely.yml: ${e.message}');
49+
return;
50+
} catch (e) {
51+
logger.err('Invalid structure in localizely.yml: $e');
52+
return;
53+
}
54+
55+
if (localeCodes.isEmpty) {
56+
logger.warn('No valid locale codes found to download.');
57+
return;
58+
}
3359

3460
logger.info('Downloading translations for: ${localeCodes.join(', ')}');
3561
final zipFiles = await httpClient.getTranslationFiles(applicationId);

0 commit comments

Comments
 (0)