Browse Source

add i2pd multilingual support

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/32/head
R4SAS 4 years ago
parent
commit
eef59d9052
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 3
      app/jni/Android.mk
  2. 1
      app/jni/Application.mk
  3. 20
      app/jni/DaemonAndroid.cpp
  4. 2
      app/jni/DaemonAndroid.h
  5. 2
      app/jni/i2pd
  6. 8
      app/jni/i2pd_android.cpp
  7. 3
      app/jni/org_purplei2p_i2pd_I2PD_JNI.h
  8. 9
      app/src/main/java/org/purplei2p/i2pd/DaemonWrapper.java
  9. 2
      app/src/main/java/org/purplei2p/i2pd/I2PD_JNI.java

3
app/jni/Android.mk

@ -2,7 +2,7 @@ LOCAL_PATH := $(call my-dir) @@ -2,7 +2,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := i2pd
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_C_INCLUDES += $(IFADDRS_PATH) $(LIB_SRC_PATH) $(LIB_CLIENT_SRC_PATH) $(DAEMON_SRC_PATH)
LOCAL_C_INCLUDES += $(IFADDRS_PATH) $(LIB_SRC_PATH) $(LIB_CLIENT_SRC_PATH) $(LANG_SRC_PATH) $(DAEMON_SRC_PATH)
LOCAL_STATIC_LIBRARIES := \
boost_system \
boost_date_time \
@ -19,6 +19,7 @@ LOCAL_SRC_FILES := \ @@ -19,6 +19,7 @@ LOCAL_SRC_FILES := \
$(IFADDRS_PATH)/ifaddrs.c \
$(wildcard $(LIB_SRC_PATH)/*.cpp) \
$(wildcard $(LIB_CLIENT_SRC_PATH)/*.cpp) \
$(wildcard $(LANG_SRC_PATH)/*.cpp) \
$(DAEMON_SRC_PATH)/Daemon.cpp \
$(DAEMON_SRC_PATH)/UPnP.cpp \
$(DAEMON_SRC_PATH)/HTTPServer.cpp \

1
app/jni/Application.mk

@ -19,4 +19,5 @@ I2PD_SRC_PATH = $(NDK_MODULE_PATH)/i2pd @@ -19,4 +19,5 @@ I2PD_SRC_PATH = $(NDK_MODULE_PATH)/i2pd
LIB_SRC_PATH = $(I2PD_SRC_PATH)/libi2pd
LIB_CLIENT_SRC_PATH = $(I2PD_SRC_PATH)/libi2pd_client
LANG_SRC_PATH = $(I2PD_SRC_PATH)/i18n
DAEMON_SRC_PATH = $(I2PD_SRC_PATH)/daemon

20
app/jni/DaemonAndroid.cpp

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
#include "FS.h"
#include "DaemonAndroid.h"
#include "Daemon.h"
#include "I18N.h"
namespace i2p
{
@ -74,6 +75,7 @@ namespace android @@ -74,6 +75,7 @@ namespace android
}
*/
std::string dataDir = "";
std::string language = "";
DaemonAndroidImpl::DaemonAndroidImpl ()
//:
@ -104,7 +106,7 @@ namespace android @@ -104,7 +106,7 @@ namespace android
std::this_thread::sleep_for (std::chrono::seconds(1)); // otherwise wait for 1 more second
}
while (numAttempts <= 10); // 10 seconds max
return Daemon.init(argc,argv);
return Daemon.init(argc, argv);
}
void DaemonAndroidImpl::start()
@ -163,12 +165,16 @@ namespace android @@ -163,12 +165,16 @@ namespace android
{
//Log.d(TAG"Initialising the daemon...");
bool daemonInitSuccess = daemon.init(1,argv);
bool daemonInitSuccess = daemon.init(1, argv);
if(!daemonInitSuccess)
{
//QMessageBox::critical(0, "Error", "Daemon init failed");
return "Daemon init failed";
}
// Set webconsole language from application
i2p::i18n::SetLanguage(language);
//Log.d(TAG"Initialised, creating the main window...");
//MainWindow w;
//Log.d(TAG"Before main window.show()...");
@ -219,10 +225,14 @@ namespace android @@ -219,10 +225,14 @@ namespace android
dataDir = jdataDir;
}
std::string
GetDataDir(void)
std::string GetDataDir(void)
{
return dataDir;
}
}
void SetLanguage(std::string jlanguage)
{
language = jlanguage;
}
}
}

