Skip to content

Commit

Permalink
refactor: TranslationModelBuilder should return PopulatedContextType
Browse files Browse the repository at this point in the history
  • Loading branch information
Tienisto committed Jan 21, 2024
1 parent 4bc9509 commit a1cbe1e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
10 changes: 2 additions & 8 deletions slang/lib/builder/builder/generate_config_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GenerateConfigBuilder {
required String baseName,
required RawConfig config,
required String inputDirectoryHint,
required List<ContextType> contexts,
required List<PopulatedContextType> contexts,
required List<Interface> interfaces,
}) {
return GenerateConfig(
Expand All @@ -31,13 +31,7 @@ class GenerateConfigBuilder {
translationOverrides: config.translationOverrides,
renderTimestamp: config.renderTimestamp,
renderStatistics: config.renderStatistics,
contexts: contexts.map((c) {
return PopulatedContextType(
enumName: c.enumName,
enumValues: c.enumValues!,
generateEnum: c.generateEnum,
);
}).toList(),
contexts: contexts,
interface: interfaces,
obfuscation: config.obfuscation,
imports: config.imports,
Expand Down
12 changes: 9 additions & 3 deletions slang/lib/builder/builder/translation_model_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:slang/builder/utils/string_extensions.dart';
class BuildModelResult {
final ObjectNode root; // the actual strings
final List<Interface> interfaces; // detected interfaces
final List<ContextType> contexts; // detected context types
final List<PopulatedContextType> contexts; // detected context types

BuildModelResult({
required this.root,
Expand Down Expand Up @@ -190,8 +190,14 @@ class TranslationModelBuilder {
return BuildModelResult(
root: root,
interfaces: interfaceCollection.resultInterfaces.values.toList(),
contexts:
contextCollection.values.where((c) => c.enumValues != null).toList(),
contexts: contextCollection.values
.where((c) => c.enumValues != null)
.map((c) => PopulatedContextType(
enumName: c.enumName,
enumValues: c.enumValues!,
generateEnum: c.generateEnum,
))
.toList(),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion slang/lib/builder/generator_facade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GeneratorFacade {
// combine all contexts of all locales
// if one context appears on more than one locale, then the context of
// the base locale will have precedence
final contextMap = <String, ContextType>{};
final contextMap = <String, PopulatedContextType>{};
for (final locale in translationModelList) {
for (final context in locale.contexts) {
if (!contextMap.containsKey(context.enumName)) {
Expand Down
2 changes: 1 addition & 1 deletion slang/lib/builder/model/i18n_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class I18nData {
final bool base; // whether or not this is the base locale
final I18nLocale locale; // the locale (the part after the underscore)
final ObjectNode root; // the actual strings
final List<ContextType> contexts; // detected context types
final List<PopulatedContextType> contexts; // detected context types
final List<Interface> interfaces; // detected interfaces

I18nData({
Expand Down

0 comments on commit a1cbe1e

Please sign in to comment.