Unverified Commit 0d348138 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

Sort locales and method/properties/getters alphabetically (#44761)

* Sort locales and method/properties/getters alphabetically

* Refresh stocks example to show proper sorting
parent f766871e
...@@ -149,6 +149,10 @@ const String pluralMethodTemplate = ''' ...@@ -149,6 +149,10 @@ const String pluralMethodTemplate = '''
} }
'''; ''';
int sortFilesByPath (FileSystemEntity a, FileSystemEntity b) {
return a.path.compareTo(b.path);
}
List<String> genMethodParameters(Map<String, dynamic> bundle, String key, String type) { List<String> genMethodParameters(Map<String, dynamic> bundle, String key, String type) {
final Map<String, dynamic> attributesMap = bundle['@$key']; final Map<String, dynamic> attributesMap = bundle['@$key'];
if (attributesMap != null && attributesMap.containsKey('placeholders')) { if (attributesMap != null && attributesMap.containsKey('placeholders')) {
...@@ -384,7 +388,7 @@ Future<void> main(List<String> arguments) async { ...@@ -384,7 +388,7 @@ Future<void> main(List<String> arguments) async {
final Set<String> supportedLanguageCodes = <String>{}; final Set<String> supportedLanguageCodes = <String>{};
final Set<LocaleInfo> supportedLocales = <LocaleInfo>{}; final Set<LocaleInfo> supportedLocales = <LocaleInfo>{};
for (FileSystemEntity entity in l10nDirectory.listSync()) { for (FileSystemEntity entity in l10nDirectory.listSync().toList()..sort(sortFilesByPath)) {
final String entityPath = entity.path; final String entityPath = entity.path;
if (FileSystemEntity.isFileSync(entityPath)) { if (FileSystemEntity.isFileSync(entityPath)) {
...@@ -435,7 +439,7 @@ Future<void> main(List<String> arguments) async { ...@@ -435,7 +439,7 @@ Future<void> main(List<String> arguments) async {
final RegExp pluralValueRE = RegExp(r'^\s*\{[\w\s,]*,\s*plural\s*,'); final RegExp pluralValueRE = RegExp(r'^\s*\{[\w\s,]*,\s*plural\s*,');
for (String key in bundle.keys) { for (String key in bundle.keys.toList()..sort()) {
if (key.startsWith('@')) if (key.startsWith('@'))
continue; continue;
if (!_isValidGetterAndMethodName(key)) if (!_isValidGetterAndMethodName(key))
......
...@@ -15,21 +15,21 @@ import 'package:intl/intl.dart'; ...@@ -15,21 +15,21 @@ import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart'; import 'package:intl/message_lookup_by_library.dart';
import 'package:intl/src/intl_helpers.dart'; import 'package:intl/src/intl_helpers.dart';
import 'messages_es_ES.dart' as messages_es_es;
import 'messages_en_US.dart' as messages_en_us; import 'messages_en_US.dart' as messages_en_us;
import 'messages_es_ES.dart' as messages_es_es;
typedef Future<dynamic> LibraryLoader(); typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = { Map<String, LibraryLoader> _deferredLibraries = {
'es_ES': () => new Future.value(null),
'en_US': () => new Future.value(null), 'en_US': () => new Future.value(null),
'es_ES': () => new Future.value(null),
}; };
MessageLookupByLibrary _findExact(String localeName) { MessageLookupByLibrary _findExact(String localeName) {
switch (localeName) { switch (localeName) {
case 'es_ES':
return messages_es_es.messages;
case 'en_US': case 'en_US':
return messages_en_us.messages; return messages_en_us.messages;
case 'es_ES':
return messages_es_es.messages;
default: default:
return null; return null;
} }
......
...@@ -65,7 +65,7 @@ class StockStrings { ...@@ -65,7 +65,7 @@ class StockStrings {
static Future<StockStrings> load(Locale locale) { static Future<StockStrings> load(Locale locale) {
return initializeMessages(locale.toString()) return initializeMessages(locale.toString())
.then<StockStrings>((void _) => StockStrings(locale)); .then<StockStrings>((_) => StockStrings(locale));
} }
static StockStrings of(BuildContext context) { static StockStrings of(BuildContext context) {
...@@ -89,19 +89,10 @@ class StockStrings { ...@@ -89,19 +89,10 @@ 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('es', 'ES'),
Locale('en', 'US'), Locale('en', 'US'),
Locale('es', 'ES'),
]; ];
String get title {
return Intl.message(
r'Stocks',
locale: _localeName,
name: 'title',
desc: r'Title for the Stocks application'
);
}
String get market { String get market {
return Intl.message( return Intl.message(
r'MARKET', r'MARKET',
...@@ -120,6 +111,15 @@ class StockStrings { ...@@ -120,6 +111,15 @@ class StockStrings {
); );
} }
String get title {
return Intl.message(
r'Stocks',
locale: _localeName,
name: 'title',
desc: r'Title for the Stocks application'
);
}
} }
class _StockStringsDelegate extends LocalizationsDelegate<StockStrings> { class _StockStringsDelegate extends LocalizationsDelegate<StockStrings> {
...@@ -129,7 +129,7 @@ class _StockStringsDelegate extends LocalizationsDelegate<StockStrings> { ...@@ -129,7 +129,7 @@ class _StockStringsDelegate extends LocalizationsDelegate<StockStrings> {
Future<StockStrings> load(Locale locale) => StockStrings.load(locale); Future<StockStrings> load(Locale locale) => StockStrings.load(locale);
@override @override
bool isSupported(Locale locale) => <String>['es', 'en'].contains(locale.languageCode); bool isSupported(Locale locale) => <String>['en', 'es'].contains(locale.languageCode);
@override @override
bool shouldReload(_StockStringsDelegate old) => false; bool shouldReload(_StockStringsDelegate old) => false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment