Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation feature for German to English and Vice-Viersa #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# PocketCode-IDE-Flutter
# Regarding German to English and vice-versa translation feature using Localization (l10n) library.
Points to follow :
1) The language map is created in the lib/l10n directory.
2) The language map for English (en) is intl_en.dart.
3) The language map for German (de) is intl_de.dart.
4) The language can be changed for now through the main.dart file by changing language code passed in the Locale class constructor of the locale parameter of the MaterialApp class constructor.
5) Whenever a new text is added in the app the developer will has to add the word with its translation and description in the language map files mentioned in points 2 and 3.
6) Use the command flutter gen-l10n to update or re-generate the localization files to use the newly added words.\
7) The translated word is used like this => S.of(context).<variable-name-in-map>
201 changes: 201 additions & 0 deletions lib/SignInPage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import 'package:catrobat_flutter/ui/shared/dialogs/SignInRegisterDialog.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/gestures.dart';
import 'package:sign_in_button/sign_in_button.dart';

class SignInPage extends StatefulWidget {
const SignInPage({super.key});

@override
State<SignInPage> createState() => _SignInPageState();
}

class _SignInPageState extends State<SignInPage> {
@override
Widget build(BuildContext context) {
bool signInIsChecked = false;
bool registerIsChecked = false;
bool testCondition = false; //TODO
Text titleSignIn = const Text('Einloggen', style: TextStyle(fontSize: 16));
Text titleRegister = const Text('Registrieren', style: TextStyle(fontSize: 16));
Column contentSignIn = Column(
children: [
TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Benutzername",
),
),
TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Passwort",
),
),
Align(
alignment: Alignment.centerLeft,
child: ListTile(
title: const Text("Passwort anzeigen"),
leading: Checkbox(
value: signInIsChecked,
onChanged: (value) => {
setState(() {
signInIsChecked = value!;
}),
},
),
),
),
],
);

Column contentRegister = Column(
children: [
TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Benutzername",
),
),
TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "E-Mail",
),
),
TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Passwort",
),
),
TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Passwort bestätigen",
),
),
Align(
alignment: Alignment.centerLeft,
child: ListTile(
title: const Text("Passwort anzeigen"),
leading: Checkbox(
value: registerIsChecked,
onChanged: (value) => {
setState(() {
registerIsChecked = value!;
}),
},
),
),
),
],
);

Column actionsSignIn = Column (
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: testCondition ? () {
Navigator.pop(context);
} : null,
child: const Align(
alignment: Alignment.centerRight,
child: Text('EINLOGGEN')
),
),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Align(
alignment: Alignment.centerRight,
child: Text('ABBRECHEN'),
),
),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Align(
alignment: Alignment.centerRight,
child: Text('PASSWORT ZURÜCKSETZEN'),
),
),
],
);

Column actionsRegister = Column (
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: testCondition ? () {
Navigator.pop(context);
} : null,
child: const Align(
alignment: Alignment.centerRight,
child: Text('REGISTRIEREN')
),
),
],
);

return Scaffold(
body: Center(
child: Column (
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton (

onPressed: () {
SignInRegisterDialog.signInRegisterDialog(context, titleSignIn, contentSignIn, actionsSignIn);
},
child: const Text('EINLOGGEN'),
),
TextButton (
onPressed: () {
SignInRegisterDialog.signInRegisterDialog(context, titleRegister, contentRegister, actionsRegister);
},
child: const Text('REGISTRIEREN'),
),

SignInButton(
Buttons.google,
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( //TODO open google login
content: Text("Google Button Pressed!"),
duration: Duration(milliseconds: 400),
),
);
}
),
const Text("Mit der Registrierung akzeptierst du unsere",
style: TextStyle(
color: Color.fromARGB(255, 0, 0, 0)
),
),
RichText(
text: TextSpan(
text: 'Nutzungsbedingungen und Leistungen',
//TODO: style
style: const TextStyle(
color: Color.fromARGB(255, 205, 116, 0),
),
recognizer: TapGestureRecognizer()..onTap = () async {
var url = Uri.parse("https://share.catrob.at/");
if (await launchUrl(url)) {
await launchUrl(url);
} else {
throw 'Could not launch $url';
}
},
)
),
],
),
),
);
}
}
67 changes: 67 additions & 0 deletions lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
// This is a library that looks up messages for specific locales by
// delegating to the appropriate library.

