l10n: Basic setup with en language

This commit is contained in:
Neeraj Gupta 2021-08-16 01:05:16 +05:30
parent 44464d8c85
commit def66ee3cc
11 changed files with 194 additions and 5 deletions

3
l10n.yaml Normal file
View file

@ -0,0 +1,3 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart

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> {
};
}

67
lib/generated/l10n.dart Normal file
View file

@ -0,0 +1,67 @@
// 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
// **************************************************************************
// ignore_for_file: non_constant_identifier_names, lines_longer_than_80_chars
// ignore_for_file: join_return_with_assignment, prefer_final_in_for_each
// ignore_for_file: avoid_redundant_argument_values
class S {
S();
static S current;
static const AppLocalizationDelegate delegate =
AppLocalizationDelegate();
static Future<S> load(Locale locale) {
final name = (locale.countryCode?.isEmpty ?? false) ? locale.languageCode : locale.toString();
final localeName = Intl.canonicalizedLocale(name);
return initializeMessages(localeName).then((_) {
Intl.defaultLocale = localeName;
S.current = S();
return S.current;
});
}
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 (var supportedLocale in supportedLocales) {
if (supportedLocale.languageCode == locale.languageCode) {
return true;
}
}
}
return false;
}
}

7
lib/l10n/app_en.arb Normal file
View file

@ -0,0 +1,7 @@
{
"sign_up": "sign up",
"@sign_up": {
"description": "Text on the sign up button used during registration"
},
"log_in": "log in"
}

7
lib/l10n/l10n.dart Normal file
View file

@ -0,0 +1,7 @@
import 'dart:ui';
class L10n {
static final all = [
const Locale('en'),
];
}

View file

@ -4,6 +4,7 @@ import 'package:background_fetch/background_fetch.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart';
@ -27,6 +28,9 @@ import 'package:photos/utils/crypto_util.dart';
import 'package:photos/utils/file_uploader.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:super_logging/super_logging.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'l10n/l10n.dart';
final _logger = Logger("main");
@ -241,6 +245,13 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
home: EnteApp._homeWidget,
debugShowCheckedModeBanner: false,
builder: EasyLoading.init(),
supportedLocales: L10n.all,
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
);
}

View file

@ -15,6 +15,7 @@ import 'package:photos/ui/web_page.dart';
import 'package:photos/utils/data_util.dart';
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/email_util.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class EmailEntryPage extends StatefulWidget {
EmailEntryPage({Key key}) : super(key: key);
@ -65,7 +66,7 @@ class _EmailEntryPageState extends State<EmailEntryPage> {
child: Material(
type: MaterialType.transparency,
child: Text(
"sign up",
AppLocalizations.of(context).sign_up,
style: TextStyle(
fontSize: 18,
letterSpacing: 0.6,

View file

@ -8,6 +8,8 @@ import 'package:photos/ui/password_entry_page.dart';
import 'package:photos/ui/password_reentry_page.dart';
import 'package:photos/ui/payment/subscription.dart';
import 'package:photos/ui/payment/subscription_page.dart';
import 'package:photos/ui/subscription_page.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class LandingPageWidget extends StatefulWidget {
const LandingPageWidget({Key key}) : super(key: key);
@ -110,7 +112,7 @@ class _LandingPageWidgetState extends State<LandingPageWidget> {
child: Material(
type: MaterialType.transparency,
child: Text(
"log in",
AppLocalizations.of(context).log_in,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,

View file

@ -8,6 +8,7 @@ import 'package:photos/ui/common_elements.dart';
import 'package:photos/ui/web_page.dart';
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/email_util.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class LoginPage extends StatefulWidget {
LoginPage({Key key}) : super(key: key);
@ -35,7 +36,7 @@ class _LoginPageState extends State<LoginPage> {
child: Material(
type: MaterialType.transparency,
child: Text(
"log in",
AppLocalizations.of(context).log_in,
style: TextStyle(
fontSize: 16,
letterSpacing: 0.6,
@ -137,7 +138,7 @@ class _LoginPageState extends State<LoginPage> {
height: 64,
padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
child: button(
"log in",
AppLocalizations.of(context).log_in,
onPressed: _email != null && _email.isNotEmpty
? () {
if (!isValidEmail(_email)) {

View file

@ -7,6 +7,7 @@ import 'package:photos/events/subscription_purchased_event.dart';
import 'package:photos/ui/common_elements.dart';
import 'package:photos/ui/recovery_page.dart';
import 'package:photos/utils/dialog_util.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class PasswordReentryPage extends StatefulWidget {
PasswordReentryPage({Key key}) : super(key: key);
@ -92,7 +93,7 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
width: double.infinity,
height: 64,
child: button(
"log in",
AppLocalizations.of(context).log_in,
fontSize: 18,
onPressed: _passwordController.text.isNotEmpty
? () async {