Skip to content

Commit f470de8

Browse files
authored
Admin UI: Localization support (#634)
* feat: support l10n * feat: add extension for easier l10n access * feat: add some simple translations
1 parent aed77da commit f470de8

File tree

9 files changed

+29
-14
lines changed

9 files changed

+29
-14
lines changed

AdminUi/apps/admin_ui/l10n.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
arb-dir: lib/l10n
2+
template-arb-file: app_en.arb
3+
output-localization-file: app_localizations.dart
4+
use-escaping: false

AdminUi/apps/admin_ui/lib/core/extensions.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
23
import 'package:get_it/get_it.dart';
34

45
import 'theme/theme.dart';
56

7+
extension AppLocalizationsExtension on BuildContext {
8+
AppLocalizations get l10n => AppLocalizations.of(this)!;
9+
}
10+
611
extension UnregisterIfRegistered on GetIt {
712
Future<void> unregisterIfRegistered<T extends Object>() async {
813
if (!isRegistered<T>()) return;

AdminUi/apps/admin_ui/lib/home/clients_overview/modals/change_client_secret_dialog.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class _ChangeClientSecretDialogState extends State<_ChangeClientSecretDialog> {
113113
),
114114
),
115115
actions: [
116-
OutlinedButton(onPressed: _saving ? null : () => context.pop(), child: Text(_saveSucceeded ? 'Close' : 'Cancel')),
117-
if (!_saveSucceeded) FilledButton(onPressed: _saving ? null : _changeClientSecret, child: const Text('Save')),
116+
OutlinedButton(onPressed: _saving ? null : () => context.pop(), child: Text(_saveSucceeded ? context.l10n.close : context.l10n.cancel)),
117+
if (!_saveSucceeded) FilledButton(onPressed: _saving ? null : _changeClientSecret, child: Text(context.l10n.save)),
118118
],
119119
),
120120
);

AdminUi/apps/admin_ui/lib/home/clients_overview/modals/create_client_dialog.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ class _CreateClientDialogState extends State<_CreateClientDialog> {
166166
),
167167
),
168168
actions: [
169-
OutlinedButton(onPressed: _saving ? null : () => context.pop(), child: Text(_saveSucceeded ? 'Close' : 'Cancel')),
169+
OutlinedButton(onPressed: _saving ? null : () => context.pop(), child: Text(_saveSucceeded ? context.l10n.close : context.l10n.cancel)),
170170
if (!_saveSucceeded)
171171
FilledButton(
172172
onPressed: _chosenDefaultTier != null && !_saveSucceeded && !_saving ? _createClient : null,
173-
child: const Text('Save'),
173+
child: Text(context.l10n.save),
174174
),
175175
],
176176
),

AdminUi/apps/admin_ui/lib/home/clients_overview/modals/remove_clients_dialog.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ class _RemoveClientsDialogState extends State<_RemoveClientsDialog> {
5050
actions: <Widget>[
5151
OutlinedButton(
5252
onPressed: _deleting ? null : () => context.pop(),
53-
child: Text(_deletionSucceeded ? 'Close' : 'Cancel'),
53+
child: Text(_deletionSucceeded ? context.l10n.close : context.l10n.cancel),
5454
),
5555
if (!_deletionSucceeded)
5656
TextButton(
5757
onPressed: _deleting ? null : _deleteSelectedClients,
58-
child: Text('Yes', style: TextStyle(color: Theme.of(context).colorScheme.error)),
58+
child: Text(context.l10n.yes, style: TextStyle(color: Theme.of(context).colorScheme.error)),
5959
),
6060
],
6161
),

AdminUi/apps/admin_ui/lib/home/tiers_overview/modals/show_create_tier_dialog.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _CreateTierDialogState extends State<_CreateTierDialog> {
8080
actions: <Widget>[
8181
OutlinedButton(
8282
onPressed: _isLoading ? null : () => context.pop(),
83-
child: const Text('Cancel'),
83+
child: Text(context.l10n.cancel),
8484
),
8585
FilledButton(
8686
onPressed: _isLoading ? null : () => _onSubmitted(_tierNameController.text),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"@@locale": "de"
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@@locale": "en",
3+
"cancel": "Cancel",
4+
"close": "Close",
5+
"save": "Save",
6+
"yes": "Yes"
7+
}

AdminUi/apps/admin_ui/lib/main.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter_localizations/flutter_localizations.dart';
2+
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
33
import 'package:get_it/get_it.dart';
44
import 'package:go_router/go_router.dart';
55
import 'package:logger/logger.dart';
@@ -82,12 +82,8 @@ class AdminUiApp extends StatelessWidget {
8282
),
8383
debugShowCheckedModeBanner: false,
8484
routerConfig: _router,
85-
supportedLocales: const [Locale('en'), Locale('de')],
86-
localizationsDelegates: const [
87-
GlobalMaterialLocalizations.delegate,
88-
GlobalWidgetsLocalizations.delegate,
89-
GlobalCupertinoLocalizations.delegate,
90-
],
85+
localizationsDelegates: AppLocalizations.localizationsDelegates,
86+
supportedLocales: AppLocalizations.supportedLocales,
9187
);
9288
}
9389
}

0 commit comments

Comments
 (0)