// Ignore issues from commonly used lints in this file.
// ignore_for_file:implementation_imports, file_names, unnecessary_new
// ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering
// ignore_for_file:argument_type_not_assignable, invalid_assignment
// ignore_for_file:prefer_single_quotes, prefer_generic_function_type_aliases
// ignore_for_file:comment_references

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
import 'package:intl/src/intl_helpers.dart';

import 'messages_de.dart' as messages_de;
import 'messages_en.dart' as messages_en;

typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'de': () => new SynchronousFuture(null),
'en': () => new SynchronousFuture(null),
};

MessageLookupByLibrary? _findExact(String localeName) {
switch (localeName) {
case 'de':
return messages_de.messages;
case 'en':
return messages_en.messages;
default:
return null;
}
}

/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) {
var availableLocale = Intl.verifiedLocale(
localeName, (locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return new SynchronousFuture(false);
}
var lib = _deferredLibraries[availableLocale];
lib == null ? new SynchronousFuture(false) : lib();
initializeInternalMessageLookup(() => new CompositeMessageLookup());
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
return new SynchronousFuture(true);
}

bool _messagesExistFor(String locale) {
try {
return _findExact(locale) != null;
} catch (e) {
return false;
}
}

MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) {
var actualLocale =
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
if (actualLocale == null) return null;
return _findExact(actualLocale);
}
39 changes: 39 additions & 0 deletions lib/generated/intl/messages_de.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
// This is a library that provides messages for a de locale. All the
// messages from the main program should be duplicated here with the same
// function name.

// Ignore issues from commonly used lints in this file.
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';

final messages = new MessageLookup();

typedef String MessageIfAbsent(String messageStr, List<dynamic> args);

class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'de';

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"cancel": MessageLookupByLibrary.simpleMessage("Abbrechen"),
"exampleproject":
MessageLookupByLibrary.simpleMessage("Beispielprojekt"),
"language": MessageLookupByLibrary.simpleMessage("German"),
"mainproject": MessageLookupByLibrary.simpleMessage("Mein Projekt"),
"mostdownloaded":
MessageLookupByLibrary.simpleMessage("Meist heruntergeladen"),
"ok": MessageLookupByLibrary.simpleMessage("OK"),
"projectname": MessageLookupByLibrary.simpleMessage("Projektname"),
"projectsonthedevice":
MessageLookupByLibrary.simpleMessage("Projekte am Gerät"),
"randomprojects":
MessageLookupByLibrary.simpleMessage("Zufällige Projekte")
};
}
39 changes: 39 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
// This is a library that provides messages for a en locale. All the
// messages from the main program should be duplicated here with the same
// function name.

// Ignore issues from commonly used lints in this file.
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';

final messages = new MessageLookup();

typedef String MessageIfAbsent(String messageStr, List<dynamic> args);

class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"cancel": MessageLookupByLibrary.simpleMessage("Cancel"),
"exampleproject":
MessageLookupByLibrary.simpleMessage("Example project"),
"language": MessageLookupByLibrary.simpleMessage("English"),
"mainproject": MessageLookupByLibrary.simpleMessage("Main Project"),
"mostdownloaded":
MessageLookupByLibrary.simpleMessage("Most downloaded"),
"ok": MessageLookupByLibrary.simpleMessage("OK"),
"projectname": MessageLookupByLibrary.simpleMessage("Project name"),
"projectsonthedevice":
MessageLookupByLibrary.simpleMessage("Projects on the device"),
"randomprojects":
MessageLookupByLibrary.simpleMessage("Random projects")
};
}
Loading