Unification of android version with ios - use constants

This commit is contained in:
Lukas Benes 2016-01-03 11:24:05 +01:00
parent ec62aaa8f2
commit 27bc21f3d4
2 changed files with 9 additions and 15 deletions

View File

@ -3,8 +3,9 @@ package com.i18n.reactnativei18n;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback; import java.util.HashMap;
import java.util.Map;
public class ReactNativeI18nLocale extends ReactContextBaseJavaModule { public class ReactNativeI18nLocale extends ReactContextBaseJavaModule {
@ -21,11 +22,10 @@ public class ReactNativeI18nLocale extends ReactContextBaseJavaModule {
return "RNI18n"; return "RNI18n";
} }
@ReactMethod @Override
public void getCurrentLocale( public Map<String, Object> getConstants() {
Callback successCallback HashMap<String,Object> constants = new HashMap<String,Object>();
) { constants.put("locale", reactContext.getResources().getConfiguration().locale.toString());
String current = reactContext.getResources().getConfiguration().locale.toString(); return constants;
successCallback.invoke(current);
} }
} }

View File

@ -4,12 +4,6 @@ let { Platform, NativeModules } = require('react-native')
let { RNI18n } = NativeModules let { RNI18n } = NativeModules
let I18n = require('./vendor/i18n') let I18n = require('./vendor/i18n')
if (Platform.OS === 'android') { I18n.locale = RNI18n.locale.replace(/_/, '-');
RNI18n.getCurrentLocale( function(locale) {
I18n.locale = locale.replace(/_/, '-');
});
} else {
I18n.locale = RNI18n.locale.replace(/_/, '-');
}
module.exports = I18n; module.exports = I18n;