From d20b69358f68ad3f1f652b7a1ab206e92d92642b Mon Sep 17 00:00:00 2001 From: JHubi1 Date: Sat, 25 May 2024 19:18:24 +0200 Subject: [PATCH] Added multilingual support --- l10n.yaml | 3 +++ lib/l10n/app_de.arb | 38 +++++++++++++++++++++++++++++++++++ lib/l10n/app_en.arb | 38 +++++++++++++++++++++++++++++++++++ lib/main.dart | 49 +++++++++++++++++++++++++++++---------------- pubspec.lock | 11 +++++++--- pubspec.yaml | 4 ++++ 6 files changed, 123 insertions(+), 20 deletions(-) create mode 100644 l10n.yaml create mode 100644 lib/l10n/app_de.arb create mode 100644 lib/l10n/app_en.arb diff --git a/l10n.yaml b/l10n.yaml new file mode 100644 index 0000000..15338f2 --- /dev/null +++ b/l10n.yaml @@ -0,0 +1,3 @@ +arb-dir: lib/l10n +template-arb-file: app_en.arb +output-localization-file: app_localizations.dart diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb new file mode 100644 index 0000000..1ce9c13 --- /dev/null +++ b/lib/l10n/app_de.arb @@ -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": "", + "@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" + } +} \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb new file mode 100644 index 0000000..a195c5b --- /dev/null +++ b/lib/l10n/app_en.arb @@ -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": "", + "@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" + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 3e15d27..0cee4a5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_chat_types/flutter_chat_types.dart' as types; import 'package:flutter_chat_ui/flutter_chat_ui.dart'; @@ -97,7 +99,12 @@ class _AppState extends State { @override Widget build(BuildContext context) { 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 { splashFactory: NoSplash.splashFactory, highlightColor: Colors.transparent, enableFeedback: false, - child: const SizedBox( + child: SizedBox( height: 72, child: Row( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, children: [ Flexible( - child: Text("", + child: Text( + AppLocalizations.of(context)!.noSelectedModel, overflow: TextOverflow.fade, - style: TextStyle( + style: const TextStyle( fontFamily: "monospace", fontSize: 16))), - SizedBox(width: 4), - Icon(Icons.expand_more_rounded) + const SizedBox(width: 4), + const Icon(Icons.expand_more_rounded) ]))), actions: [ IconButton( @@ -245,7 +253,9 @@ class _MainAppState extends State { HapticFeedback.selectionClick(); }, icon: const Icon(Icons.image_rounded), - label: const Text("Upload Image"))), + label: Text( + AppLocalizations.of(context)! + .uploadImage))), const SizedBox(height: 8), SizedBox( width: double.infinity, @@ -279,11 +289,15 @@ class _MainAppState extends State { }, icon: const Icon( 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( keyboardType: TextInputType.text, sendButtonVisibilityMode: SendButtonVisibilityMode.always), @@ -315,8 +329,7 @@ class _MainAppState extends State { ? 0 : 8)) : DarkChatTheme( - backgroundColor: - (themeDark ?? ThemeData.dark()).colorScheme.background, + backgroundColor: (themeDark ?? ThemeData.dark()).colorScheme.background, primaryColor: (themeDark ?? ThemeData.dark()).colorScheme.primary.withAlpha(40), attachmentButtonIcon: const Icon(Icons.file_upload_rounded), sendButtonIcon: const Icon(Icons.send_rounded), @@ -341,16 +354,18 @@ class _MainAppState extends State { } }, selectedIndex: 1, - children: const [ + children: [ NavigationDrawerDestination( - icon: ImageIcon(AssetImage("assets/logo512.png")), - label: Text("Ollama"), + icon: const ImageIcon(AssetImage("assets/logo512.png")), + label: Text(AppLocalizations.of(context)!.appTitle), ), - Divider(), + const Divider(), NavigationDrawerDestination( - icon: Icon(Icons.add_rounded), label: Text("New Chat")), + icon: const Icon(Icons.add_rounded), + label: Text(AppLocalizations.of(context)!.optionNewChat)), NavigationDrawerDestination( - icon: Icon(Icons.settings_rounded), label: Text("Settings")) + icon: const Icon(Icons.settings_rounded), + label: Text(AppLocalizations.of(context)!.optionSettings)) ])); } } diff --git a/pubspec.lock b/pubspec.lock index 9bde1de..77cd177 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -206,6 +206,11 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.2" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_parsed_text: dependency: transitive description: @@ -321,13 +326,13 @@ packages: source: hosted version: "0.2.1+1" intl: - dependency: transitive + dependency: "direct main" description: name: intl - sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" url: "https://pub.dev" source: hosted - version: "0.19.0" + version: "0.18.1" json_annotation: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 17454bf..cdc081f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,6 +16,9 @@ dependencies: image_picker: ^1.1.1 file_picker: ^8.0.3 visibility_detector: ^0.4.0+2 + flutter_localizations: + sdk: flutter + intl: any dev_dependencies: flutter_test: @@ -24,5 +27,6 @@ dev_dependencies: flutter: uses-material-design: true + generate: true assets: - assets/logo512.png