Added multilingual support

This commit is contained in:
JHubi1 2024-05-25 19:18:24 +02:00
parent 1f1ef19743
commit d20b69358f
No known key found for this signature in database
GPG Key ID: 106B3E4BCE046A53
6 changed files with 123 additions and 20 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

38
lib/l10n/app_de.arb Normal file
View File

@ -0,0 +1,38 @@
{
"@@locale": "de",
"appTitle": "Ollama",
"@appTitle": {
"description": "Title of the application",
"context": "Visible in the side bar"
},
"optionSettings": "Einstellungen",
"@optionSettings": {
"description": "Text displayed for settings option",
"context": "Visible in the side bar"
},
"optionNewChat": "Neuer Chat",
"@optionNewChat": {
"description": "Text displayed for new chat option",
"context": "Visible in the side bar"
},
"noSelectedModel": "<selektor>",
"@noSelectedModel": {
"description": "Text displayed when no model is selected",
"context": "Visible in model selector, above the chat viewF"
},
"uploadImage": "Bild Hochladen",
"@uploadImage": {
"description": "Text displayed for image upload button",
"context": "Visible in attachment menu"
},
"uploadFile": "Datei Hochladen",
"@uploadFile": {
"description": "Text displayed for file upload button",
"context": "Visible in attachment menu"
},
"messageInputPlaceholder": "Nachricht",
"@messageInputPlaceholder": {
"description": "Placeholder text for message input",
"context": "Visible in the chat view"
}
}

38
lib/l10n/app_en.arb Normal file
View File

@ -0,0 +1,38 @@
{
"@@locale": "en",
"appTitle": "Ollama",
"@appTitle": {
"description": "Title of the application",
"context": "Visible in the side bar"
},
"optionSettings": "Settings",
"@optionSettings": {
"description": "Text displayed for settings option",
"context": "Visible in the side bar"
},
"optionNewChat": "New Chat",
"@optionNewChat": {
"description": "Text displayed for new chat option",
"context": "Visible in the side bar"
},
"noSelectedModel": "<selector>",
"@noSelectedModel": {
"description": "Text displayed when no model is selected",
"context": "Visible in model selector, above the chat viewF"
},
"uploadImage": "Upload Image",
"@uploadImage": {
"description": "Text displayed for image upload button",
"context": "Visible in attachment menu"
},
"uploadFile": "Upload File",
"@uploadFile": {
"description": "Text displayed for file upload button",
"context": "Visible in attachment menu"
},
"messageInputPlaceholder": "Message",
"@messageInputPlaceholder": {
"description": "Placeholder text for message input",
"context": "Visible in the chat view"
}
}

View File

