Skip to content

Commit 14bded4

Browse files
committed
Implement localization tutorial
1 parent e88d733 commit 14bded4

File tree

9 files changed

+295
-92
lines changed

9 files changed

+295
-92
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
2+
// This is a library that looks up messages for specific locales by
3+
// delegating to the appropriate library.
4+
5+
// Ignore issues from commonly used lints in this file.
6+
// ignore_for_file:implementation_imports, file_names, unnecessary_new
7+
// ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering
8+
// ignore_for_file:argument_type_not_assignable, invalid_assignment
9+
// ignore_for_file:prefer_single_quotes, prefer_generic_function_type_aliases
10+
// ignore_for_file:comment_references
11+
12+
import 'dart:async';
13+
14+
import 'package:flutter/foundation.dart';
15+
import 'package:intl/intl.dart';
16+
import 'package:intl/message_lookup_by_library.dart';
17+
import 'package:intl/src/intl_helpers.dart';
18+
19+
import 'messages_en.dart' as messages_en;
20+
import 'messages_ru.dart' as messages_ru;
21+
22+
typedef Future<dynamic> LibraryLoader();
23+
Map<String, LibraryLoader> _deferredLibraries = {
24+
'en': () => new SynchronousFuture(null),
25+
'ru': () => new SynchronousFuture(null),
26+
};
27+
28+
MessageLookupByLibrary? _findExact(String localeName) {
29+
switch (localeName) {
30+
case 'en':
31+
return messages_en.messages;
32+
case 'ru':
33+
return messages_ru.messages;
34+
default:
35+
return null;
36+
}
37+
}
38+
39+
/// User programs should call this before using [localeName] for messages.
40+
Future<bool> initializeMessages(String localeName) {
41+
var availableLocale = Intl.verifiedLocale(
42+
localeName, (locale) => _deferredLibraries[locale] != null,
43+
onFailure: (_) => null);
44+
if (availableLocale == null) {
45+
return new SynchronousFuture(false);
46+
}
47+
var lib = _deferredLibraries[availableLocale];
48+
lib == null ? new SynchronousFuture(false) : lib();
49+
initializeInternalMessageLookup(() => new CompositeMessageLookup());
50+
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
51+
return new SynchronousFuture(true);
52+
}
53+
54+
bool _messagesExistFor(String locale) {
55+
try {
56+
return _findExact(locale) != null;
57+
} catch (e) {
58+
return false;
59+
}
60+
}
61+
62+
MessageLookupByLibrary? _findGeneratedMessagesFor(String locale) {
63+
var actualLocale =
64+
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null);
65+
if (actualLocale == null) return null;
66+
return _findExact(actualLocale);
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
2+
// This is a library that provides messages for a en locale. All the
3+
// messages from the main program should be duplicated here with the same
4+
// function name.
5+
6+
// Ignore issues from commonly used lints in this file.
7+
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
8+
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
9+
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
10+
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
11+
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes
12+
13+
import 'package:intl/intl.dart';
14+
import 'package:intl/message_lookup_by_library.dart';
15+
16+
final messages = new MessageLookup();
17+
18+
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
19+
20+
class MessageLookup extends MessageLookupByLibrary {
21+
String get localeName => 'en';
22+
23+
static String m0(bonus) => "You receive ${bonus} points";
24+
25+
final messages = _notInlinedMessages(_notInlinedMessages);
26+
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
27+
"goodbye": MessageLookupByLibrary.simpleMessage("Goodbye"),
28+
"hello": MessageLookupByLibrary.simpleMessage("Hello!"),
29+
"youReceiveNBouns": m0
30+
};
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
2+
// This is a library that provides messages for a ru locale. All the
3+
// messages from the main program should be duplicated here with the same
4+
// function name.
5+
6+
// Ignore issues from commonly used lints in this file.
7+
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
8+
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
9+
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
10+
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
11+
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes
12+
13+
import 'package:intl/intl.dart';
14+
import 'package:intl/message_lookup_by_library.dart';
15+
16+
final messages = new MessageLookup();
17+
18+
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
19+
20+
class MessageLookup extends MessageLookupByLibrary {
21+
String get localeName => 'ru';
22+
23+
static String m0(bonus) => "Вы получили бонус ${bonus} баллов";
24+
25+
final messages = _notInlinedMessages(_notInlinedMessages);
26+
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
27+
"goodbye": MessageLookupByLibrary.simpleMessage("Пока"),
28+
"hello": MessageLookupByLibrary.simpleMessage("Привет!"),
29+
"youReceiveNBouns": m0
30+
};
31+
}

localization/lib/generated/l10n.dart

+109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

localization/lib/l10n/intl_en.arb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hello": "Hello!",
3+
"goodbye": "Goodbye",
4+
"youReceiveNBouns": "You receive {bonus} points"
5+
}

localization/lib/l10n/intl_ru.arb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hello": "Привет!",
3+
"goodbye": "Пока",
4+
"youReceiveNBouns": "Вы получили бонус {bonus} баллов"
5+
}

0 commit comments

Comments
 (0)