Repository: kiwicom/mobile
Pull request #1022 (2018-08-24 13:39:22)

Remove redundant translate method
* remove `translate` method

*NOTE:* Current `translate` method is former `translateAsync`


Patch:
diff --git a/RNAndroidPlayground/react-native-native-modules/src/main/java/com/skypicker/reactnative/nativemodules/translation/RNTranslationManager.kt b/RNAndroidPlayground/react-native-native-modules/src/main/java/com/skypicker/reactnative/nativemodules/translation/RNTranslationManager.kt
index 20fb5333..202216c7 100644
--- a/RNAndroidPlayground/react-native-native-modules/src/main/java/com/skypicker/reactnative/nativemodules/translation/RNTranslationManager.kt
+++ b/RNAndroidPlayground/react-native-native-modules/src/main/java/com/skypicker/reactnative/nativemodules/translation/RNTranslationManager.kt
@@ -1,8 +1,9 @@
 package com.skypicker.reactnative.nativemodules.translation
 
-import com.facebook.react.bridge.*
-import com.facebook.react.bridge.ReactMethod
 import com.facebook.react.bridge.Promise
+import com.facebook.react.bridge.ReactApplicationContext
+import com.facebook.react.bridge.ReactContextBaseJavaModule
+import com.facebook.react.bridge.ReactMethod
 
 class RNTranslationManager(
   reactContext: ReactApplicationContext,
@@ -28,11 +29,8 @@ class RNTranslationManager(
 
   override fun getName(): String = Constant.TAG
 
-  @ReactMethod(isBlockingSynchronousMethod = true)
-  fun translate(key: String) = stringListener.getTranslation(key)
-
   @ReactMethod
-  fun translateAsync(key: String, promise: Promise) {
+  fun translate(key: String, promise: Promise) {
     promise.resolve(stringListener.getTranslation(key))
   }
   // endregion Public Methods
diff --git a/app/core/config/NativeModulesMocks/RNTranslationManager.js b/app/core/config/NativeModulesMocks/RNTranslationManager.js
index 2e7e8d66..40442f98 100644
--- a/app/core/config/NativeModulesMocks/RNTranslationManager.js
+++ b/app/core/config/NativeModulesMocks/RNTranslationManager.js
@@ -4,5 +4,4 @@ import { NativeModules } from 'react-native';
 
 NativeModules.RNTranslationManager = {
   translate: jest.fn(key => key),
-  translateAsync: jest.fn(key => key),
 };
diff --git a/ios/RNModules/RNTranslationManager/RNTranslationManager/RNTranslationManager.m b/ios/RNModules/RNTranslationManager/RNTranslationManager/RNTranslationManager.m
index c119014f..6f4866e7 100755
--- a/ios/RNModules/RNTranslationManager/RNTranslationManager/RNTranslationManager.m
+++ b/ios/RNModules/RNTranslationManager/RNTranslationManager/RNTranslationManager.m
@@ -47,11 +47,7 @@ RCT_EXPORT_MODULE();
     return _translator;
 }
 
-RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(translate:(NSString *)key) {
-    return [self.translator translate:key];
-}
-
-RCT_EXPORT_METHOD(translateAsync:(NSString *)key
+RCT_EXPORT_METHOD(translate:(NSString *)key
                   resolver:(RCTPromiseResolveBlock)resolve
                   rejecter:(RCTPromiseRejectBlock)reject) {
     NSString *translation = [self.translator translate:key];
diff --git a/packages/localization/src/CancellableTranslation.js b/packages/localization/src/CancellableTranslation.js
index eb7f9db6..067041ac 100644
--- a/packages/localization/src/CancellableTranslation.js
+++ b/packages/localization/src/CancellableTranslation.js
@@ -1,7 +1,7 @@
 // @flow strict
 
 import { CancellablePromise } from '@kiwicom/mobile-shared';
-import { translateAsync } from '@kiwicom/rnmodules';
+import { translate } from '@kiwicom/rnmodules';
 
 export type TranslationPromise = {|
   cancel: () => void,
@@ -9,5 +9,5 @@ export type TranslationPromise = {|
 |};
 
 export function cancellableTranslation(nativeKey: string): TranslationPromise {
-  return CancellablePromise(translateAsync(nativeKey));
+  return CancellablePromise(translate(nativeKey));
 }
diff --git a/packages/rnmodules/index.js b/packages/rnmodules/index.js
index d77b206f..42aa5acc 100644
--- a/packages/rnmodules/index.js
+++ b/packages/rnmodules/index.js
@@ -1,4 +1,3 @@
 // @flow
 
 export { translate } from './translation/TranslationManager';
-export { translateAsync } from './translation/TranslationManager';
diff --git a/packages/rnmodules/translation/README.md b/packages/rnmodules/translation/README.md
index cbc3d76c..4a59d59d 100644
--- a/packages/rnmodules/translation/README.md
+++ b/packages/rnmodules/translation/README.md
@@ -4,12 +4,6 @@ It exposes the following methods:
 
 ## translate
 
-```js
-translate(key: String) => String
-```
-
-## translateAsync
-
 ```js
 translateAsync(key: String) => Promise<String>
 ```
\ No newline at end of file
diff --git a/packages/rnmodules/translation/TranslationManager.js b/packages/rnmodules/translation/TranslationManager.js
index d518d35f..d79c1058 100644
--- a/packages/rnmodules/translation/TranslationManager.js
+++ b/packages/rnmodules/translation/TranslationManager.js
@@ -3,4 +3,3 @@
 import { NativeModules } from 'react-native';
 
 export const translate = NativeModules.RNTranslationManager.translate;
-export const translateAsync = NativeModules.RNTranslationManager.translateAsync;


Test patch:
diff --git a/packages/localization/src/__tests__/Translation.test.js b/packages/localization/src/__tests__/Translation.test.js
index 1e7a506c..78d0c7ae 100644
--- a/packages/localization/src/__tests__/Translation.test.js
+++ b/packages/localization/src/__tests__/Translation.test.js
@@ -2,7 +2,7 @@
 
 import * as React from 'react';
 import renderer from 'react-test-renderer';
-import { translateAsync } from '@kiwicom/rnmodules';
+import { translate } from '@kiwicom/rnmodules';
 
 import Translation from '../Translation';
 import { replaceValues } from '../TranslationHelpers';
@@ -24,7 +24,7 @@ const getComponent = (id: string = 'test.key') => {
 
 it('should call getTranslationAsync with the key parameter', () => {
   getComponent();
-  expect(translateAsync).toBeCalledWith('mobile.test.key');
+  expect(translate).toBeCalledWith('mobile.test.key');
 });
 
 it('replaces parameter', () => {