forked from pauldemarco/flutter_blue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25002f3
commit 480b3fc
Showing
43 changed files
with
211 additions
and
375 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,42 +1,53 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_blue_example/i18n/app_messages_all.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
// 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 app_messages_*.dart files from the ARB files, run: | ||
// flutter packages pub run intl_translation:generate_from_arb --output-dir=lib/i18n --generated-file-prefix=app_ --no-use-deferred-loading lib/*.dart lib/i18n/*.arb | ||
// Information about how this file relates to i18n/stock_messages_all.dart and how the i18n files | ||
// were generated can be found in i18n/regenerate.md. | ||
|
||
class AppStrings extends LocaleQueryData { | ||
static AppStrings of(BuildContext context) { | ||
return LocaleQuery.of(context); | ||
class AppStrings { | ||
AppStrings(Locale locale) : _localeName = locale.toString(); | ||
|
||
final String _localeName; | ||
|
||
static Future<AppStrings> load(Locale locale) { | ||
return initializeMessages(locale.toString()) | ||
.then((Null _) { | ||
return new AppStrings(locale); | ||
}); | ||
} | ||
|
||
static final AppStrings instance = new AppStrings(); | ||
static AppStrings of(BuildContext context) { | ||
return Localizations.of<AppStrings>(context, AppStrings); | ||
} | ||
|
||
String title() => Intl.message( | ||
'Stocks', | ||
name: 'title', | ||
desc: 'Title for the Stocks application' | ||
desc: 'Title for the Stocks application', | ||
locale: _localeName, | ||
); | ||
|
||
String devices() => Intl.message( | ||
'Devices', | ||
name: 'devices', | ||
desc: 'Title for the Devices application' | ||
desc: 'Title for the Devices application', | ||
locale: _localeName, | ||
); | ||
|
||
String scanner() => Intl.message( | ||
'SCANNER', | ||
name: 'scanner', | ||
desc: 'Label for the Scanner tab' | ||
desc: 'Label for the Scanner tab', | ||
locale: _localeName, | ||
); | ||
|
||
String bonded() => Intl.message( | ||
'BONDED', | ||
name: 'bonded', | ||
desc: 'Label for the Bonded tab' | ||
desc: 'Label for the Bonded tab', | ||
locale: _localeName, | ||
); | ||
} |
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
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 @@ | ||
{"title":"Stocks","@title":{"description":"Title for the Stocks application","type":"text","placeholders":{}},"devices":"Devices","@devices":{"description":"Title for the Devices application","type":"text","placeholders":{}},"scanner":"SCANNER","@scanner":{"description":"Label for the Scanner tab","type":"text","placeholders":{}},"bonded":"BONDED","@bonded":{"description":"Label for the Bonded tab","type":"text","placeholders":{}}} |
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 |
---|---|---|
@@ -1,5 +1,33 @@ | ||
To rebuild the i18n files: | ||
## Regenerating the i18n files | ||
|
||
The files in this directory are based on ../lib/stock_strings.dart | ||
which defines all of the localizable strings used by the stocks | ||
app. The stocks app uses | ||
the [Dart `intl` package](https://github.com/dart-lang/intl). | ||
|
||
Rebuilding everything requires two steps. | ||
|
||
With the `examples/stocks` as the current directory, generate | ||
`intl_messages.arb` from `lib/stock_strings.dart`: | ||
``` | ||
flutter packages pub run intl_translation:generate_from_arb --output-dir=lib/i18n --generated-file-prefix=app_ --no-use-deferred-loading lib/*.dart lib/i18n/*.arb | ||
flutter pub pub run intl_translation:extract_to_arb --output-dir=lib/i18n lib/stock_strings.dart | ||
``` | ||
The `intl_messages.arb` file is a JSON format map with one entry for | ||
each `Intl.message()` function defined in `stock_strings.dart`. This | ||
file was used to create the English and Spanish localizations, | ||
`stocks_en.arb` and `stocks_es.arb`. The `intl_messages.arb` wasn't | ||
checked into the repository, since it only serves as a template for | ||
the other `.arb` files. | ||
|
||
|
||
With the `examples/stocks` as the current directory, generate a | ||
`stock_messages_<locale>.dart` for each `stocks_<locale>.arb` file and | ||
`stock_messages_all.dart`, which imports all of the messages files: | ||
``` | ||
flutter pub pub run intl_translation:generate_from_arb --output-dir=lib/i18n \ | ||
--generated-file-prefix=stock_ --no-use-deferred-loading lib/*.dart lib/i18n/stocks_*.arb | ||
``` | ||
|
||
The `StockStrings` class uses the generated `initializeMessages()` | ||
function (`stock_messages_all.dart`) to load the localized messages | ||
and `Intl.message()` to look them up. |
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
Oops, something went wrong.