Skip to content

Commit

Permalink
RTL support
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Jul 15, 2020
1 parent 8cb5cb2 commit baba5e2
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,7 @@ Added missing translation handler, according to [issue/67](https://github.com/il
## [0.16.3]

Removed cache parameter from loadString method, resolve [issue/116](https://github.com/ilteoood/flutter_i18n/issues/116)

## [0.17.0]

RTL support.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
builder: FlutterI18n.rootAppBuilder() //If you want to support RTL.
```
Below you can find the name and description of the accepted parameters.
Expand Down
13 changes: 8 additions & 5 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\Users\a34p\Documents\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\a34p\Documents\clienti\flutter_i18n\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_ROOT=/home/teo/snap/flutter/common/flutter"
export "FLUTTER_APPLICATION_PATH=/home/teo/Documenti/git/personale/flutter_i18n/example"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "FLUTTER_FRAMEWORK_DIR=C:\Users\a34p\Documents\flutter\bin\cache\artifacts\engine\ios"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/home/teo/snap/flutter/common/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
1 change: 1 addition & 0 deletions example/lib/basic_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MyApp extends StatelessWidget {
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
builder: FlutterI18n.rootAppBuilder(),
);
}
}
Expand Down
100 changes: 78 additions & 22 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.36.4"
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
Expand All @@ -21,42 +28,49 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
version: "2.4.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "2.0.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
version: "1.1.3"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
version: "1.14.12"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
coverage:
dependency: transitive
description:
name: coverage
url: "https://pub.dartlang.org"
source: hosted
version: "0.13.11"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1+1"
version: "2.1.4"
csslib:
dependency: transitive
description:
Expand All @@ -77,7 +91,7 @@ packages:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.8+1"
version: "5.1.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -94,7 +108,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.16.0"
version: "0.16.3"
flutter_localizations:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -152,13 +166,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
intl:
dependency: transitive
description:
name: intl
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.8"
version: "0.16.1"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -187,13 +208,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.19"
logging:
dependency: transitive
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.4"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.5"
version: "0.12.6"
merge_map:
dependency: transitive
description:
Expand All @@ -207,7 +235,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.7"
version: "1.1.8"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -249,7 +277,7 @@ packages:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.9.3"
package_resolver:
dependency: transitive
description:
Expand Down Expand Up @@ -298,21 +326,21 @@ packages:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.11"
version: "3.0.12"
pub_semver:
dependency: transitive
description:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.2"
version: "1.4.4"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "2.1.3"
shelf:
dependency: transitive
description:
Expand Down Expand Up @@ -352,7 +380,7 @@ packages:
name: source_map_stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.5"
version: "2.0.0"
source_maps:
dependency: transitive
description:
Expand All @@ -366,7 +394,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.5"
version: "1.7.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -388,6 +416,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
sync_http:
dependency: transitive
description:
name: sync_http
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
term_glyph:
dependency: transitive
description:
Expand All @@ -401,21 +436,21 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.3"
version: "1.14.4"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.5"
version: "0.2.15"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.5"
version: "0.3.4"
typed_data:
dependency: transitive
description:
Expand All @@ -430,6 +465,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
vm_service_client:
dependency: transitive
description:
Expand All @@ -450,14 +492,28 @@ packages:
name: web_socket_channel
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.15"
version: "1.1.0"
webdriver:
dependency: transitive
description:
name: webdriver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
webkit_inspection_protocol:
dependency: transitive
description:
name: webkit_inspection_protocol
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.3"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
version: "3.6.1"
xml2json:
dependency: transitive
description:
Expand All @@ -473,4 +529,4 @@ packages:
source: hosted
version: "2.2.1"
sdks:
dart: ">=2.4.0 <3.0.0"
dart: ">=2.7.0 <3.0.0"
25 changes: 24 additions & 1 deletion lib/flutter_i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_i18n/loaders/file_translation_loader.dart';
import 'package:flutter_i18n/loaders/translation_loader.dart';
import 'package:flutter_i18n/utils/plural_translator.dart';
import 'package:flutter_i18n/utils/simple_translator.dart';
import 'package:intl/intl.dart' as intl;

export 'flutter_i18n_delegate.dart';
export 'loaders/e2e_file_translation_loader.dart';
Expand All @@ -22,6 +23,7 @@ class FlutterI18n {

Map<dynamic, dynamic> decodedMap;
MissingTranslationHandler missingTranslationHandler;
final _localeStream = StreamController<Locale>();

FlutterI18n(
TranslationLoader translationLoader, {
Expand All @@ -34,6 +36,7 @@ class FlutterI18n {

Future<bool> load() async {
decodedMap = await translationLoader.load();
_localeStream.add(locale);
return true;
}

Expand Down Expand Up @@ -77,10 +80,30 @@ class FlutterI18n {
}

static Locale currentLocale(final BuildContext context) {
return _retrieveCurrentInstance(context).translationLoader.locale;
final FlutterI18n currentInstance = _retrieveCurrentInstance(context);
return currentInstance?.translationLoader?.locale;
}

static FlutterI18n _retrieveCurrentInstance(BuildContext context) {
return Localizations.of<FlutterI18n>(context, FlutterI18n);
}

static rootAppBuilder() {
return (BuildContext context, Widget child) {
return StreamBuilder<Locale>(
stream: _retrieveCurrentInstance(context)?._localeStream?.stream,
builder: (BuildContext context, AsyncSnapshot<Locale> snapshot) {
return Directionality(
textDirection: _findTextDirection(snapshot.data),
child: child,
);
});
};
}

static _findTextDirection(final Locale locale) {
return intl.Bidi.isRtlLanguage(locale?.countryCode)
? TextDirection.rtl
: TextDirection.ltr;
}
}
Loading

0 comments on commit baba5e2

Please sign in to comment.