1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'localizations_utils.dart';
6
7// See http://en.wikipedia.org/wiki/Right-to-left
8const List<String> _rtlLanguages = <String>[
9 'ar', // Arabic
10 'fa', // Farsi
11 'he', // Hebrew
12 'ps', // Pashto
13 'ur', // Urdu
14];
15
16String generateWidgetsHeader(String regenerateInstructions) {
17 return '''
18// Copyright 2014 The Flutter Authors. All rights reserved.
19// Use of this source code is governed by a BSD-style license that can be
20// found in the LICENSE file.
21
22// This file has been automatically generated. Please do not edit it manually.
23// To regenerate the file, use:
24// $regenerateInstructions
25
26import 'dart:collection';
27import 'dart:ui';
28
29import '../widgets_localizations.dart';
30
31// The classes defined here encode all of the translations found in the
32// `flutter_localizations/lib/src/l10n/*.arb` files.
33//
34// These classes are constructed by the [getWidgetsTranslation] method at the
35// bottom of this file, and used by the [_WidgetsLocalizationsDelegate.load]
36// method defined in `flutter_localizations/lib/src/widgets_localizations.dart`.
37
38// TODO(goderbauer): Extend the generator to properly format the output.
39// dart format off''';
40}
41
42/// Returns the source of the constructor for a GlobalWidgetsLocalizations
43/// subclass.
44String generateWidgetsConstructor(LocaleInfo locale) {
45 final String localeName = locale.originalString;
46 final String language = locale.languageCode.toLowerCase();
47 final String textDirection = _rtlLanguages.contains(language)
48 ? 'TextDirection.rtl'
49 : 'TextDirection.ltr';
50 return '''
51 /// Create an instance of the translation bundle for ${describeLocale(localeName)}.
52 ///
53 /// For details on the meaning of the arguments, see [GlobalWidgetsLocalizations].
54 const WidgetsLocalization${locale.camelCase()}() : super($textDirection);''';
55}
56
57/// Returns the source of the constructor for a GlobalWidgetsLocalizations
58/// subclass.
59String generateWidgetsConstructorForCountrySubclass(LocaleInfo locale) {
60 final String localeName = locale.originalString;
61 return '''
62 /// Create an instance of the translation bundle for ${describeLocale(localeName)}.
63 ///
64 /// For details on the meaning of the arguments, see [GlobalWidgetsLocalizations].
65 const WidgetsLocalization${locale.camelCase()}();''';
66}
67
68const String widgetsFactoryName = 'getWidgetsTranslation';
69
70const String widgetsFactoryDeclaration = '''
71GlobalWidgetsLocalizations? getWidgetsTranslation(
72 Locale locale,
73) {''';
74
75const String widgetsFactoryArguments = '';
76
77const String widgetsSupportedLanguagesConstant = 'kWidgetsSupportedLanguages';
78
79const String widgetsSupportedLanguagesDocMacro = 'flutter.localizations.widgets.languages';
80