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
e08d446e
Commit
e08d446e
authored
Dec 03, 2015
by
Jason Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Example of using the Dart internationalization package in Flutter
parent
a2b8f8b9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
187 additions
and
4 deletions
+187
-4
stock_messages_all.dart
examples/stocks/lib/i18n/stock_messages_all.dart
+45
-0
stock_messages_en.dart
examples/stocks/lib/i18n/stock_messages_en.dart
+29
-0
stock_messages_es.dart
examples/stocks/lib/i18n/stock_messages_es.dart
+29
-0
stocks_en.arb
examples/stocks/lib/i18n/stocks_en.arb
+22
-0
stocks_es.arb
examples/stocks/lib/i18n/stocks_es.arb
+22
-0
main.dart
examples/stocks/lib/main.dart
+6
-1
stock_home.dart
examples/stocks/lib/stock_home.dart
+3
-3
stock_strings.dart
examples/stocks/lib/stock_strings.dart
+29
-0
pubspec.yaml
examples/stocks/pubspec.yaml
+2
-0
No files found.
examples/stocks/lib/i18n/stock_messages_all.dart
0 → 100644
View file @
e08d446e
/**
* 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.
*/
library
messages_all
;
import
'dart:async'
;
import
'package:intl/message_lookup_by_library.dart'
;
import
'package:intl/src/intl_helpers.dart'
;
import
'package:intl/intl.dart'
;
import
'stock_messages_en.dart'
as
messages_en
;
import
'stock_messages_es.dart'
as
messages_es
;
Map
<
String
,
Function
>
_deferredLibraries
=
{
'en'
:
()
=>
new
Future
.
value
(
null
),
'es'
:
()
=>
new
Future
.
value
(
null
),
};
MessageLookupByLibrary
_findExact
(
localeName
)
{
switch
(
localeName
)
{
case
'en'
:
return
messages_en
.
messages
;
case
'es'
:
return
messages_es
.
messages
;
default
:
return
null
;
}
}
/** User programs should call this before using [localeName] for messages.*/
Future
initializeMessages
(
String
localeName
)
{
initializeInternalMessageLookup
(()
=>
new
CompositeMessageLookup
());
var
lib
=
_deferredLibraries
[
Intl
.
canonicalizedLocale
(
localeName
)];
var
load
=
lib
==
null
?
new
Future
.
value
(
false
)
:
lib
();
return
load
.
then
((
_
)
=>
messageLookup
.
addLocale
(
localeName
,
_findGeneratedMessagesFor
));
}
MessageLookupByLibrary
_findGeneratedMessagesFor
(
locale
)
{
var
actualLocale
=
Intl
.
verifiedLocale
(
locale
,
(
x
)
=>
_findExact
(
x
)
!=
null
,
onFailure:
(
_
)
=>
null
);
if
(
actualLocale
==
null
)
return
null
;
return
_findExact
(
actualLocale
);
}
examples/stocks/lib/i18n/stock_messages_en.dart
0 → 100644
View file @
e08d446e
/**
* 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.
*/
library
messages_en
;
import
'package:intl/intl.dart'
;
import
'package:intl/message_lookup_by_library.dart'
;
final
messages
=
new
MessageLookup
();
class
MessageLookup
extends
MessageLookupByLibrary
{
get
localeName
=>
'en'
;
static
market
()
=>
"MARKET"
;
static
portfolio
()
=>
"PORTFOLIO"
;
static
title
()
=>
"Stocks"
;
final
messages
=
const
{
"market"
:
market
,
"portfolio"
:
portfolio
,
"title"
:
title
};
}
\ No newline at end of file
examples/stocks/lib/i18n/stock_messages_es.dart
0 → 100644
View file @
e08d446e
/**
* DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
* This is a library that provides messages for a es locale. All the
* messages from the main program should be duplicated here with the same
* function name.
*/
library
messages_es
;
import
'package:intl/intl.dart'
;
import
'package:intl/message_lookup_by_library.dart'
;
final
messages
=
new
MessageLookup
();
class
MessageLookup
extends
MessageLookupByLibrary
{
get
localeName
=>
'es'
;
static
market
()
=>
"MERCADO"
;
static
portfolio
()
=>
"CARTERA"
;
static
title
()
=>
"Acciones"
;
final
messages
=
const
{
"market"
:
market
,
"portfolio"
:
portfolio
,
"title"
:
title
};
}
\ No newline at end of file
examples/stocks/lib/i18n/stocks_en.arb
0 → 100644
View file @
e08d446e
{
"title"
:
"Stocks"
,
"@title"
:
{
"description"
:
"Title for the Stocks application"
,
"type"
:
"text"
,
"placeholders"
:
{}
},
"market"
:
"MARKET"
,
"@market"
:
{
"description"
:
"Label for the Market tab"
,
"type"
:
"text"
,
"placeholders"
:
{}
},
"portfolio"
:
"PORTFOLIO"
,
"@portfolio"
:
{
"description"
:
"Label for the Portfolio tab"
,
"type"
:
"text"
,
"placeholders"
:
{}
}
}
examples/stocks/lib/i18n/stocks_es.arb
0 → 100644
View file @
e08d446e
{
"title"
:
"Acciones"
,
"@title"
:
{
"description"
:
"Title for the Stocks application"
,
"type"
:
"text"
,
"placeholders"
:
{}
},
"market"
:
"MERCADO"
,
"@market"
:
{
"description"
:
"Label for the Market tab"
,
"type"
:
"text"
,
"placeholders"
:
{}
},
"portfolio"
:
"CARTERA"
,
"@portfolio"
:
{
"description"
:
"Label for the Portfolio tab"
,
"type"
:
"text"
,
"placeholders"
:
{}
}
}
examples/stocks/lib/main.dart
View file @
e08d446e
...
@@ -13,8 +13,10 @@ import 'package:flutter/material.dart';
...
@@ -13,8 +13,10 @@ import 'package:flutter/material.dart';
import
'package:flutter/painting.dart'
;
import
'package:flutter/painting.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:intl/intl.dart'
;
import
'stock_data.dart'
;
import
'stock_data.dart'
;
import
'i18n/stock_messages_all.dart'
;
part
'stock_arrow.dart'
;
part
'stock_arrow.dart'
;
part
'stock_home.dart'
;
part
'stock_home.dart'
;
...
@@ -22,6 +24,7 @@ part 'stock_list.dart';
...
@@ -22,6 +24,7 @@ part 'stock_list.dart';
part
'stock_menu.dart'
;
part
'stock_menu.dart'
;
part
'stock_row.dart'
;
part
'stock_row.dart'
;
part
'stock_settings.dart'
;
part
'stock_settings.dart'
;
part
'stock_strings.dart'
;
part
'stock_symbol_viewer.dart'
;
part
'stock_symbol_viewer.dart'
;
part
'stock_types.dart'
;
part
'stock_types.dart'
;
...
@@ -105,5 +108,7 @@ class StocksAppState extends State<StocksApp> {
...
@@ -105,5 +108,7 @@ class StocksAppState extends State<StocksApp> {
}
}
void
main
(
)
{
void
main
(
)
{
runApp
(
new
StocksApp
());
initializeMessages
(
Intl
.
defaultLocale
).
then
((
_
)
{
runApp
(
new
StocksApp
());
});
}
}
examples/stocks/lib/stock_home.dart
View file @
e08d446e
...
@@ -147,7 +147,7 @@ class StockHomeState extends State<StockHome> {
...
@@ -147,7 +147,7 @@ class StockHomeState extends State<StockHome> {
Widget
buildToolBar
()
{
Widget
buildToolBar
()
{
return
new
ToolBar
(
return
new
ToolBar
(
elevation:
0
,
elevation:
0
,
center:
new
Text
(
'Stocks'
),
center:
new
Text
(
StockStrings
.
title
()
),
right:
<
Widget
>[
right:
<
Widget
>[
new
IconButton
(
new
IconButton
(
icon:
"action/search"
,
icon:
"action/search"
,
...
@@ -161,8 +161,8 @@ class StockHomeState extends State<StockHome> {
...
@@ -161,8 +161,8 @@ class StockHomeState extends State<StockHome> {
tabBar:
new
TabBar
(
tabBar:
new
TabBar
(
selection:
_tabBarSelection
,
selection:
_tabBarSelection
,
labels:
<
TabLabel
>[
labels:
<
TabLabel
>[
const
TabLabel
(
text:
'MARKET'
),
new
TabLabel
(
text:
StockStrings
.
market
()
),
const
TabLabel
(
text:
'PORTFOLIO'
)]
new
TabLabel
(
text:
StockStrings
.
portfolio
()
)]
)
)
);
);
}
}
...
...
examples/stocks/lib/stock_strings.dart
0 → 100644
View file @
e08d446e
part of
stocks
;
// Wrappers for strings that are shown in the UI. The strings can be
// translated for different locales using the Dart intl package.
//
// Locale-specific values for the strings live in the i18n/*.arb files.
//
// To generate the stock_messages_*.dart files from the ARB files, run:
// pub run intl:generate_from_arb --output-dir=lib/i18n --generated-file-prefix=stock_ --no-use-deferred-loading lib/stock_strings.dart lib/i18n/stocks_*.arb
class
StockStrings
{
static
String
title
()
=>
Intl
.
message
(
'Stocks'
,
name:
'title'
,
desc:
'Title for the Stocks application'
);
static
String
market
()
=>
Intl
.
message
(
'MARKET'
,
name:
'market'
,
desc:
'Label for the Market tab'
);
static
String
portfolio
()
=>
Intl
.
message
(
'PORTFOLIO'
,
name:
'portfolio'
,
desc:
'Label for the Portfolio tab'
);
}
examples/stocks/pubspec.yaml
View file @
e08d446e
...
@@ -2,3 +2,5 @@ name: stocks
...
@@ -2,3 +2,5 @@ name: stocks
dependencies
:
dependencies
:
flutter
:
flutter
:
path
:
../../packages/flutter
path
:
../../packages/flutter
intl
:
'
>=0.12.4+2
<0.13.0'
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