flutter-web-admin icon indicating copy to clipboard operation
flutter-web-admin copied to clipboard

Generate translations

Open zikriirfandi opened this issue 1 year ago • 0 comments

Hi, I am trying to change translation by using

dart run intl_utils:generate

I have already define l10n.yaml in root folder

arb-dir: lib/l10n
template-arb-file: intl_en.arb
output-dir: lib/generated/intl
output-localization-file: l10n.dart  # Change the output file
class-name: Lang  # Specify the custom class name

but unfortenately, the generated code give error, because of class-name issue in l10n.dart

class S {
  S();

  static S? _current;

  static S get current {
    assert(_current != null,
        'No instance of S was loaded. Try to initialize the S delegate before accessing S.current.');
    return _current!;
  }

  static const AppLocalizationDelegate delegate = AppLocalizationDelegate();

  static Future<S> load(Locale locale) {
    final name = (locale.countryCode?.isEmpty ?? false)
        ? locale.languageCode
        : locale.toString();
    final localeName = Intl.canonicalizedLocale(name);
    return initializeMessages(localeName).then((_) {
      Intl.defaultLocale = localeName;
      final instance = S();
      S._current = instance;

      return instance;
    });
  }

  static S of(BuildContext context) {
    final instance = S.maybeOf(context);
    assert(instance != null,
        'No instance of S present in the widget tree. Did you add S.delegate in localizationsDelegates?');
    return instance!;
  }

  static S? maybeOf(BuildContext context) {
    return Localizations.of<S>(context, S);
  }

the class name should Lang

Could you tell me, the correct way to generate translation?

zikriirfandi avatar Aug 26 '24 04:08 zikriirfandi