Last changes not published
This commit is contained in:
parent
ac65ccf990
commit
21ec08303a
43 changed files with 607 additions and 613 deletions
|
|
@ -1,25 +1,34 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
final esRegExp = new RegExp("^es-");
|
||||
|
||||
String getFallbackLang(String lang) {
|
||||
if (lang == 'ast' || lang == 'gl' || lang == 'eu' ||
|
||||
lang == 'es' || lang == 'ca' || (esRegExp).allMatches(lang).length > 0) {
|
||||
String getFallbackLang(String lang) {
|
||||
if (lang == 'ast' ||
|
||||
lang == 'gl' ||
|
||||
lang == 'eu' ||
|
||||
lang == 'es' ||
|
||||
lang == 'ca' ||
|
||||
(esRegExp).allMatches(lang).length > 0) {
|
||||
return 'es';
|
||||
}
|
||||
return 'en';
|
||||
}
|
||||
|
||||
Future<String> getFileNameOfLang({@required String dir,@required String fileName,@required String ext,@required String lang}) async {
|
||||
Future<String> getFileNameOfLang(
|
||||
{@required String dir,
|
||||
@required String fileName,
|
||||
@required String ext,
|
||||
@required String lang}) async {
|
||||
String base = '$dir/$fileName';
|
||||
String fallback = getFallbackLang(lang);
|
||||
String file = '${base}-${lang}.${ext}';
|
||||
String file = '$base-$lang.$ext';
|
||||
if (await assetNotExists(file)) {
|
||||
file = '${base}-${fallback}.${ext}';
|
||||
file = '$base-$fallback.$ext';
|
||||
if (await assetNotExists(file)) {
|
||||
file = '${base}.${ext}';
|
||||
file = '$base.$ext';
|
||||
}
|
||||
}
|
||||
return file;
|
||||
|
|
@ -28,5 +37,9 @@ Future<String> getFileNameOfLang({@required String dir,@required String fileNam
|
|||
// https://github.com/flutter/flutter/issues/15325
|
||||
Future<bool> assetNotExists(String asset) {
|
||||
print('Does not exists $asset ?');
|
||||
return rootBundle.load(asset).then((_) => false).catchError((err, stack) { print (err); print(stack); return true;});
|
||||
}
|
||||
return rootBundle.load(asset).then((_) => false).catchError((err, stack) {
|
||||
print(err);
|
||||
print(stack);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue