Skip to content

Commit

Permalink
add: add localizations support.
Browse files Browse the repository at this point in the history
  • Loading branch information
hwh97 committed Jul 13, 2020
1 parent a80a542 commit 51d652c
Show file tree
Hide file tree
Showing 20 changed files with 1,011 additions and 69 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Bored App (Developing)

# IDEA plugin used
- [FlutterJsonBeanFactory](https://plugins.jetbrains.com/plugin/11415-flutterjsonbeanfactory)
- [Flutter Intl](https://plugins.jetbrains.com/plugin/13666-flutter-intl/)


## Getting Started

This project is a starting point for a Flutter application.
Expand Down
9 changes: 9 additions & 0 deletions lib/consts/config_constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:bored/generated/l10n.dart';
import 'package:flutter/cupertino.dart';

class ConfigConstants {
static String appName(BuildContext context) => S.of(context).app_name;

// share preferences keys
static String get languageKey => "cur_language";
}
67 changes: 67 additions & 0 deletions lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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.

// Ignore issues from commonly used lints in this file.
// ignore_for_file:implementation_imports, file_names, unnecessary_new
// ignore_for_file:unnecessary_brace_in_string_interps, directives_ordering
// ignore_for_file:argument_type_not_assignable, invalid_assignment
// ignore_for_file:prefer_single_quotes, prefer_generic_function_type_aliases
// ignore_for_file:comment_references

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_en.dart' as messages_en;
import 'messages_zh.dart' as messages_zh;

typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'en': () => new Future.value(null),
'zh': () => new Future.value(null),
};

MessageLookupByLibrary _findExact(String localeName) {
switch (localeName) {
case 'en':
return messages_en.messages;
case 'zh':
return messages_zh.messages;
default:
return null;
}
}

/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) async {
var availableLocale = Intl.verifiedLocale(
localeName,
(locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return new Future.value(false);
}
var lib = _deferredLibraries[availableLocale];
await (lib == null ? new Future.value(false) : lib());
initializeInternalMessageLookup(() => new CompositeMessageLookup());
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
return new Future.value(true);
}

bool _messagesExistFor(String locale) {
try {
return _findExact(locale) != null;
} catch (e) {
return false;
}
}

MessageLookupByLibrary _findGeneratedMessagesFor(String locale) {
var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor,
onFailure: (_) => null);
if (actualLocale == null) return null;
return _findExact(actualLocale);
}
55 changes: 55 additions & 0 deletions lib/generated/intl/messages_en.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 provides messages for a en locale. All the
// messages from the main program should be duplicated here with the same
// function name.

// Ignore issues from commonly used lints in this file.
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';

final messages = new MessageLookup();

typedef String MessageIfAbsent(String messageStr, List<dynamic> args);

class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';

static m0(p1, p2, p3, p4) => "${p1} ${p2} ${p3} ${p4}";

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"accessibility" : MessageLookupByLibrary.simpleMessage("accessibility:"),
"activity" : MessageLookupByLibrary.simpleMessage("Activity"),
"app_name" : MessageLookupByLibrary.simpleMessage("Boring Remover"),
"april" : MessageLookupByLibrary.simpleMessage("april"),
"august" : MessageLookupByLibrary.simpleMessage("august"),
"december" : MessageLookupByLibrary.simpleMessage("december"),
"february" : MessageLookupByLibrary.simpleMessage("february"),
"format_date" : m0,
"friday" : MessageLookupByLibrary.simpleMessage("Friday"),
"january" : MessageLookupByLibrary.simpleMessage("january"),
"july" : MessageLookupByLibrary.simpleMessage("july"),
"june" : MessageLookupByLibrary.simpleMessage("june"),
"loading" : MessageLookupByLibrary.simpleMessage("Loading"),
"march" : MessageLookupByLibrary.simpleMessage("march"),
"may" : MessageLookupByLibrary.simpleMessage("may"),
"monday" : MessageLookupByLibrary.simpleMessage("Monday"),
"november" : MessageLookupByLibrary.simpleMessage("november"),
"october" : MessageLookupByLibrary.simpleMessage("october"),
"participants" : MessageLookupByLibrary.simpleMessage("participants:"),
"price" : MessageLookupByLibrary.simpleMessage("price:"),
"saturday" : MessageLookupByLibrary.simpleMessage("Saturday"),
"september" : MessageLookupByLibrary.simpleMessage("september"),
"sunday" : MessageLookupByLibrary.simpleMessage("Sunday"),
"thursday" : MessageLookupByLibrary.simpleMessage("Thursday"),
"todoList" : MessageLookupByLibrary.simpleMessage("TODO List"),
"tuesday" : MessageLookupByLibrary.simpleMessage("Tuesday"),
"unknown" : MessageLookupByLibrary.simpleMessage("Unknown"),
"wednesday" : MessageLookupByLibrary.simpleMessage("Wednesday")
};
}
55 changes: 55 additions & 0 deletions lib/generated/intl/messages_zh.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 provides messages for a zh locale. All the
// messages from the main program should be duplicated here with the same
// function name.

// Ignore issues from commonly used lints in this file.
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';

final messages = new MessageLookup();

typedef String MessageIfAbsent(String messageStr, List<dynamic> args);

class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'zh';

static m0(p1, p2, p3, p4) => "${p1}年${p2}${p3}号${p4}";

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"accessibility" : MessageLookupByLibrary.simpleMessage("可行性:"),
"activity" : MessageLookupByLibrary.simpleMessage("活动"),
"app_name" : MessageLookupByLibrary.simpleMessage("找点事做"),
"april" : MessageLookupByLibrary.simpleMessage("4月"),
"august" : MessageLookupByLibrary.simpleMessage("8月"),
"december" : MessageLookupByLibrary.simpleMessage("12月"),
"february" : MessageLookupByLibrary.simpleMessage("2月"),
"format_date" : m0,
"friday" : MessageLookupByLibrary.simpleMessage("星期五"),
"january" : MessageLookupByLibrary.simpleMessage("1月"),
"july" : MessageLookupByLibrary.simpleMessage("7月"),
"june" : MessageLookupByLibrary.simpleMessage("6月"),
"loading" : MessageLookupByLibrary.simpleMessage("加载中..."),
"march" : MessageLookupByLibrary.simpleMessage("3月"),
"may" : MessageLookupByLibrary.simpleMessage("5月"),
"monday" : MessageLookupByLibrary.simpleMessage("星期一"),
"november" : MessageLookupByLibrary.simpleMessage("11月"),
"october" : MessageLookupByLibrary.simpleMessage("10月"),
"participants" : MessageLookupByLibrary.simpleMessage("人员数:"),
"price" : MessageLookupByLibrary.simpleMessage("费用:"),
"saturday" : MessageLookupByLibrary.simpleMessage("星期六"),
"september" : MessageLookupByLibrary.simpleMessage("9月"),
"sunday" : MessageLookupByLibrary.simpleMessage("星期日"),
"thursday" : MessageLookupByLibrary.simpleMessage("星期四"),
"todoList" : MessageLookupByLibrary.simpleMessage("待办列表"),
"tuesday" : MessageLookupByLibrary.simpleMessage("星期二"),
"unknown" : MessageLookupByLibrary.simpleMessage("未知"),
"wednesday" : MessageLookupByLibrary.simpleMessage("星期三")
};
}
Loading

0 comments on commit 51d652c

Please sign in to comment.