Skip to content

Commit

Permalink
[explorer] append i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeShkurko committed Mar 6, 2021
1 parent 758d05a commit 87f54bd
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 128 deletions.
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ analyzer:
implicit-casts: true
implicit-dynamic: true
errors:
always_declare_return_types: error
always_declare_return_types: warning
camel_case_types: warning
empty_constructor_bodies: warning
annotate_overrides: warning
Expand Down
4 changes: 4 additions & 0 deletions packages/explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [1.1.0]

* Append i18n

## [1.1.0]

* Added i18n

## [1.0.0]
Expand Down
4 changes: 0 additions & 4 deletions packages/explorer/lib/src/i18n/messages/messages_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@ import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
import 'package:intl/src/intl_helpers.dart';

import 'messages_messages.dart' deferred as messages_messages;
import 'messages_en.dart' deferred as messages_en;
import 'messages_ru.dart' deferred as messages_ru;

typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'messages': messages_messages.loadLibrary,
'en': messages_en.loadLibrary,
'ru': messages_ru.loadLibrary,
};

MessageLookupByLibrary _findExact(String localeName) {
switch (localeName) {
case 'messages':
return messages_messages.messages;
case 'en':
return messages_en.messages;
case 'ru':
Expand Down
8 changes: 7 additions & 1 deletion packages/explorer/lib/src/i18n/messages/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class MessageLookup extends MessageLookupByLibrary {
"actionMenuOpen" : MessageLookupByLibrary.simpleMessage("Open"),
"actionMoveHere" : MessageLookupByLibrary.simpleMessage("Move here"),
"cancel" : MessageLookupByLibrary.simpleMessage("Cancel"),
"empty" : MessageLookupByLibrary.simpleMessage("Empty")
"create" : MessageLookupByLibrary.simpleMessage("Create"),
"empty" : MessageLookupByLibrary.simpleMessage("Empty"),
"fileName" : MessageLookupByLibrary.simpleMessage("File name"),
"folderName" : MessageLookupByLibrary.simpleMessage("Folder name"),
"newFile" : MessageLookupByLibrary.simpleMessage("New file"),
"newFolder" : MessageLookupByLibrary.simpleMessage("New folder"),
"uploadFiles" : MessageLookupByLibrary.simpleMessage("Upload files")
};
}
33 changes: 0 additions & 33 deletions packages/explorer/lib/src/i18n/messages/messages_messages.dart

This file was deleted.

8 changes: 7 additions & 1 deletion packages/explorer/lib/src/i18n/messages/messages_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class MessageLookup extends MessageLookupByLibrary {
"actionMenuOpen" : MessageLookupByLibrary.simpleMessage("Открыть"),
"actionMoveHere" : MessageLookupByLibrary.simpleMessage("Вставить сюда"),
"cancel" : MessageLookupByLibrary.simpleMessage("Отменить"),
"empty" : MessageLookupByLibrary.simpleMessage("Пусто")
"create" : MessageLookupByLibrary.simpleMessage("Создать"),
"empty" : MessageLookupByLibrary.simpleMessage("Пусто"),
"fileName" : MessageLookupByLibrary.simpleMessage("Имя файла"),
"folderName" : MessageLookupByLibrary.simpleMessage("Имя папки"),
"newFile" : MessageLookupByLibrary.simpleMessage("Новый файл"),
"newFolder" : MessageLookupByLibrary.simpleMessage("Новая папка"),
"uploadFiles" : MessageLookupByLibrary.simpleMessage("Выгрузить файлы")
};
}
7 changes: 7 additions & 0 deletions packages/explorer/lib/src/i18n/string_resources.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ mixin StringResources {
String get actionMoveHere =>
Intl.message('Move here', name: 'actionMoveHere');

String get folderName => Intl.message('Folder name', name: 'folderName');
String get fileName => Intl.message('File name', name: 'fileName');
String get newFolder => Intl.message('New folder', name: 'newFolder');
String get newFile => Intl.message('New file', name: 'newFile');
String get uploadFiles => Intl.message('Upload files', name: 'uploadFiles');

String get empty => Intl.message('Empty', name: 'empty');
String get cancel => Intl.message('Cancel', name: 'cancel');
String get create => Intl.message('Create', name: 'create');
}
39 changes: 13 additions & 26 deletions packages/explorer/lib/src/ui/widgets/toolbar.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
import 'package:explorer/src/i18n/localization.dart';
import 'package:explorer/src/ui/provider.dart';
import 'package:explorer/src/ui/widgets/breadcrumbs.dart';
import 'package:explorer/src/ui/widgets/fixed_sliver_persistent_header_delegate.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

const _defaultTranslate = {
'cancel': 'Cancel',
'create': 'Create',
'folder_name': 'Folder name',
'file_name': 'File name',
'new_folder': 'New folder',
'new_file': 'New file',
'upload_files': 'Upload files',
};