@ -1,6 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_chat_types/flutter_chat_types.dart' as types; import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
import 'package:flutter_chat_ui/flutter_chat_ui.dart'; import 'package:flutter_chat_ui/flutter_chat_ui.dart';
@ -97,7 +99,12 @@ class _AppState extends State<App> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
theme: theme, darkTheme: themeDark, home: const MainApp()); localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
title: "Ollama",
theme: theme,
darkTheme: themeDark,
home: const MainApp());
} }
} }
@ -141,19 +148,20 @@ class _MainAppState extends State<MainApp> {
splashFactory: NoSplash.splashFactory, splashFactory: NoSplash.splashFactory,
highlightColor: Colors.transparent, highlightColor: Colors.transparent,
enableFeedback: false, enableFeedback: false,
child: const SizedBox( child: SizedBox(
height: 72, height: 72,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
Flexible( Flexible(
child: Text("<none>", child: Text(
AppLocalizations.of(context)!.noSelectedModel,
overflow: TextOverflow.fade, overflow: TextOverflow.fade,
style: TextStyle( style: const TextStyle(
fontFamily: "monospace", fontSize: 16))), fontFamily: "monospace", fontSize: 16))),
SizedBox(width: 4), const SizedBox(width: 4),
Icon(Icons.expand_more_rounded) const Icon(Icons.expand_more_rounded)
]))), ]))),
actions: [ actions: [
IconButton( IconButton(
@ -245,7 +253,9 @@ class _MainAppState extends State<MainApp> {
HapticFeedback.selectionClick(); HapticFeedback.selectionClick();
}, },
icon: const Icon(Icons.image_rounded), icon: const Icon(Icons.image_rounded),
label: const Text("Upload Image"))), label: Text(
AppLocalizations.of(context)!
.uploadImage))),
const SizedBox(height: 8), const SizedBox(height: 8),
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
@ -279,11 +289,15 @@ class _MainAppState extends State<MainApp> {
}, },
icon: const Icon( icon: const Icon(
Icons.file_copy_rounded), Icons.file_copy_rounded),
label: const Text("Upload File"))) label: Text(
AppLocalizations.of(context)!
.uploadFile)))
])); ]));
}); });
}, },
l10n: const ChatL10nEn(), l10n: ChatL10nEn(
inputPlaceholder:
AppLocalizations.of(context)!.messageInputPlaceholder),
inputOptions: const InputOptions( inputOptions: const InputOptions(
keyboardType: TextInputType.text, keyboardType: TextInputType.text,
sendButtonVisibilityMode: SendButtonVisibilityMode.always), sendButtonVisibilityMode: SendButtonVisibilityMode.always),
@ -315,8 +329,7 @@ class _MainAppState extends State<MainApp> {
? 0 ? 0
: 8)) : 8))
: DarkChatTheme( : DarkChatTheme(
backgroundColor: backgroundColor: (themeDark ?? ThemeData.dark()).colorScheme.background,
(themeDark ?? ThemeData.dark()).colorScheme.background,
primaryColor: (themeDark ?? ThemeData.dark()).colorScheme.primary.withAlpha(40), primaryColor: (themeDark ?? ThemeData.dark()).colorScheme.primary.withAlpha(40),
attachmentButtonIcon: const Icon(Icons.file_upload_rounded), attachmentButtonIcon: const Icon(Icons.file_upload_rounded),
sendButtonIcon: const Icon(Icons.send_rounded), sendButtonIcon: const Icon(Icons.send_rounded),
@ -341,16 +354,18 @@ class _MainAppState extends State<MainApp> {
} }
}, },
selectedIndex: 1, selectedIndex: 1,
children: const [ children: [
NavigationDrawerDestination( NavigationDrawerDestination(
icon: ImageIcon(AssetImage("assets/logo512.png")), icon: const ImageIcon(AssetImage("assets/logo512.png")),
label: Text("Ollama"), label: Text(AppLocalizations.of(context)!.appTitle),
), ),
Divider(), const Divider(),
NavigationDrawerDestination( NavigationDrawerDestination(
icon: Icon(Icons.add_rounded), label: Text("New Chat")), icon: const Icon(Icons.add_rounded),
label: Text(AppLocalizations.of(context)!.optionNewChat)),
NavigationDrawerDestination( NavigationDrawerDestination(
icon: Icon(Icons.settings_rounded), label: Text("Settings")) icon: const Icon(Icons.settings_rounded),
label: Text(AppLocalizations.of(context)!.optionSettings))
])); ]));
} }
} }

View File

@ -206,6 +206,11 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.0.2" version: "3.0.2"
flutter_localizations:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_parsed_text: flutter_parsed_text:
dependency: transitive dependency: transitive
description: description:
@ -321,13 +326,13 @@ packages:
source: hosted source: hosted
version: "0.2.1+1" version: "0.2.1+1"
intl: intl:
dependency: transitive dependency: "direct main"
description: description:
name: intl name: intl
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.19.0" version: "0.18.1"
json_annotation: json_annotation:
dependency: transitive dependency: transitive
description: description:

View File

@ -16,6 +16,9 @@ dependencies:
image_picker: ^1.1.1 image_picker: ^1.1.1
file_picker: ^8.0.3 file_picker: ^8.0.3
visibility_detector: ^0.4.0+2 visibility_detector: ^0.4.0+2
flutter_localizations:
sdk: flutter
intl: any
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
@ -24,5 +27,6 @@ dev_dependencies:
flutter: flutter:
uses-material-design: true uses-material-design: true
generate: true
assets: assets:
- assets/logo512.png - assets/logo512.png