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 =
48 _rtlLanguages.contains(language) ? 'TextDirection.rtl' : 'TextDirection.ltr';
49 return '''
50 /// Create an instance of the translation bundle for ${describeLocale(localeName)}.
51 ///
52 /// For details on the meaning of the arguments, see [GlobalWidgetsLocalizations].
53 const WidgetsLocalization${locale.camelCase()}() : super($textDirection);''';
54}
55
56/// Returns the source of the constructor for a GlobalWidgetsLocalizations
57/// subclass.
58String generateWidgetsConstructorForCountrySubclass(LocaleInfo locale) {
59 final String localeName = locale.originalString;
60 return '''
61 /// Create an instance of the translation bundle for ${describeLocale(localeName)}.
62 ///
63 /// For details on the meaning of the arguments, see [GlobalWidgetsLocalizations].
64 const WidgetsLocalization${locale.camelCase()}();''';
65}
66
67const String widgetsFactoryName = 'getWidgetsTranslation';
68
69const String widgetsFactoryDeclaration = '''
70GlobalWidgetsLocalizations? getWidgetsTranslation(
71 Locale locale,
72) {''';
73
74const String widgetsFactoryArguments = '';
75
76const String widgetsSupportedLanguagesConstant = 'kWidgetsSupportedLanguages';
77
78const String widgetsSupportedLanguagesDocMacro = 'flutter.localizations.widgets.languages';
79

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com