Search code examples
flutterdartlocalization

intl localization generating empty arb template


I'm using intl in flutter localization and I've created AppLocalization class as follows:

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../l10n/messages_all.dart';

class AppLocalization {
  static Future<AppLocalization> load(Locale locale) {
    final String name =
        locale.countryCode.isEmpty ? locale.languageCode : locale.toString();
    final String localeName = Intl.canonicalizedLocale(name);
    return initializeMessages(localeName).then((_) {
      Intl.defaultLocale = localeName;
      return AppLocalization();
    });
  }

  static AppLocalization of(BuildContext context) {
    return Localizations.of<AppLocalization>(context, AppLocalization);
  }

  // list of locales
  String get hello {
    return Intl.message('Hello',
        name: 'hello', desc: "Simple word for greeting ");
  }

}

class AppLocalizationDelegate extends LocalizationsDelegate<AppLocalization> {
  final Locale overriddenLocale;

  const AppLocalizationDelegate(this.overriddenLocale);

  @override
  bool isSupported(Locale locale) => ['en', 'ar'].contains(locale.languageCode);

  @override
  Future<AppLocalization> load(Locale locale) => AppLocalization.load(locale);

  @override
  bool shouldReload(LocalizationsDelegate<AppLocalization> old) => false;
}

then running this command to generate intl_messages.arb template

flutter pub run intl_translation:extract_to_arb --output-dir=lib/l10n 

lib/locale/app_localization.dart

it sometimes generates intl_messages.arb successfully with this format

{
  
  "@@last_modified": "2020-12-02T09:23:59.737528",
  "hello": "Hello",
  "@hello": {
    "description": "Simple word for greeting ",
    "type": "text",
    "placeholders": {}
  }
}

and many times generate empty template with last_modified field only without any errors in terminal what is the problem?


Solution

  • this command is working well although it has the same keyword

    flutter pub run intl_translation:extract_to_arb --output-dir=lib/l10n lib/locale/app_localization.dart
    

    I think because this one doesn't have a new line CR and LF symbols that generated automatically in notepad I've used notepad++ and show end line symbols to compare between two commands