Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
chore: add about page builder and i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Jun 15, 2023
1 parent 329559f commit c52cb6c
Show file tree
Hide file tree
Showing 24 changed files with 358 additions and 8 deletions.
8 changes: 8 additions & 0 deletions crowdin.yaml
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
1 change: 1 addition & 0 deletions i18n/main.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/libtokyo/lib/logic.dart
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';
9 changes: 9 additions & 0 deletions packages/libtokyo/lib/logic/feedback.dart
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;
}
1 change: 1 addition & 0 deletions packages/libtokyo/lib/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'package:libtokyo/widgets/about_page_builder.dart';
export 'package:libtokyo/widgets/app.dart';
export 'package:libtokyo/widgets/basic_card.dart';
export 'package:libtokyo/widgets/file_browser.dart';
Expand Down
17 changes: 17 additions & 0 deletions packages/libtokyo/lib/widgets/about_page_builder.dart
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;
}
1 change: 1 addition & 0 deletions packages/libtokyo/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ dev_dependencies:
dependencies:
meta: 1.9.1
path: ^1.8.3
pubspec: ^2.3.0
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#include "generated_plugin_registrant.h"

#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) bitsdojo_window_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "BitsdojoWindowPlugin");
bitsdojo_window_plugin_register_with_registrar(bitsdojo_window_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
bitsdojo_window_linux
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import FlutterMacOS
import Foundation

import bitsdojo_window_macos
import shared_preferences_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
BitsdojoWindowPlugin.register(with: registry.registrar(forPlugin: "BitsdojoWindowPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#include "generated_plugin_registrant.h"

#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
BitsdojoWindowPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("BitsdojoWindowPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
bitsdojo_window_windows
url_launcher_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
6 changes: 6 additions & 0 deletions packages/libtokyo_flutter/l10n.yaml
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
2 changes: 2 additions & 0 deletions packages/libtokyo_flutter/lib/l10n.dart
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';
1 change: 1 addition & 0 deletions packages/libtokyo_flutter/lib/l10n/lib_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
125 changes: 125 additions & 0 deletions packages/libtokyo_flutter/lib/l10n/libtokyo_localizations.dart
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.'
);
}
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);


}
4 changes: 3 additions & 1 deletion packages/libtokyo_flutter/lib/libtokyo.dart
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';
3 changes: 2 additions & 1 deletion packages/libtokyo_flutter/lib/logic.dart
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';
13 changes: 13 additions & 0 deletions packages/libtokyo_flutter/lib/logic/settings.dart
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()}';
}
2 changes: 1 addition & 1 deletion packages/libtokyo_flutter/lib/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'package:flutter/material.dart' hide Scaffold, ColorScheme;
export 'package:flutter/material.dart' hide Scaffold, ColorScheme, ThemeData, Color;

export 'widgets/app.dart';
export 'widgets/basic_card.dart';
Expand Down
Loading

0 comments on commit c52cb6c

Please sign in to comment.