Merge pull request #12 from falsecz/android-constants

Unification of android version with ios - use constants
This commit is contained in:
Alexander Zaytsev 2016-02-10 20:20:12 +05:00
commit 4687046261
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.ReactContext;
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 {
@ -21,11 +22,10 @@ public class ReactNativeI18nLocale extends ReactContextBaseJavaModule {
return "RNI18n";
}
@ReactMethod
public void getCurrentLocale(
Callback successCallback
) {
String current = reactContext.getResources().getConfiguration().locale.toString();
successCallback.invoke(current);
@Override
public Map<String, Object> getConstants() {
HashMap<String,Object> constants = new HashMap<String,Object>();
constants.put("locale", reactContext.getResources().getConfiguration().locale.toString());
return constants;
}
}

View File

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