Skip to content

Commit

Permalink
Added multilingual support
Browse files Browse the repository at this point in the history
  • Loading branch information
JHubi1 committed May 25, 2024
1 parent 1f1ef19 commit d20b693
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 20 deletions.
3 changes: 3 additions & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
38 changes: 38 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
@@ -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 changes: 38 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -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"
}
}
49 changes: 32 additions & 17 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -97,7 +99,12 @@ class _AppState extends State<App> {
@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());
}
}

Expand Down Expand Up @@ -141,19 +148,20 @@ class _MainAppState extends State<MainApp> {
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("<none>",
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(
Expand Down Expand Up @@ -245,7 +253,9 @@ class _MainAppState extends State<MainApp> {
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,
Expand Down Expand Up @@ -279,11 +289,15 @@ class _MainAppState extends State<MainApp> {
},
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),
Expand Down Expand Up @@ -315,8 +329,7 @@ class _MainAppState extends State<MainApp> {
? 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),
Expand All @@ -341,16 +354,18 @@ class _MainAppState extends State<MainApp> {
}
},
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))
]));
}
}
11 changes: 8 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -24,5 +27,6 @@ dev_dependencies:

flutter:
uses-material-design: true
generate: true
assets:
- assets/logo512.png

0 comments on commit d20b693

Please sign in to comment.