-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add extra asset loaders * make some changes based on code review * minor refactor
- Loading branch information
1 parent
76484a9
commit 63a3974
Showing
9 changed files
with
302 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import 'dart:developer'; | ||
|
||
import 'package:easy_localization/src/easy_localization_controller.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'utils/test_asset_loaders.dart'; | ||
|
||
void main() { | ||
group('ExtraAssetLoaders', () { | ||
test('should work normal if no extraAssetLoaders is provided', () async { | ||
final EasyLocalizationController controller = EasyLocalizationController( | ||
forceLocale: const Locale('en'), | ||
path: 'path/en.json', | ||
supportedLocales: const [Locale('en')], | ||
useOnlyLangCode: true, | ||
useFallbackTranslations: false, | ||
saveLocale: false, | ||
onLoadError: (FlutterError e) { | ||
log(e.toString()); | ||
}, | ||
assetLoader: const ImmutableJsonAssetLoader(), | ||
extraAssetLoaders: null, | ||
); | ||
|
||
var result = await controller.loadTranslationData(const Locale('en')); | ||
|
||
expect(result, {'test': 'test'}); | ||
expect(result.entries.length, 1); | ||
}); | ||
|
||
test('load assets from external loader and merge with asset loader', | ||
() async { | ||
final EasyLocalizationController controller = EasyLocalizationController( | ||
forceLocale: const Locale('en'), | ||
path: 'path/en.json', | ||
supportedLocales: const [Locale('en')], | ||
useOnlyLangCode: true, | ||
useFallbackTranslations: false, | ||
saveLocale: false, | ||
onLoadError: (FlutterError e) { | ||
log(e.toString()); | ||
}, | ||
assetLoader: const ImmutableJsonAssetLoader(), | ||
extraAssetLoaders: [const ExternalAssetLoader()], | ||
); | ||
|
||
final Map<String, dynamic> result = | ||
await controller.loadTranslationData(const Locale('en')); | ||
|
||
expect(result, { | ||
'test': 'test', | ||
'package_value_01': 'package_value_01', | ||
'package_value_02': 'package_value_02', | ||
'package_value_03': 'package_value_03', | ||
}); | ||
expect(result.entries.length, 4); | ||
}); | ||
|
||
test( | ||
'load assets from external loader with nested translations and merge with asset loader', | ||
() async { | ||
final EasyLocalizationController controller = EasyLocalizationController( | ||
forceLocale: const Locale('en'), | ||
path: 'path/en.json', | ||
supportedLocales: const [Locale('en')], | ||
useOnlyLangCode: true, | ||
useFallbackTranslations: false, | ||
saveLocale: false, | ||
onLoadError: (FlutterError e) { | ||
log(e.toString()); | ||
}, | ||
assetLoader: const ImmutableJsonAssetLoader(), | ||
extraAssetLoaders: [const NestedAssetLoader()], | ||
); | ||
|
||
final Map<String, dynamic> result = | ||
await controller.loadTranslationData(const Locale('en')); | ||
|
||
expect(result, { | ||
'test': 'test', | ||
'nested': { | ||
'super': { | ||
'duper': { | ||
'nested': 'nested.super.duper.nested', | ||
} | ||
} | ||
}, | ||
}); | ||
expect(result.entries.length, 2); | ||
}); | ||
|
||
test( | ||
'load assets from external loader and merge duplicates with asset loader', | ||
() async { | ||
final EasyLocalizationController controller = EasyLocalizationController( | ||
forceLocale: const Locale('en'), | ||
path: 'path/en.json', | ||
supportedLocales: const [Locale('en')], | ||
useOnlyLangCode: true, | ||
useFallbackTranslations: false, | ||
saveLocale: false, | ||
onLoadError: (FlutterError e) { | ||
log(e.toString()); | ||
}, | ||
assetLoader: const ImmutableJsonAssetLoader(), | ||
extraAssetLoaders: [const ImmutableJsonAssetLoader()], | ||
); | ||
|
||
final Map<String, dynamic> result = | ||
await controller.loadTranslationData(const Locale('en')); | ||
|
||
expect(result, {'test': 'test'}); | ||
expect(result.entries.length, 1); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.