Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
4faa0367
Commit
4faa0367
authored
Sep 01, 2017
by
Hans Muller
Committed by
GitHub
Sep 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added localizations for Directionality (#11870)
parent
e216004b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
19 deletions
+64
-19
app.dart
packages/flutter/lib/src/widgets/app.dart
+1
-3
localizations.dart
packages/flutter/lib/src/widgets/localizations.dart
+42
-13
localizations_test.dart
packages/flutter/test/widgets/localizations_test.dart
+21
-3
No files found.
packages/flutter/lib/src/widgets/app.dart
View file @
4faa0367
...
...
@@ -28,9 +28,7 @@ class _WidgetsLocalizationsDelegate extends LocalizationsDelegate<WidgetsLocaliz
const
_WidgetsLocalizationsDelegate
();
@override
Future
<
WidgetsLocalizations
>
load
(
Locale
locale
)
{
return
new
SynchronousFuture
<
WidgetsLocalizations
>(
const
WidgetsLocalizations
());
}
Future
<
WidgetsLocalizations
>
load
(
Locale
locale
)
=>
DefaultWidgetsLocalizations
.
load
(
locale
);
@override
bool
shouldReload
(
_WidgetsLocalizationsDelegate
old
)
=>
false
;
...
...
packages/flutter/lib/src/widgets/localizations.dart
View file @
4faa0367
...
...
@@ -114,20 +114,13 @@ abstract class LocalizationsDelegate<T> {
/// In particular, this maps locales to a specific [Directionality] using the
/// [textDirection] property.
///
/// This class provides a default placeholder implementation that returns
/// hard-coded American English values.
class
WidgetsLocalizations
{
/// Create a placeholder object for the localized resources of the lowest
/// levels of the Flutter framework which only provides values for American
/// English.
const
WidgetsLocalizations
();
/// The locale for which the values of this class's localized resources
/// have been translated.
Locale
get
locale
=>
const
Locale
(
'en'
,
'US'
);
/// See also:
///
/// * [DefaultWidgetsLocalizations], which implements this interface and
/// supports a variety of locales.
abstract
class
WidgetsLocalizations
{
/// The reading direction for text in this locale.
TextDirection
get
textDirection
=>
TextDirection
.
ltr
;
TextDirection
get
textDirection
;
/// The `WidgetsLocalizations` from the closest [Localizations] instance
/// that encloses the given context.
...
...
@@ -146,6 +139,42 @@ class WidgetsLocalizations {
}
}
/// Localized values for widgets.
class
DefaultWidgetsLocalizations
implements
WidgetsLocalizations
{
DefaultWidgetsLocalizations
(
this
.
locale
)
{
final
String
language
=
locale
.
languageCode
.
toLowerCase
();
_textDirection
=
_rtlLanguages
.
contains
(
language
)
?
TextDirection
.
rtl
:
TextDirection
.
ltr
;
}
// See http://en.wikipedia.org/wiki/Right-to-left
static
const
List
<
String
>
_rtlLanguages
=
const
<
String
>[
'ar'
,
// Arabic
'dv'
,
// Dhivehi
'fa'
,
// Farsi
'he'
,
// Hebrew
'ps'
,
// Pashto
'sd'
,
// Sindhi
'ur'
,
// Urdu
];
/// The locale for which the values of this class's localized resources
/// have been translated.
final
Locale
locale
;
@override
TextDirection
get
textDirection
=>
_textDirection
;
TextDirection
_textDirection
;
/// Creates an object that provides localized resource values for the
/// lowest levels of the Flutter framework.
///
/// This method is typically used to create a [LocalizationsDelegate].
/// The [WidgetsApp] does so by default.
static
Future
<
WidgetsLocalizations
>
load
(
Locale
locale
)
{
return
new
SynchronousFuture
<
WidgetsLocalizations
>(
new
DefaultWidgetsLocalizations
(
locale
));
}
}
class
_LocalizationsScope
extends
InheritedWidget
{
_LocalizationsScope
({
Key
key
,
...
...
packages/flutter/test/widgets/localizations_test.dart
View file @
4faa0367
...
...
@@ -417,6 +417,26 @@ void main() {
expect
(
modifiedDelegate
.
shouldReloadValues
,
<
bool
>[
true
]);
});
testWidgets
(
'Directionality tracks system locale'
,
(
WidgetTester
tester
)
async
{
BuildContext
pageContext
;
await
tester
.
pumpWidget
(
buildFrame
(
buildContent:
(
BuildContext
context
)
{
pageContext
=
context
;
return
const
Text
(
'Hello World'
);
}
)
);
await
tester
.
binding
.
setLocale
(
'en'
,
'GB'
);
await
tester
.
pump
();
expect
(
Directionality
.
of
(
pageContext
),
TextDirection
.
ltr
);
await
tester
.
binding
.
setLocale
(
'ar'
,
'EG'
);
await
tester
.
pump
();
expect
(
Directionality
.
of
(
pageContext
),
TextDirection
.
rtl
);
});
}
// Same as _WidgetsLocalizationsDelegate in widgets/app.dart
...
...
@@ -424,9 +444,7 @@ class DefaultWidgetsLocalizationsDelegate extends LocalizationsDelegate<WidgetsL
const
DefaultWidgetsLocalizationsDelegate
();
@override
Future
<
WidgetsLocalizations
>
load
(
Locale
locale
)
{
return
new
SynchronousFuture
<
WidgetsLocalizations
>(
const
WidgetsLocalizations
());
}
Future
<
WidgetsLocalizations
>
load
(
Locale
locale
)
=>
DefaultWidgetsLocalizations
.
load
(
locale
);
@override
bool
shouldReload
(
DefaultWidgetsLocalizationsDelegate
old
)
=>
false
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment