Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullsafety #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions bin/import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import 'package:gsheet_to_arb/src/utils/log.dart';
void main(List<String> args) async {
var parser = ArgParser();

bool showHelp;
bool createConfig;
var showHelp = false;
var createConfig = false;

parser.addFlag('help',
negatable: false,
Expand Down Expand Up @@ -59,29 +59,31 @@ void main(List<String> args) async {

void _checkAuthConfig(GoogleSheetConfig config) {
final placeholder = 'TODO';
final auth = config.auth;

if (config.auth == null) {
if (auth == null) {
Log.i(
'Authetnication config not found - please add config to ${config.authFile} file');
exit(1);
}

final auth = config.auth;
final oauthClientId = auth.oauthClientId;
final serviceAccountKey = auth.serviceAccountKey;

if (auth.oauthClientId == null && auth.serviceAccountKey == null) {
if (oauthClientId == null && serviceAccountKey == null) {
Log.i(
'Authetnication config is invalid - please add config to ${config.authFile} file');
exit(1);
}

if (auth.oauthClientId != null) {
if (auth.oauthClientId.clientId == placeholder ||
auth.oauthClientId.clientSecret == placeholder) {
if (oauthClientId != null) {
if (oauthClientId.clientId == placeholder ||
oauthClientId.clientSecret == placeholder) {
Log.i('Please use valid auth client configuration');
exit(1);
}
} else if (auth.serviceAccountKey != null) {
if (auth.serviceAccountKey.privateKey == placeholder) {
} else if (serviceAccountKey != null) {
if (serviceAccountKey.privateKey == placeholder) {
Log.i('Please use valid auth server configuration');
exit(1);
}
Expand Down
38 changes: 21 additions & 17 deletions example/lib/l10n/_messages_de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,30 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'de';

static m0(count) => "${Intl.plural(count, one: '${count} kanadische Dollar', other: '${count} kanadischen Dollar')}";
static String m0(count) =>
"${Intl.plural(count, one: '${count} kanadische Dollar', other: '${count} kanadischen Dollar')}";

static m1(count) => "${Intl.plural(count, zero: 'Keine Lieder gefunden.', one: 'Ein Lied gefunden.', two: '${count} Songs gefunden.', few: '${count} Songs gefunden.', many: '${count} Songs gefunden.', other: '${count} Lied gefunden.')}";
static String m1(count) =>
"${Intl.plural(count, zero: 'Keine Lieder gefunden.', one: 'Ein Lied gefunden.', two: '${count} Songs gefunden.', few: '${count} Songs gefunden.', many: '${count} Songs gefunden.', other: '${count} Lied gefunden.')}";

static m2(name) => "Einzel ${name} Argument";
static String m2(name) => "Einzel ${name} Argument";

static m3(first, second) => "Dwa argumenty: ${first} i ${second}";
static String m3(first, second) => "Dwa argumenty: ${first} i ${second}";

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"amountDollars" : m0,
"appName" : MessageLookupByLibrary.simpleMessage("Anwendung"),
"login" : MessageLookupByLibrary.simpleMessage("Einloggen"),
"longText" : MessageLookupByLibrary.simpleMessage("Linie ein\nLinie b\nLinie c\nlorem\nipsum"),
"message" : MessageLookupByLibrary.simpleMessage("Nachricht"),
"numberOfSongsAvailable" : m1,
"register" : MessageLookupByLibrary.simpleMessage("Registrieren"),
"singleArgument" : m2,
"specialCharacters" : MessageLookupByLibrary.simpleMessage("special: äöüß"),
"title" : MessageLookupByLibrary.simpleMessage("Titel"),
"twoArguments" : m3
};
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"amountDollars": m0,
"appName": MessageLookupByLibrary.simpleMessage("Anwendung"),
"login": MessageLookupByLibrary.simpleMessage("Einloggen"),
"longText": MessageLookupByLibrary.simpleMessage(
"Linie ein\nLinie b\nLinie c\nlorem\nipsum"),
"message": MessageLookupByLibrary.simpleMessage("Nachricht"),
"numberOfSongsAvailable": m1,
"register": MessageLookupByLibrary.simpleMessage("Registrieren"),
"singleArgument": m2,
"specialCharacters":
MessageLookupByLibrary.simpleMessage("special: äöüß"),
"title": MessageLookupByLibrary.simpleMessage("Titel"),
"twoArguments": m3
};
}
38 changes: 21 additions & 17 deletions example/lib/l10n/_messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,30 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';

static m0(count) => "${Intl.plural(count, one: '${count} Canadian dollar', other: '${count} Canadian dollars')}";
static String m0(count) =>
"${Intl.plural(count, one: '${count} Canadian dollar', other: '${count} Canadian dollars')}";

static m1(count) => "${Intl.plural(count, zero: 'No songs found.', one: 'One song found.', two: '${count} songs found.', few: '${count} songs found.', many: '${count} songs found.', other: '${count} song found.')}";
static String m1(count) =>
"${Intl.plural(count, zero: 'No songs found.', one: 'One song found.', two: '${count} songs found.', few: '${count} songs found.', many: '${count} songs found.', other: '${count} song found.')}";

static m2(name) => "Single ${name} argument";
static String m2(name) => "Single ${name} argument";

static m3(first, second) => "Argument ${first} and ${second}";
static String m3(first, second) => "Argument ${first} and ${second}";

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"amountDollars" : m0,
"appName" : MessageLookupByLibrary.simpleMessage("Sample Application"),
"login" : MessageLookupByLibrary.simpleMessage("Login"),
"longText" : MessageLookupByLibrary.simpleMessage("line a\nline b\nline c\nlorem\nipsum"),
"message" : MessageLookupByLibrary.simpleMessage("Message"),
"numberOfSongsAvailable" : m1,
"register" : MessageLookupByLibrary.simpleMessage("Register"),
"singleArgument" : m2,
"specialCharacters" : MessageLookupByLibrary.simpleMessage("special: !@#\$%^&*()"),
"title" : MessageLookupByLibrary.simpleMessage("Title"),
"twoArguments" : m3
};
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"amountDollars": m0,
"appName": MessageLookupByLibrary.simpleMessage("Sample Application"),
"login": MessageLookupByLibrary.simpleMessage("Login"),
"longText": MessageLookupByLibrary.simpleMessage(
"line a\nline b\nline c\nlorem\nipsum"),
"message": MessageLookupByLibrary.simpleMessage("Message"),
"numberOfSongsAvailable": m1,
"register": MessageLookupByLibrary.simpleMessage("Register"),
"singleArgument": m2,
"specialCharacters":
MessageLookupByLibrary.simpleMessage("special: !@#\$%^&*()"),
"title": MessageLookupByLibrary.simpleMessage("Title"),
"twoArguments": m3
};
}
38 changes: 21 additions & 17 deletions example/lib/l10n/_messages_pl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,30 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'pl';

static m0(count) => "${Intl.plural(count, one: '${count} dolar kanadyjski', other: '${count} dolarów kanadyjskich')}";
static String m0(count) =>
"${Intl.plural(count, one: '${count} dolar kanadyjski', other: '${count} dolarów kanadyjskich')}";

static m1(count) => "${Intl.plural(count, zero: 'Nie znaleziono piosenek.', one: 'Znaleziono jedną piosenkę.', two: 'Znaleziono ${count} piosenki.', few: 'Znaleziono ${count} piosenek.', many: 'Znaleziono ${count} piosenek.', other: 'Znaleziono ${count} piosenek.')}";
static String m1(count) =>
"${Intl.plural(count, zero: 'Nie znaleziono piosenek.', one: 'Znaleziono jedną piosenkę.', two: 'Znaleziono ${count} piosenki.', few: 'Znaleziono ${count} piosenek.', many: 'Znaleziono ${count} piosenek.', other: 'Znaleziono ${count} piosenek.')}";

static m2(name) => "Pojedynczy argument ${name} ";
static String m2(name) => "Pojedynczy argument ${name} ";

static m3(first, second) => "Dwa argumenty: ${first} i ${second}";
static String m3(first, second) => "Dwa argumenty: ${first} i ${second}";

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"amountDollars" : m0,
"appName" : MessageLookupByLibrary.simpleMessage("Aplikacja"),
"login" : MessageLookupByLibrary.simpleMessage("Zaloguj"),
"longText" : MessageLookupByLibrary.simpleMessage("lina a\nlina b\nlina c\nlorem\nipsum"),
"message" : MessageLookupByLibrary.simpleMessage("Wiadomość"),
"numberOfSongsAvailable" : m1,
"register" : MessageLookupByLibrary.simpleMessage("Zarejestruj"),
"singleArgument" : m2,
"specialCharacters" : MessageLookupByLibrary.simpleMessage("special: ąęśćż"),
"title" : MessageLookupByLibrary.simpleMessage("Tytuł"),
"twoArguments" : m3
};
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"amountDollars": m0,
"appName": MessageLookupByLibrary.simpleMessage("Aplikacja"),
"login": MessageLookupByLibrary.simpleMessage("Zaloguj"),
"longText": MessageLookupByLibrary.simpleMessage(
"lina a\nlina b\nlina c\nlorem\nipsum"),
"message": MessageLookupByLibrary.simpleMessage("Wiadomość"),
"numberOfSongsAvailable": m1,
"register": MessageLookupByLibrary.simpleMessage("Zarejestruj"),
"singleArgument": m2,
"specialCharacters":
MessageLookupByLibrary.simpleMessage("special: ąęśćż"),
"title": MessageLookupByLibrary.simpleMessage("Tytuł"),
"twoArguments": m3
};
}
13 changes: 6 additions & 7 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ name: gsheet_to_arb_example
description: Example of how to use ghseet_to_arb plugin

environment:
sdk: '>=2.0.0 <3.0.0'
sdk: '>=2.0.1 <3.0.0'

dependencies:
intl:
intl_translation: ^0.17.9
intl: any

dev_dependencies:
gsheet_to_arb: ^0.1.8
# path: ../
test: ^1.5.3
mockito: ^4.0.0
gsheet_to_arb: #^0.1.8
path: ../
test: any
mockito: any

gsheet_to_arb:
arb_file_prefix: 'intl'
Expand Down
47 changes: 25 additions & 22 deletions lib/src/arb/arb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
*/

class ArbDocument {
String locale;
DateTime lastModified;
List<ArbResource> entries;
String? locale;
DateTime? lastModified;
List<ArbResource> entries = <ArbResource>[];

ArbDocument(this.locale, this.lastModified, this.entries);

Map<String, Object> toJson({bool compact = false}) {
final json = <String, Object>{};

json['@@locale'] = locale;
json['@@last_modified'] = lastModified.toIso8601String();
if (locale != null) {
json['@@locale'] = locale!;
}

if (lastModified != null) {
json['@@last_modified'] = lastModified!.toIso8601String();
}

entries.forEach((ArbResource resource) {
json[resource.key] = resource.value;
Expand All @@ -38,7 +43,7 @@ class ArbDocument {
lastModified = DateTime.parse(value);
} else if (key.startsWith('@')) {
var entry = entriesMap[key.substring(2)];
entry.attributes.addAll(value);
entry?.attributes.addAll(value);
} else {
var entry = ArbResource(key, value);
entries.add(entry);
Expand All @@ -52,9 +57,9 @@ class ArbResource {
final String key;
final String value;
final Map<String, Object> attributes = {};
final List<ArbResourcePlaceholder> placeholders;
final String description;
final String context;
final List<ArbResourcePlaceholder>? placeholders;
final String? description;
final String? context;

ArbResource(String key, String value,
{this.description = '', this.context = '', this.placeholders = const []})
Expand All @@ -63,16 +68,16 @@ class ArbResource {
// Possible values are "text", "image", "css"
attributes['type'] = 'Text';

if (placeholders != null && placeholders.isNotEmpty) {
attributes['placeholders'] = _formatPlaceholders(placeholders);
if (placeholders != null && placeholders!.isNotEmpty) {
attributes['placeholders'] = _formatPlaceholders(placeholders!);
}

if (description != null && description.isNotEmpty) {
attributes['description'] = description;
if (description != null && description!.isNotEmpty) {
attributes['description'] = description!;
}

if (context != null && context.isNotEmpty) {
attributes['context'] = context;
if (context != null && context!.isNotEmpty) {
attributes['context'] = context!;
}
}

Expand All @@ -82,9 +87,7 @@ class ArbResource {

placeholders.forEach((placeholder) {
final placeholderArgs = <String, Object>{};
if (placeholder.type != null) {
placeholderArgs['type'] = placeholder.type;
}
placeholderArgs['type'] = placeholder.type;
map[placeholder.name] = placeholderArgs;
});
return map;
Expand All @@ -97,12 +100,12 @@ class ArbResourcePlaceholder {

final String name;
final String type;
final String description;
final String example;
final String? description;
final String? example;

ArbResourcePlaceholder({
this.name,
this.type,
required this.name,
required this.type,
this.description,
this.example,
});
Expand Down
Loading