slang-i18n / slang

Type-safe i18n for Dart and Flutter
https://pub.dev/packages/slang
MIT License
419 stars 36 forks source link

A modifier works like 'rich' in pure dart #215

Open andyzhshg opened 2 months ago

andyzhshg commented 2 months ago

Motivation

I'm working on a CLI tool that will generate some text files with style, much like generating HTML. When translating some fields using slang, I also hope to specify some sort of style on this field. It's very similar to how the rich modifier works in slang.

However, as the rich modifier relies on TextSpan, which is not available in pure Dart, I'm stuck here.

What I hope for is something like this, a class similar to TextSpan:

class CustomStyledSpan {
  CustomStyledSpan({this.text, this.style, this.children});
  final String? text;
  final Object? style;
  final List<CustomStyledSpan>? children;
}

and the builder can generate something like this:

mixin GeneratedClass {
  CustomStyledSpan? text({required CustomStyledSpan field});
}

Developer Experience

I think this feature would add more flexibility when using slang with pure Dart.

I'm looking into how to implement this feature myself and would really appreciate any guidance or advice anyone can provide.