2
app/jni/DaemonAndroid.h

@ -54,6 +54,8 @@ namespace android @@ -54,6 +54,8 @@ namespace android
void SetDataDir(std::string jdataDir);
// get datadir
std::string GetDataDir(void);
// set webconsole language
void SetLanguage(std::string jlanguage);
/*
class Worker : public QObject
{

2
app/jni/i2pd

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit f22eaa6db51e36d0a064c56907589164752035c5
Subproject commit 3a53e049bd4fbb085af75810e13970e4471c8a64

8
app/jni/i2pd_android.cpp

@ -56,6 +56,7 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startDaemon @@ -56,6 +56,7 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_startDaemon
(JNIEnv *env, jclass clazz) {
return env->NewStringUTF(i2p::android::start().c_str());
}
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getDataDir
(JNIEnv *env, jclass clazz) {
return env->NewStringUTF( i2p::android::GetDataDir().c_str() );
@ -125,3 +126,10 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getWebConsAddr @@ -125,3 +126,10 @@ JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getWebConsAddr
std::string result = "http://" + httpAddr + ":" + std::to_string(httpPort) + "/";
return env->NewStringUTF(result.c_str());
}
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_setLanguage
(JNIEnv *env, jclass clazz, jstring jlanguage) {
auto language = env->GetStringUTFChars(jlanguage, NULL);
env->ReleaseStringUTFChars(jlanguage, language);
i2p::android::SetLanguage(language);
}

3
app/jni/org_purplei2p_i2pd_I2PD_JNI.h

@ -53,6 +53,9 @@ JNIEXPORT jint JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_GetTransitTunnelsCount @@ -53,6 +53,9 @@ JNIEXPORT jint JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_GetTransitTunnelsCount
JNIEXPORT jstring JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_getWebConsAddr
(JNIEnv *, jclass);
JNIEXPORT void JNICALL Java_org_purplei2p_i2pd_I2PD_1JNI_setLanguage
(JNIEnv *env, jclass clazz, jstring jlanguage);
#ifdef __cplusplus
}
#endif

9
app/src/main/java/org/purplei2p/i2pd/DaemonWrapper.java

@ -10,6 +10,7 @@ import java.io.InputStream; @@ -10,6 +10,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
import java.util.Locale;
import android.annotation.TargetApi;
import android.content.res.AssetManager;
@ -31,6 +32,8 @@ public class DaemonWrapper { @@ -31,6 +32,8 @@ public class DaemonWrapper {
private String i2pdpath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/i2pd/";
private boolean assetsCopied;
private static final String appLocale = Locale.getDefault().getDisplayLanguage(Locale.ENGLISH).toLowerCase(); // lower-case system language (like "english")
public interface StateUpdateListener {
void daemonStateUpdate(State oldValue, State newValue);
}
@ -184,7 +187,11 @@ public class DaemonWrapper { @@ -184,7 +187,11 @@ public class DaemonWrapper {
}
try {
synchronized (DaemonWrapper.this) {
I2PD_JNI.setDataDir(i2pdpath);//(Environment.getExternalStorageDirectory().getAbsolutePath() + "/i2pd");
I2PD_JNI.setDataDir(i2pdpath); // (Environment.getExternalStorageDirectory().getAbsolutePath() + "/i2pd");
Log.d(TAG, "setting webconsole language to " + appLocale);
I2PD_JNI.setLanguage(appLocale);
daemonStartResult = I2PD_JNI.startDaemon();
if ("ok".equals(daemonStartResult)) {
setState(State.startedOkay);

2
app/src/main/java/org/purplei2p/i2pd/I2PD_JNI.java

@ -26,6 +26,8 @@ public class I2PD_JNI { @@ -26,6 +26,8 @@ public class I2PD_JNI {
public static native String getWebConsAddr();
public static native void setLanguage(String jlanguage);
public static void loadLibraries() {
//System.loadLibrary("c++_shared");
System.loadLibrary("i2pd");

Loading…
Cancel
Save