Skip to content

Commit

Permalink
Initialized localization
Browse files Browse the repository at this point in the history
  • Loading branch information
konifar committed Jan 15, 2018
1 parent e2fe0e7 commit f0691fa
Show file tree
Hide file tree
Showing 14 changed files with 429 additions and 100 deletions.
69 changes: 69 additions & 0 deletions lib/generated/i18n.dart
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();
15 changes: 15 additions & 0 deletions lib/i18n/REGENERATE.md
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
```
10 changes: 10 additions & 0 deletions lib/i18n/en.arb
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"
}
43 changes: 43 additions & 0 deletions lib/i18n/intl_messages.arb
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": {}
}
}
10 changes: 10 additions & 0 deletions lib/i18n/ja.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"appName":"DroidKaigi 2018",
"allSessions":"すべてのセッション",
"mySchedule":"マイスケジュール",
"map":"マップ",
"settings":"設定",
"sponsors":"スポンサー",
"questionnaire":"アンケート",
"about":"詳細"
}
31 changes: 31 additions & 0 deletions lib/i18n/messages_.dart
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("スポンサー")
};
}
55 changes: 55 additions & 0 deletions lib/i18n/messages_all.dart
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);
}
31 changes: 31 additions & 0 deletions lib/i18n/messages_messages.dart
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")
};
}
32 changes: 32 additions & 0 deletions lib/i18n/strings.dart
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");
}
Loading

0 comments on commit f0691fa

Please sign in to comment.