class ExplorerToolbar extends StatelessWidget {
const ExplorerToolbar({
Key key,
this.translate = _defaultTranslate,
}) : super(key: key);

final Map<String, String> translate;

Future<String> openModal(BuildContext context, String labelText) async =>
showDialog<String>(
context: context,
builder: (context) {
final i18n = ExplorerLocalizations.of(context);

String result;
return AlertDialog(
contentPadding: const EdgeInsets.all(16.0),
Expand All @@ -44,13 +30,13 @@ class ExplorerToolbar extends StatelessWidget {
),
actions: <Widget>[
TextButton(
child: Text(translate['cancel']),
child: Text(i18n.cancel),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: Text(translate['create']),
child: Text(i18n.create),
onPressed: () {
Navigator.of(context).pop(result);
},
Expand All @@ -63,6 +49,7 @@ class ExplorerToolbar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _controller = ControllerProvider.of(context).explorerController;
final i18n = ExplorerLocalizations.of(context);

final safeTopPadding = MediaQuery.of(context).padding.top;
return SliverPersistentHeader(
Expand Down Expand Up @@ -91,12 +78,12 @@ class ExplorerToolbar extends StatelessWidget {
icon: Icon(Icons.add),
onSelected: (String value) async {
if (value == 'directory') {
final folderName = await openModal(
context, translate['folder_name']);
final folderName =
await openModal(context, i18n.folderName);
_controller.newDirectory(folderName);
} else if (value == 'file') {
final fileName = await openModal(
context, translate['file_name']);
final fileName =
await openModal(context, i18n.fileName);
_controller.newFile(fileName);
} else if (value == 'upload') {
_controller.uploadLocalFiles();
Expand All @@ -111,7 +98,7 @@ class ExplorerToolbar extends StatelessWidget {
children: <Widget>[
Icon(Icons.create_new_folder),
SizedBox(width: 16),
Text(translate['new_folder']),
Text(i18n.newFolder),
],
),
),
Expand All @@ -122,7 +109,7 @@ class ExplorerToolbar extends StatelessWidget {
children: <Widget>[
Icon(Icons.note_add),
SizedBox(width: 16),
Text(translate['new_file']),
Text(i18n.newFile),
],
),
),
Expand All @@ -133,7 +120,7 @@ class ExplorerToolbar extends StatelessWidget {
children: <Widget>[
Icon(Icons.upload_file),
SizedBox(width: 16),
Text(translate['upload_files']),
Text(i18n.uploadFiles),
],
),
enabled: _controller.uploadFiles != null,
Expand Down
6 changes: 0 additions & 6 deletions packages/explorer/locales/en.yaml

This file was deleted.

43 changes: 0 additions & 43 deletions packages/explorer/locales/intl_messages.arb

This file was deleted.

25 changes: 25 additions & 0 deletions packages/explorer/locales/intl_messages_en.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"@@locale": "en",
"actionMenuOpen": "Open",
"@actionMenuOpen": {
"type": "text"
Expand All @@ -23,12 +24,36 @@
"@actionMoveHere": {
"type": "text"
},
"folderName": "Folder name",
"@folderName": {
"type": "text"
},
"fileName": "File name",
"@fileName": {
"type": "text"
},
"newFolder": "New folder",
"@newFolder": {
"type": "text"
},
"newFile": "New file",
"@newFile": {
"type": "text"
},
"uploadFiles": "Upload files",
"@uploadFiles": {
"type": "text"
},
"empty": "Empty",
"@empty": {
"type": "text"
},
"cancel": "Cancel",
"@cancel": {
"type": "text"
},
"create": "Create",
"@create": {
"type": "text"
}
}
24 changes: 24 additions & 0 deletions packages/explorer/locales/intl_messages_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,36 @@
"@actionMoveHere": {
"type": "text"
},
"folderName": "Имя папки",
"@folderName": {
"type": "text"
},
"fileName": "Имя файла",
"@fileName": {
"type": "text"
},
"newFolder": "Новая папка",
"@newFolder": {
"type": "text"
},
"newFile": "Новый файл",
"@newFile": {
"type": "text"
},
"uploadFiles": "Выгрузить файлы",
"@uploadFiles": {
"type": "text"
},
"empty": "Пусто",
"@empty": {
"type": "text"
},
"cancel": "Отменить",
"@cancel": {
"type": "text"
},
"create": "Создать",
"@create": {
"type": "text"
}
}
6 changes: 0 additions & 6 deletions packages/explorer/locales/ru.yaml

This file was deleted.

10 changes: 3 additions & 7 deletions packages/explorer/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: explorer
description: Universal explorer UI for navigate files, ftp, etc
version: 1.1.0
version: 1.1.1
homepage: https://github.com/rbcprolabs/packages.flutter/tree/master/packages/explorer

environment:
Expand All @@ -23,15 +23,11 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^1.11.5
intl_translation: ^0.17.10+1

dependency_overrides:
build_runner: ^1.11.5
analyzer: ^1.1.0
args: ^2.0.0
intl: ^0.17.0
io: ^1.0.0

scripts:
i18n: flutter pub run easy_localization:generate -s assets/locales -f keys -O lib/src/i18n -o locale_keys.g.dart
i18n_to_arb: flutter pub run intl_translation:extract_to_arb --output-dir=locales lib/src/i18n/string_resources.dart
i18n_from_arb: flutter pub run intl_translation:generate_from_arb lib/src/i18n/string_resources.dart locales/*.arb --output-dir=lib/src/i18n/messages

0 comments on commit 87f54bd

Please sign in to comment.