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
39ffce3e
Unverified
Commit
39ffce3e
authored
May 28, 2020
by
Shi-Hao Hong
Committed by
GitHub
May 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update stocks example to use l10n.yaml workflow (#58121)
parent
7cdf26d0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
27 deletions
+42
-27
l10n.yaml
dev/benchmarks/test_apps/stocks/l10n.yaml
+17
-0
regenerate.md
dev/benchmarks/test_apps/stocks/lib/i18n/regenerate.md
+11
-19
stock_strings.dart
dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings.dart
+14
-8
No files found.
dev/benchmarks/test_apps/stocks/l10n.yaml
0 → 100644
View file @
39ffce3e
# Options used by the localizations tool
## `arb-dir` sets the input directory. The output directory will match
## the input directory if the output directory is not set.
arb-dir
:
lib/i18n
## `template-arb-file` describes the template arb file that the tool
## will use to check and validate the remaining arb files when
## generating Flutter's localization files.
template-arb-file
:
stocks_en.arb
## `output-localization-file` is the name of the generated file.
output-localization-file
:
stock_strings.dart
## `output-class` is the name of the localizations class your
## Flutter application will use. The file will need to be
## imported throughout your application.
output-class
:
StockStrings
## `header-file` is the file that contains a custom
## header for each of the generated files.
header-file
:
header.txt
dev/benchmarks/test_apps/stocks/lib/i18n/regenerate.md
View file @
39ffce3e
# Regenerating the i18n files
# Regenerating the i18n files
The files in this directory are used to generate
`stock_strings.dart`
, which
The files in this directory are used to generate
`stock_strings.dart`
,
is used by the stocks application to look up localized message strings. The
which contains the
`StockStrings`
class. This localizations class is
stocks app uses the
[
Dart `intl` package
](
https://github.com/dart-lang/intl
)
.
used by the stocks application to look up localized message strings.
The stocks app uses the
[
Dart `intl` package
](
https://github.com/dart-lang/intl
)
.
Rebuilding everything requires two steps.
To update the English and Spanish localizations, modify the
`stocks_en_US.arb`
,
`stocks_en.arb`
, or
`stocks_es.arb`
files. See the
1.
Create or update the English and Spanish localizations,
`stocks_en_US.arb`
,
`stocks_en.arb`
, and
`stocks_es.arb`
. See the
[
ARB specification
](
https://github.com/google/app-resource-bundle/wiki/ApplicationResourceBundleSpecification
)
[
ARB specification
](
https://github.com/google/app-resource-bundle/wiki/ApplicationResourceBundleSpecification
)
for more info.
for more info.
2.
With
`examples/stocks`
as the current directory, generate a
To modify the project's configuration of the localizations tool,
`messages_<locale>.dart`
for each
`stocks_<locale>.arb`
file,
change the
`l10n.yaml`
file.
`messages_all.dart`
, and
`stock_strings.dart`
with the following command:
```
dart
dart
$
{
FLUTTER_PATH
}/
dev
/
tools
/
localization
/
bin
/
gen_l10n
.
dart
--
arb
-
dir
=
lib
/
i18n
\
--
template
-
arb
-
file
=
stocks_en
.
arb
--
output
-
localization
-
file
=
stock_strings
.
dart
\
--
output
-
class
=
StockStrings
--
header
-
file
=
header
.
txt
```
The
`StockStrings`
class creates a delegate that performs message lookups
The
`StockStrings`
class creates a delegate that performs message lookups
based on the locale of the device. In this case, the stocks app supports
based on the locale of the device. In this case, the stocks app supports
`en`
,
`en_US`
, and
`es`
. Thus, the
`StockStringsEn`
and
`StockStringsEs`
`en`
,
`en_US`
, and
`es`
locales. Thus, the
`StockStringsEn`
and
classes extends
`StockStrings`
.
`StockStringsEnUs`
extends
`StockStringsEs`
classes extends
`StockStrings`
.
`StockStringsEnUs`
extends
`StockStringsEn`
. This allows
`StockStringsEnUs`
to fall back on messages
`StockStringsEn`
. This allows
`StockStringsEnUs`
to fall back on messages
in
`StockStringsEn`
.
in
`StockStringsEn`
.
\ No newline at end of file
dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings.dart
View file @
39ffce3e
...
@@ -4,17 +4,15 @@
...
@@ -4,17 +4,15 @@
import
'dart:async'
;
import
'dart:async'
;
// ignore: unused_import
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_localizations/flutter_localizations.dart'
;
import
'package:flutter_localizations/flutter_localizations.dart'
;
// ignore: unused_import
import
'package:intl/intl.dart'
as
intl
;
import
'package:intl/intl.dart'
as
intl
;
import
'stock_strings_en.dart'
;
import
'stock_strings_en.dart'
;
import
'stock_strings_es.dart'
;
import
'stock_strings_es.dart'
;
// ignore_for_file: unnecessary_brace_in_string_interps
/// Callers can lookup localized strings with an instance of StockStrings returned
/// Callers can lookup localized strings with an instance of StockStrings returned
/// by `StockStrings.of(context)`.
/// by `StockStrings.of(context)`.
///
///
...
@@ -42,8 +40,7 @@ import 'stock_strings_es.dart';
...
@@ -42,8 +40,7 @@ import 'stock_strings_es.dart';
/// # Internationalization support.
/// # Internationalization support.
/// flutter_localizations:
/// flutter_localizations:
/// sdk: flutter
/// sdk: flutter
/// intl: 0.16.0
/// intl: 0.16.1
/// intl_translation: 0.17.7
///
///
/// # rest of dependencies
/// # rest of dependencies
/// ```
/// ```
...
@@ -99,7 +96,7 @@ abstract class StockStrings {
...
@@ -99,7 +96,7 @@ abstract class StockStrings {
/// A list of this localizations delegate's supported locales.
/// A list of this localizations delegate's supported locales.
static
const
List
<
Locale
>
supportedLocales
=
<
Locale
>[
static
const
List
<
Locale
>
supportedLocales
=
<
Locale
>[
Locale
(
'en'
),
Locale
(
'en'
),
Locale
(
'en
,
US'
),
Locale
(
'en
'
,
'
US'
),
Locale
(
'es'
)
Locale
(
'es'
)
];
];
...
@@ -129,15 +126,24 @@ class _StockStringsDelegate extends LocalizationsDelegate<StockStrings> {
...
@@ -129,15 +126,24 @@ class _StockStringsDelegate extends LocalizationsDelegate<StockStrings> {
}
}
StockStrings
_lookupStockStrings
(
Locale
locale
)
{
StockStrings
_lookupStockStrings
(
Locale
locale
)
{
switch
(
locale
.
languageCode
)
{
// Lookup logic when language+country codes are specified.
switch
(
locale
.
languageCode
)
{
case
'en'
:
{
case
'en'
:
{
switch
(
locale
.
countryCode
)
{
switch
(
locale
.
countryCode
)
{
case
'US'
:
return
StockStringsEnUs
();
case
'US'
:
return
StockStringsEnUs
();
}
}
return
StockStringsEn
()
;
break
;
}
}
}
// Lookup logic when only language code is specified.
switch
(
locale
.
languageCode
)
{
case
'en'
:
return
StockStringsEn
();
case
'es'
:
return
StockStringsEs
();
case
'es'
:
return
StockStringsEs
();
}
}
assert
(
false
,
'StockStrings.delegate failed to load unsupported locale "
$locale
"'
);
assert
(
false
,
'StockStrings.delegate failed to load unsupported locale "
$locale
"'
);
return
null
;
return
null
;
}
}
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