setTranslations method

  1. @override
Future<void> setTranslations({
  1. required String fileNameOrPath,
  2. String? packageName,
  3. required dynamic callback(
    1. FlyResponse response
    ),
})
override

Sets custom translations for the MirrorFly platform.

Implementation

@override
Future<void> setTranslations(
    {required fileNameOrPath,
    String? packageName,
    required Function(FlyResponse response) callback}) async {
  final FileReadResult result = await MirrorFlyFileHelper.readFile(
      fileNameOrPath: fileNameOrPath, packageName: packageName);
  if (result.isSuccess) {
    try {
      LogMessage.d(
          "setTranslations loadString success", "true, map: ${result.map}");
      await mirrorFlyMethodChannel
          .invokeMethod<bool>('setTranslations', {"stringSet": result.map});
      callback
          .call(FlyResponse(true, FlyConstants.empty, FlyConstants.empty));
    } on PlatformException catch (e) {
      LogMessage.d("Platform Exception =", " $e");
      callback.call(FlyResponse(false, FlyConstants.empty, FlyConstants.empty,
          FlyException(e.code, e.message, e.details)));
    } on Exception catch (e) {
      LogMessage.d("Exception ", " $e");
      callback.call(FlyResponse(false, FlyConstants.empty, FlyConstants.empty,
          FlyException(FlyErrorCode.unHandle, FlyErrorMessage.unHandle, e)));
    }
  } else {
    LogMessage.d("Exception ", " ${result.errorMessage}");
    callback.call(
        FlyResponse(false, FlyConstants.empty, result.errorMessage, null));
  }
}