Permalink
Browse files

reorg: Preparing fort Dart II

  • Loading branch information...
MikeMitterer committed Aug 29, 2018
1 parent 392f87d commit b5525bc10a94913336cbd19426b505f9c9b276ca
View
@@ -3,3 +3,4 @@ packages
packages/**
##locale
*.po~
*.pot
@@ -30,9 +30,9 @@ abstract class ShellCommand {
Validate.notBlank(name);
}
String get executable {
FutureOr<String> get executable async {
if (_exeCache == null) {
_exeCache = whichSync(name);
_exeCache = await where(name);
}
return _exeCache;
}
@@ -43,27 +43,30 @@ abstract class ShellCommand {
bool includeParentEnvironment: true,
bool runInShell: false,
Encoding stdoutEncoding: systemEncoding,
Encoding stderrEncoding: systemEncoding}) =>
Process.run(executable, arguments,
workingDirectory: workingDirectory,
includeParentEnvironment: includeParentEnvironment,
runInShell: runInShell,
stdoutEncoding: stdoutEncoding,
stderrEncoding: stderrEncoding);
Encoding stderrEncoding: systemEncoding}) async {
runSync(List<String> arguments,
{String workingDirectory,
Map<String, String> environment,
bool includeParentEnvironment: true,
bool runInShell: false,
Encoding stdoutEncoding: systemEncoding,
Encoding stderrEncoding: systemEncoding}) =>
Process.runSync(executable, arguments,
workingDirectory: workingDirectory,
includeParentEnvironment: includeParentEnvironment,
runInShell: runInShell,
stdoutEncoding: stdoutEncoding,
stderrEncoding: stderrEncoding);
final String exe = await executable;
return Process.run(exe, arguments,
workingDirectory: workingDirectory,
includeParentEnvironment: includeParentEnvironment,
runInShell: runInShell,
stdoutEncoding: stdoutEncoding,
stderrEncoding: stderrEncoding);
}
// runSync(List<String> arguments,
// {String workingDirectory,
// Map<String, String> environment,
// bool includeParentEnvironment: true,
// bool runInShell: false,
// Encoding stdoutEncoding: systemEncoding,
// Encoding stderrEncoding: systemEncoding}) =>
// Process.runSync(executable, arguments,
// workingDirectory: workingDirectory,
// includeParentEnvironment: includeParentEnvironment,
// runInShell: runInShell,
// stdoutEncoding: stdoutEncoding,
// stderrEncoding: stderrEncoding);
// - private -------------------------------------------------------------------------------------------------------
View
@@ -7,9 +7,9 @@ import 'dart:convert';
import 'dart:math';
import 'package:args/args.dart';
import 'package:which/which.dart';
import 'package:yaml/yaml.dart' as yaml;
import 'package:validate/validate.dart';
import 'package:where/where.dart';
import 'package:intl/intl.dart';
import 'package:intl/intl_standalone.dart';
@@ -65,12 +65,14 @@ class Application {
// _createJson returns ASYNC - so we wait until all locale JSON-Files are created
final List<Future> futuresForJson = new List<Future>();
locales.forEach( (final String locale) {
final File pofile = _preparePOFile(locale, potfile,config.getPOFile(locale));
await Future.forEach(locales, (final String locale) async {
final File pofile = await _preparePOFile(locale, potfile,config.getPOFile(locale));
_mergePO(pofile,potfile);
futuresForJson.add( _createJson(locale,pofile).then((final Map<String,String> jsonForLocale) => json[locale] = jsonForLocale));
});
Future.wait(futuresForJson).then((_) {
_createMergedJson(json,config.jsonfile);
_createDartFile(json,config.dartfile,libPrefix: config.libprefix);
@@ -125,20 +127,20 @@ class Application {
}
/// Updates your translated PO with new records from .pot-File
void _mergePO(final File pofile,final File potfile) {
final ProcessResult result = msgmerge.runSync(['-U', pofile.path, potfile.path]);
void _mergePO(final File pofile,final File potfile) async {
final ProcessResult result = await msgmerge.run(['-U', pofile.path, potfile.path]);
if(result.exitCode != 0) {
_logger.severe(result.stderr);
}
_logger.fine("${pofile.path} merged!");
}
/// Mainly a copy of POT File
File _preparePOFile(final String locale, final File potfile, final String pofilename) {
Future<File> _preparePOFile(final String locale, final File potfile, final String pofilename) async {
final File pofile = new File(pofilename);
if(!pofile.existsSync()) {
pofile.createSync(recursive: true);
final ProcessResult result = msginit.runSync(['--no-translator','--input', potfile.path, '--output', pofile.path, '-l', locale ]);
final ProcessResult result = await msginit.run(['--no-translator','--input', potfile.path, '--output', pofile.path, '-l', locale ]);
if(result.exitCode != 0) {
_logger.severe(result.stderr);
} else {
@@ -195,17 +197,17 @@ class Application {
/// Iterates through dirs and adds the result to the POT-File
Future<bool> _scanDirsAndFillPOTWithXGetText(final List<String> dirstoscan,
String potfile, final List<String> dirsToExclude) {
String potfile, final List<String> dirsToExclude) async {
potfile = potfile.replaceFirst(new RegExp(r"\.pot$"), ".gettext.pot");
final Future<bool> future = new Future<bool>(() {
for (final String dir in dirstoscan) {
_iterateThroughDirSync(dir, dirsToExclude, (final File file) {
_iterateThroughDirSync(dir, dirsToExclude, (final File file) async {
_logger.fine(" -> ${file.path}");
// --from-code ... iconv -l shows all the available codes!
String language = 'JavaScript';
final ProcessResult result = xgettext.runSync(['-kl10n', '-kL10N', '-k_', '-c' ,
final ProcessResult result = await xgettext.run(['-kl10n', '-kL10N', '-k_', '-c' ,
'-j', '-o', "$potfile", '-L', language ,
'--from-code=utf-8', '--sort-by-file', file.path ]);
@@ -305,10 +307,10 @@ class Application {
/// Creates .json-File in the same location where the .po file is
Future<HashMap<String,String>> _createJson(final String locale,final File pofile) {
Future<Map<String,String>> _createJson(final String locale,final File pofile) {
final Completer<Map<String,String>> completer = new Completer<Map<String,String>>();
final Map<String,Map<String,String>> json = new HashMap<String,Map<String,String>>();
final HashMap<String,Map<String,String>> json = new HashMap<String,Map<String,String>>();
json[locale] = new SplayTreeMap<String,String>((final String key1,final String key2) {
// sort case insensitive
return key1.toLowerCase().compareTo(key2.toLowerCase());
View
@@ -45,7 +45,7 @@ abstract class Translatable {
/// bind(Translator, toValue: _translator);
/// }
/// }
@di.injectable
@inject
abstract class Translator {
String translate(final L10N l10n);
View
@@ -4,7 +4,7 @@ import "dart:collection";
import 'package:logging/logging.dart';
import 'dart:convert';
import 'package:intl/intl.dart';
import 'package:dryice/dryice.dart' as di;
import 'package:dryice/dryice.dart';
import "package:validate/validate.dart";
@@ -13,7 +13,7 @@ part "interfaces.dart";
part 'l10n/L10NImpl.dart';
part 'l10n/L10NTranslate.dart';
final L10NTranslate TRANSLATOR = new L10NTranslate();
final L10NTranslate TRANSLATOR = L10NTranslate();
/// Shortcut to get a L10N object
///
@@ -4,6 +4,7 @@ part of l10n;
* Basis für Übersetzungen.
* Macht zur Zeit im Prinzip nur einen String-Replace
*/
@inject
class L10NTranslate extends Translator {
final Logger _logger = new Logger("l10n.L10NTranslate");
Oops, something went wrong.

0 comments on commit b5525bc

Please sign in to comment.