This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add about page builder and i18n
- Loading branch information
1 parent
329559f
commit c52cb6c
Showing
24 changed files
with
358 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
project_id: '595509' | ||
api_token: CROWDIN_PERSONAL_TOKEN | ||
base_path: . | ||
base_url: 'https://api.crowdin.com' | ||
preserve_hierarchy: 1 | ||
files: | ||
- source: /i18n/*.arb | ||
translation: /packages/libtokyo_flutter/lib/l10n/lib_%two_letters_code%.arb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export 'logic/change_notifier.dart'; | ||
export 'logic/color.dart'; | ||
export 'logic/feedback.dart'; | ||
export 'logic/navigator.dart'; | ||
export 'logic/state.dart'; | ||
export 'logic/theme.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
abstract class FeedbackId<BuildContext> { | ||
const FeedbackId({ | ||
required this.key, | ||
required this.onGenerateTitle, | ||
}); | ||
|
||
final String key; | ||
final String Function(BuildContext context) onGenerateTitle; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:meta/meta.dart'; | ||
import 'package:pubspec/pubspec.dart'; | ||
|
||
@immutable | ||
abstract class AboutPageBuilder<Key, Widget extends Object> { | ||
const AboutPageBuilder({ | ||
this.key, | ||
required this.appTitle, | ||
required this.appDescription, | ||
required this.pubspec, | ||
}); | ||
|
||
final Key? key; | ||
final String appTitle; | ||
final String appDescription; | ||
final PubSpec pubspec; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ dev_dependencies: | |
dependencies: | ||
meta: 1.9.1 | ||
path: ^1.8.3 | ||
pubspec: ^2.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
arb-dir: lib/l10n | ||
template-arb-file: lib_en.arb | ||
output-localization-file: libtokyo_localizations.dart | ||
output-class: GlobalTokyoLocalizations | ||
output-dir: lib/l10n | ||
synthetic-package: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'l10n/libtokyo_localizations.dart'; | ||
export 'l10n/libtokyo_localizations_en.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
125 changes: 125 additions & 0 deletions
125
packages/libtokyo_flutter/lib/l10n/libtokyo_localizations.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_localizations/flutter_localizations.dart'; | ||
import 'package:intl/intl.dart' as intl; | ||
|
||
import 'libtokyo_localizations_en.dart'; | ||
|
||
/// Callers can lookup localized strings with an instance of GlobalTokyoLocalizations | ||
/// returned by `GlobalTokyoLocalizations.of(context)`. | ||
/// | ||
/// Applications need to include `GlobalTokyoLocalizations.delegate()` in their app's | ||
/// `localizationDelegates` list, and the locales they support in the app's | ||
/// `supportedLocales` list. For example: | ||
/// | ||
/// ```dart | ||
/// import 'l10n/libtokyo_localizations.dart'; | ||
/// | ||
/// return MaterialApp( | ||
/// localizationsDelegates: GlobalTokyoLocalizations.localizationsDelegates, | ||
/// supportedLocales: GlobalTokyoLocalizations.supportedLocales, | ||
/// home: MyApplicationHome(), | ||
/// ); | ||
/// ``` | ||
/// | ||
/// ## Update pubspec.yaml | ||
/// | ||
/// Please make sure to update your pubspec.yaml to include the following | ||
/// packages: | ||
/// | ||
/// ```yaml | ||
/// dependencies: | ||
/// # Internationalization support. | ||
/// flutter_localizations: | ||
/// sdk: flutter | ||
/// intl: any # Use the pinned version from flutter_localizations | ||
/// | ||
/// # Rest of dependencies | ||
/// ``` | ||
/// | ||
/// ## iOS Applications | ||
/// | ||
/// iOS applications define key application metadata, including supported | ||
/// locales, in an Info.plist file that is built into the application bundle. | ||
/// To configure the locales supported by your app, you’ll need to edit this | ||
/// file. | ||
/// | ||
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file. | ||
/// Then, in the Project Navigator, open the Info.plist file under the Runner | ||
/// project’s Runner folder. | ||
/// | ||
/// Next, select the Information Property List item, select Add Item from the | ||
/// Editor menu, then select Localizations from the pop-up menu. | ||
/// | ||
/// Select and expand the newly-created Localizations item then, for each | ||
/// locale your application supports, add a new item and select the locale | ||
/// you wish to add from the pop-up menu in the Value field. This list should | ||
/// be consistent with the languages listed in the GlobalTokyoLocalizations.supportedLocales | ||
/// property. | ||
abstract class GlobalTokyoLocalizations { | ||
GlobalTokyoLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString()); | ||
|
||
final String localeName; | ||
|
||
static GlobalTokyoLocalizations? of(BuildContext context) { | ||
return Localizations.of<GlobalTokyoLocalizations>(context, GlobalTokyoLocalizations); | ||
} | ||
|
||
static const LocalizationsDelegate<GlobalTokyoLocalizations> delegate = _GlobalTokyoLocalizationsDelegate(); | ||
|
||
/// A list of this localizations delegate along with the default localizations | ||
/// delegates. | ||
/// | ||
/// Returns a list of localizations delegates containing this delegate along with | ||
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, | ||
/// and GlobalWidgetsLocalizations.delegate. | ||
/// | ||
/// Additional delegates can be added by appending to this list in | ||
/// MaterialApp. This list does not have to be used at all if a custom list | ||
/// of delegates is preferred or required. | ||
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[ | ||
delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
]; | ||
|
||
/// A list of this localizations delegate's supported locales. | ||
static const List<Locale> supportedLocales = <Locale>[ | ||
Locale('en') | ||
]; | ||
|
||
} | ||
|
||
class _GlobalTokyoLocalizationsDelegate extends LocalizationsDelegate<GlobalTokyoLocalizations> { | ||
const _GlobalTokyoLocalizationsDelegate(); | ||
|
||
@override | ||
Future<GlobalTokyoLocalizations> load(Locale locale) { | ||
return SynchronousFuture<GlobalTokyoLocalizations>(lookupGlobalTokyoLocalizations(locale)); | ||
} | ||
|
||
@override | ||
bool isSupported(Locale locale) => <String>['en'].contains(locale.languageCode); | ||
|
||
@override | ||
bool shouldReload(_GlobalTokyoLocalizationsDelegate old) => false; | ||
} | ||
|
||
GlobalTokyoLocalizations lookupGlobalTokyoLocalizations(Locale locale) { | ||
|
||
|
||
// Lookup logic when only language code is specified. | ||
switch (locale.languageCode) { | ||
case 'en': return GlobalTokyoLocalizationsEn(); | ||
} | ||
|
||
throw FlutterError( | ||
'GlobalTokyoLocalizations.delegate failed to load unsupported locale "$locale". This is likely ' | ||
'an issue with the localizations generation tool. Please file an issue ' | ||
'on GitHub with a reproducible sample app and the gen-l10n configuration ' | ||
'that was used.' | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/libtokyo_flutter/lib/l10n/libtokyo_localizations_en.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'libtokyo_localizations.dart'; | ||
|
||
/// The translations for English (`en`). | ||
class GlobalTokyoLocalizationsEn extends GlobalTokyoLocalizations { | ||
GlobalTokyoLocalizationsEn([String locale = 'en']) : super(locale); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
library libtokyo_flutter; | ||
|
||
export 'package:flutter/widgets.dart'; | ||
export 'package:libtokyo/libtokyo.dart' show ColorScheme, ThemeData, Color, FeedbackId; | ||
export 'package:flutter/widgets.dart' hide Color; | ||
export 'package:libtokyo_flutter/l10n.dart'; | ||
export 'package:libtokyo_flutter/widgets.dart'; | ||
export 'package:libtokyo_flutter/logic.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export 'logic/color.dart'; | ||
export 'logic/theme.dart'; | ||
export 'logic/settings.dart'; | ||
export 'logic/theme.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
abstract class Settings<T> { | ||
const Settings(this.defaultValue); | ||
|
||
String get name; | ||
final T defaultValue; | ||
T valueFor(SharedPreferences prefs) => (prefs.get(name) as T?) ?? defaultValue; | ||
Future<T> get value async => valueFor(await SharedPreferences.getInstance()); | ||
|
||
@override | ||
toString() => '$name:${T.toString()}'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.