Add intl support

This commit is contained in:
stonegate 2020-05-09 12:27:05 +08:00
parent 40e2d880b5
commit 974dd30448
6 changed files with 168 additions and 12 deletions

View File

@ -0,0 +1,63 @@
// 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.
// Ignore issues from commonly used lints in this file.
// ignore_for_file:implementation_imports, file_names, unnecessary_new
// ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering
// ignore_for_file:argument_type_not_assignable, invalid_assignment
// ignore_for_file:prefer_single_quotes, prefer_generic_function_type_aliases
// ignore_for_file:comment_references
import 'dart:async';
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
import 'package:intl/src/intl_helpers.dart';
import 'messages_en.dart' as messages_en;
typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'en': () => new Future.value(null),
};
MessageLookupByLibrary _findExact(String localeName) {
switch (localeName) {
case 'en':
return messages_en.messages;
default:
return null;
}
}
/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) async {
var availableLocale = Intl.verifiedLocale(
localeName,
(locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return new Future.value(false);
}
var lib = _deferredLibraries[availableLocale];
await (lib == null ? new Future.value(false) : lib());
initializeInternalMessageLookup(() => new CompositeMessageLookup());
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
return new Future.value(true);
}
bool _messagesExistFor(String locale) {
try {
return _findExact(locale) != null;
} catch (e) {
return false;
}
}
MessageLookupByLibrary _findGeneratedMessagesFor(String locale) {
var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor,
onFailure: (_) => null);
if (actualLocale == null) return null;
return _findExact(actualLocale);
}

View File

@ -0,0 +1,26 @@
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
// This is a library that provides messages for a en locale. All the
// messages from the main program should be duplicated here with the same
// function name.
// Ignore issues from commonly used lints in this file.
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = new MessageLookup();
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';
final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
};
}

59
lib/generated/l10n.dart Normal file
View File

@ -0,0 +1,59 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'intl/messages_all.dart';
// **************************************************************************
// Generator: Flutter Intl IDE plugin
// Made by Localizely
// **************************************************************************
class S {
S();
static const AppLocalizationDelegate delegate =
AppLocalizationDelegate();
static Future<S> load(Locale locale) {
final String name = (locale.countryCode?.isEmpty ?? false) ? locale.languageCode : locale.toString();
final String localeName = Intl.canonicalizedLocale(name);
return initializeMessages(localeName).then((_) {
Intl.defaultLocale = localeName;
return S();
});
}
static S of(BuildContext context) {
return Localizations.of<S>(context, S);
}
}
class AppLocalizationDelegate extends LocalizationsDelegate<S> {
const AppLocalizationDelegate();
List<Locale> get supportedLocales {
return const <Locale>[
Locale.fromSubtags(languageCode: 'en'),
];
}
@override
bool isSupported(Locale locale) => _isSupported(locale);
@override
Future<S> load(Locale locale) => S.load(locale);
@override
bool shouldReload(AppLocalizationDelegate old) => false;
bool _isSupported(Locale locale) {
if (locale != null) {
for (Locale supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale.languageCode) {
return true;
}
}
}
return false;
}
}

1
lib/l10n/intl_en.arb Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter/services.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'generated/l10n.dart';
import 'state/podcast_group.dart';
import 'state/audiostate.dart';
import 'state/settingstate.dart';
@ -52,9 +54,8 @@ class MyApp extends StatelessWidget {
debugShowCheckedModeBanner: false,
title: 'Tsacdop',
theme: lightTheme.copyWith(
accentColor: setting.accentSetColor,
toggleableActiveColor: setting.accentSetColor
),
accentColor: setting.accentSetColor,
toggleableActiveColor: setting.accentSetColor),
darkTheme: ThemeData.dark().copyWith(
accentColor: setting.accentSetColor,
primaryColorDark: Colors.grey[800],
@ -64,6 +65,13 @@ class MyApp extends StatelessWidget {
.copyWith(color: setting.realDark ? Colors.black87 : null),
appBarTheme: AppBarTheme(elevation: 0),
),
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
home: setting.showIntro ? SlideIntro(goto: Goto.home) : Home(),
);
},

View File

@ -15,9 +15,11 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_localizations:
sdk: flutter
json_annotation: ^3.0.1
sqflite: ^1.3.0
flutter_html: ^0.11.1
sqflite: ^1.3.0
flutter_html: ^0.11.1
path_provider: ^1.6.7
color_thief_flutter: ^1.0.2
provider: ^4.1.0
@ -45,16 +47,15 @@ dev_dependencies:
connectivity: ^0.4.8+2
flare_flutter: ^2.0.3
rxdart: ^0.24.0
auto_animated: ^2.0.2
auto_animated: ^2.0.2
just_audio:
git:
url: https://github.com/stonega/just_audio.git
url: https://github.com/stonega/just_audio.git
line_icons:
git:
url: https://github.com/galonsos/line_icons.git
dependency_overrides:
flutter_isolate: '1.0.0+11'
flutter:
assets:
@ -63,18 +64,14 @@ flutter:
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
@ -94,3 +91,5 @@ flutter:
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages
flutter_intl:
enabled: true