flutterPrologue property

String get flutterPrologue

Constant string used in generateFlutterImportFile for the beginning of the file.

Implementation

String get flutterPrologue => """
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
// This is a library that looks up messages for specific locales by
// delegating to the appropriate library.
// @dart=2.12
import 'dart:convert';

import 'package:$intlImportPath/intl.dart';
import 'package:$intlImportPath/message_lookup_by_library.dart';
import 'package:$intlImportPath/src/intl_helpers.dart';
import '$flutterImportPath/services.dart';

import '${generatedFilePrefix}messages_all.dart' show evaluateJsonTemplate;

class ResourceMessageLookup extends MessageLookupByLibrary {
ResourceMessageLookup(this.localeName, String messageText) {
  this.messages =
      const JsonDecoder().convert(messageText) as Map<String, dynamic>;
}
final String localeName;

String? evaluateMessage(dynamic translation, List<dynamic> args) {
  return evaluateJsonTemplate(translation, args);
}

late Map<String, dynamic> messages;
}

/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String? localeName) async {
if (localeName == null) {
  return false;
}

localeName = Intl.canonicalizedLocale(localeName);

initializeInternalMessageLookup(() => CompositeMessageLookup());

String? message;

// First, try to read the message from Android resource. Messages are split
// into chunks, so read until we reach an empty chunk.
var index = 0;
final chunks = <String>[];

while (true) {
  final chunk = await SystemChannels.localization
      .invokeMethod('Localization.getStringResource', {
    'key': 'flutter_localization_string\${index++}',
    'locale': localeName,
  }) as String?;

  // if the chunk is empty, we are reaching the end. Break out of the loop.
  if (chunk == null || chunk.isEmpty) {
    break;
  }

  // If the string in the Android resource is more than 32KB in size, it
  // will return "STRING_TOO_LARGE". Make sure to fail in this case.
  if (chunk == 'STRING_TOO_LARGE') {
    throw Exception('STRING_TOO_LARGE in flutter_localization_string\${index-1}');
  }

  chunks.add(chunk);
}

if (chunks.isNotEmpty) {
  message = chunks.join();
}

// If the translation does not exist in Android string resource, it is
// stored in the assets.
if (message == null) {
  try {
    // Normalize the locale name
    localeName = localeName.replaceAll('_', '-');
    message = await rootBundle
        .loadString('__flutter_localization/\${localeName}.json');
  } catch (_) {
    // Locale is not found, return false here to use the default locale.
    return false;
  }
}

if (message == null || message.isEmpty) {
  // On Android we include an empty string in the default locale resource,
  // otherwise loading all the other locales would fail. When we encounter an
  // empty string here, we treat it as locale not found. The intl package will
  // fallback to using the default locale.
  return false;
}

messageLookup.addLocale(
    localeName, (_) => ResourceMessageLookup(localeName!, message!));
return true;
}

""";