-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Multi-Language Support and enabled arabic and english with arab…
…ic fonts.
- Loading branch information
1 parent
d4298b0
commit 7fcd556
Showing
12 changed files
with
119 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"NEW_ARRIVALS": "القادمون الجدد" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"NEW_ARRIVALS": "New Arrivals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_scaffold/localizations_delegate.dart'; | ||
|
||
class AppLocalizations { | ||
final Locale locale; | ||
|
||
AppLocalizations(this.locale); | ||
|
||
// Helper method to keep the code in the widgets concise | ||
// Localizations are accessed using an InheritedWidget "of" syntax | ||
static AppLocalizations of(BuildContext context) { | ||
return Localizations.of<AppLocalizations>(context, AppLocalizations); | ||
} | ||
|
||
// Static member to have a simple access to the delegate from the MaterialApp | ||
static const LocalizationsDelegate<AppLocalizations> delegate = | ||
AppLocalizationsDelegate(); | ||
|
||
Map<String, String> _localizedStrings; | ||
|
||
Future<bool> load() async { | ||
// Load the language JSON file from the "lang" folder | ||
String jsonString = | ||
await rootBundle.loadString('assets/i18n/${locale.languageCode}.json'); | ||
Map<String, dynamic> jsonMap = jsonDecode(jsonString); | ||
|
||
_localizedStrings = jsonMap.map((key, value) { | ||
return MapEntry(key, value.toString()); | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
// This method will be called from every widget which needs a localized text | ||
String translate(String key) { | ||
return _localizedStrings[key]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_scaffold/localizations.dart'; | ||
|
||
class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> { | ||
// This delegate instance will never change (it doesn't even have fields!) | ||
// It can provide a constant constructor. | ||
const AppLocalizationsDelegate(); | ||
|
||
@override | ||
bool isSupported(Locale locale) { | ||
// Include all of your supported language codes here | ||
return ['en', 'ar'].contains(locale.languageCode); | ||
} | ||
|
||
@override | ||
Future<AppLocalizations> load(Locale locale) async { | ||
// AppLocalizations class is where the JSON loading actually runs | ||
AppLocalizations localizations = new AppLocalizations(locale); | ||
await localizations.load(); | ||
return localizations; | ||
} | ||
|
||
@override | ||
bool shouldReload(AppLocalizationsDelegate old) => false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters