-
Notifications
You must be signed in to change notification settings - Fork 104
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
Showing
14 changed files
with
429 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class S { | ||
Locale _locale; | ||
String _lang; | ||
|
||
S(this._locale) { | ||
_lang = getLang(_locale); | ||
print(_lang); | ||
} | ||
|
||
static final GeneratedLocalizationsDelegate delegate = | ||
new GeneratedLocalizationsDelegate(); | ||
|
||
static S of(BuildContext context) { | ||
var s = Localizations.of<S>(context, S); | ||
s._lang = getLang(s._locale); | ||
return s; | ||
} | ||
|
||
} | ||
|
||
class en extends S { | ||
en(Locale locale) : super(locale); | ||
} | ||
class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> { | ||
const GeneratedLocalizationsDelegate(); | ||
|
||
List<Locale> get supportedLocales { | ||
return [ | ||
new Locale("en", ""), | ||
]; | ||
} | ||
|
||
LocaleResolutionCallback resolution({Locale fallback}) { | ||
return (Locale locale, Iterable<Locale> supported) { | ||
var languageLocale = new Locale(locale.languageCode, ""); | ||
if (supported.contains(locale)) | ||
return locale; | ||
else if (supported.contains(languageLocale)) | ||
return languageLocale; | ||
else { | ||
var fallbackLocale = fallback ?? supported.first; | ||
assert(supported.contains(fallbackLocale)); | ||
return fallbackLocale; | ||
} | ||
}; | ||
} | ||
|
||
Future<S> load(Locale locale) { | ||
String lang = getLang(locale); | ||
switch (lang) { | ||
case "en": | ||
return new SynchronousFuture<S>(new en(locale)); | ||
default: | ||
return new SynchronousFuture<S>(new S(locale)); | ||
} | ||
} | ||
|
||
bool isSupported(Locale locale) => supportedLocales.contains(getLang(locale)); | ||
|
||
bool shouldReload(GeneratedLocalizationsDelegate old) => false; | ||
} | ||
|
||
String getLang(Locale l) => | ||
l.countryCode.isEmpty ? l.languageCode : l.toString(); |
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,15 @@ | ||
https://pub.dartlang.org/packages/intl | ||
|
||
``` | ||
flutter packages pub run intl_translation:extract_to_arb --output-dir=lib/i18n lib/i18n/strings.dart | ||
``` | ||
|
||
To rebuild the i18n files: | ||
|
||
``` | ||
flutter packages pub run intl_translation:generate_from_arb \ | ||
--output-dir=lib/i18n \ | ||
--no-use-deferred-loading \ | ||
lib/i18n/*.dart \ | ||
lib/i18n/*.arb | ||
``` |
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,10 @@ | ||
{ | ||
"appName":"DroidKaigi 2018", | ||
"allSessions":"All Sessions", | ||
"mySchedule":"My Schedule", | ||
"map":"Map", | ||
"settings":"Settings", | ||
"sponsors":"Sponsors", | ||
"questionnaire":"Questionnaire", | ||
"about":"About" | ||
} |
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,43 @@ | ||
{ | ||
"@@last_modified": "2018-01-15T03:07:11.397592", | ||
"appName": "DroidKaigi 2018", | ||
"@appName": { | ||
"type": "text", | ||
"placeholders": {} | ||
}, | ||
"allSessions": "All Sessions", | ||
"@allSessions": { | ||
"type": "text", | ||
"placeholders": {} | ||
}, | ||
"mySchedule": "My Schedule", | ||
"@mySchedule": { | ||
"type": "text", | ||
"placeholders": {} | ||
}, | ||
"map": "Map", | ||
"@map": { | ||
"type": "text", | ||
"placeholders": {} | ||
}, | ||
"settings": "Settings", | ||
"@settings": { | ||
"type": "text", | ||
"placeholders": {} | ||
}, | ||
"sponsors": "Sponsors", | ||
"@sponsors": { | ||
"type": "text", | ||
"placeholders": {} | ||
}, | ||
"questionnaire": "Quesionnaire", | ||
"@questionnaire": { | ||
"type": "text", | ||
"placeholders": {} | ||
}, | ||
"about": "About", | ||
"@about": { | ||
"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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"appName":"DroidKaigi 2018", | ||
"allSessions":"すべてのセッション", | ||
"mySchedule":"マイスケジュール", | ||
"map":"マップ", | ||
"settings":"設定", | ||
"sponsors":"スポンサー", | ||
"questionnaire":"アンケート", | ||
"about":"詳細" | ||
} |
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,31 @@ | ||
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart | ||
// This is a library that provides messages for a locale. All the | ||
// messages from the main program should be duplicated here with the same | ||
// function name. | ||
|
||
import 'package:intl/intl.dart'; | ||
import 'package:intl/message_lookup_by_library.dart'; | ||
|
||
final messages = new MessageLookup(); | ||
|
||
// ignore: unused_element | ||
final _keepAnalysisHappy = Intl.defaultLocale; | ||
|
||
// ignore: non_constant_identifier_names | ||
typedef MessageIfAbsent(String message_str, List args); | ||
|
||
class MessageLookup extends MessageLookupByLibrary { | ||
get localeName => ''; | ||
|
||
final messages = _notInlinedMessages(_notInlinedMessages); | ||
static _notInlinedMessages(_) => { | ||
"about": MessageLookupByLibrary.simpleMessage("詳細"), | ||
"allSessions": MessageLookupByLibrary.simpleMessage("すべてのセッション"), | ||
"appName": MessageLookupByLibrary.simpleMessage("DroidKaigi 2016"), | ||
"map": MessageLookupByLibrary.simpleMessage("マップ"), | ||
"mySchedule": MessageLookupByLibrary.simpleMessage("マイスケジュール"), | ||
"questionnaire": MessageLookupByLibrary.simpleMessage("アンケート"), | ||
"settings": MessageLookupByLibrary.simpleMessage("設定"), | ||
"sponsors": MessageLookupByLibrary.simpleMessage("スポンサー") | ||
}; | ||
} |
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,55 @@ | ||
// 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. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:intl/intl.dart'; | ||
import 'package:intl/message_lookup_by_library.dart'; | ||
import 'package:intl/src/intl_helpers.dart'; | ||
|
||
import 'messages_.dart' as messages_; | ||
import 'messages_messages.dart' as messages_messages; | ||
// ignore: implementation_imports | ||
|
||
typedef Future<dynamic> LibraryLoader(); | ||
Map<String, LibraryLoader> _deferredLibraries = { | ||
'': () => new Future.value(null), | ||
'messages': () => new Future.value(null), | ||
}; | ||
|
||
MessageLookupByLibrary _findExact(localeName) { | ||
switch (localeName) { | ||
case '': | ||
return messages_.messages; | ||
case 'messages': | ||
return messages_messages.messages; | ||
case '': | ||
return messages_.messages; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
/// User programs should call this before using [localeName] for messages. | ||
Future initializeMessages(String localeName) async { | ||
var lib = _deferredLibraries[Intl.canonicalizedLocale(localeName)]; | ||
await (lib == null ? new Future.value(false) : lib()); | ||
initializeInternalMessageLookup(() => new CompositeMessageLookup()); | ||
messageLookup.addLocale(localeName, _findGeneratedMessagesFor); | ||
} | ||
|
||
bool _messagesExistFor(String locale) { | ||
try { | ||
return _findExact(locale) != null; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
MessageLookupByLibrary _findGeneratedMessagesFor(locale) { | ||
var actualLocale = | ||
Intl.verifiedLocale(locale, _messagesExistFor, onFailure: (_) => null); | ||
if (actualLocale == null) return null; | ||
return _findExact(actualLocale); | ||
} |
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,31 @@ | ||
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart | ||
// This is a library that provides messages for a messages locale. All the | ||
// messages from the main program should be duplicated here with the same | ||
// function name. | ||
|
||
import 'package:intl/intl.dart'; | ||
import 'package:intl/message_lookup_by_library.dart'; | ||
|
||
final messages = new MessageLookup(); | ||
|
||
// ignore: unused_element | ||
final _keepAnalysisHappy = Intl.defaultLocale; | ||
|
||
// ignore: non_constant_identifier_names | ||
typedef MessageIfAbsent(String message_str, List args); | ||
|
||
class MessageLookup extends MessageLookupByLibrary { | ||
get localeName => 'messages'; | ||
|
||
final messages = _notInlinedMessages(_notInlinedMessages); | ||
static _notInlinedMessages(_) => { | ||
"about": MessageLookupByLibrary.simpleMessage("About"), | ||
"allSessions": MessageLookupByLibrary.simpleMessage("All Sessions"), | ||
"appName": MessageLookupByLibrary.simpleMessage("DroidKaigi 2018"), | ||
"map": MessageLookupByLibrary.simpleMessage("Map"), | ||
"mySchedule": MessageLookupByLibrary.simpleMessage("My Schedule"), | ||
"questionnaire": MessageLookupByLibrary.simpleMessage("Quesionnaire"), | ||
"settings": MessageLookupByLibrary.simpleMessage("Settings"), | ||
"sponsors": MessageLookupByLibrary.simpleMessage("Sponsors") | ||
}; | ||
} |
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,32 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:droidkaigi2018/i18n/messages_all.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:intl/intl.dart'; | ||
|
||
class Strings { | ||
static Future<Strings> load(Locale locale) { | ||
final String name = | ||
locale.countryCode.isEmpty ? locale.languageCode : locale.toString(); | ||
final String localeName = Intl.canonicalizedLocale(name); | ||
return initializeMessages(localeName).then((Null _) { | ||
Intl.defaultLocale = localeName; | ||
return new Strings(); | ||
}); | ||
} | ||
|
||
static Strings of(BuildContext context) { | ||
return Localizations.of<Strings>(context, Strings); | ||
} | ||
|
||
static final Strings instance = new Strings(); | ||
|
||
String get appName => Intl.message("DroidKaigi 2018", name: "appName"); | ||
String allSessions() => Intl.message("All Sessions", name: "allSessions"); | ||
String mySchedule() => Intl.message("My Schedule", name: "mySchedule"); | ||
String map() => Intl.message("Map", name: "map"); | ||
String settings() => Intl.message("Settings", name: "settings"); | ||
String sponsors() => Intl.message("Sponsors", name: "sponsors"); | ||
String questionnaire() => Intl.message("Quesionnaire", name: "questionnaire"); | ||
String about() => Intl.message("About", name: "about"); | ||
} |
Oops, something went wrong.