Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Gettext support on Android (#11435)
Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: =?UTF-8?q?Olivier=20Samyn=20=F0=9F=8E=BB?= <code@oleastre.be>
  • Loading branch information
3 people committed Aug 8, 2021
1 parent 4a3728d commit c6eddb0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/android.yml
Expand Up @@ -28,6 +28,8 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Install deps
run: sudo apt-get update; sudo apt-get install -y --no-install-recommends gettext
- name: Build with Gradle
run: cd android; ./gradlew assemblerelease
- name: Save armeabi artifact
Expand Down
11 changes: 7 additions & 4 deletions android/app/build.gradle
Expand Up @@ -76,10 +76,13 @@ task prepareAssets() {
copy {
from "${projRoot}/games/${gameToCopy}" into "${assetsFolder}/games/${gameToCopy}"
}
/*copy {
// ToDo: fix broken locales
from "${projRoot}/po" into "${assetsFolder}/po"
}*/
fileTree("${projRoot}/po").include("**/*.po").forEach { poFile ->
def moPath = "${assetsFolder}/locale/${poFile.parentFile.name}/LC_MESSAGES/"
file(moPath).mkdirs()
exec {
commandLine 'msgfmt', '-o', "${moPath}/minetest.mo", poFile
}
}
copy {
from "${projRoot}/textures" into "${assetsFolder}/textures"
}
Expand Down
9 changes: 8 additions & 1 deletion android/native/jni/Android.mk
Expand Up @@ -47,6 +47,11 @@ LOCAL_MODULE := OpenAL
LOCAL_SRC_FILES := deps/Android/OpenAL-Soft/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libopenal.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := GetText
LOCAL_SRC_FILES := deps/Android/GetText/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libintl.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := Vorbis
LOCAL_SRC_FILES := deps/Android/Vorbis/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libvorbis.a
Expand All @@ -64,6 +69,7 @@ LOCAL_CFLAGS += \
-DUSE_FREETYPE=1 \
-DUSE_LEVELDB=0 \
-DUSE_LUAJIT=1 \
-DUSE_GETTEXT=1 \
-DVERSION_MAJOR=${versionMajor} \
-DVERSION_MINOR=${versionMinor} \
-DVERSION_PATCH=${versionPatch} \
Expand All @@ -89,6 +95,7 @@ LOCAL_C_INCLUDES := \
deps/Android/Freetype/include \
deps/Android/Irrlicht/include \
deps/Android/LevelDB/include \
deps/Android/GetText/include \
deps/Android/libiconv/include \
deps/Android/libiconv/libcharset/include \
deps/Android/LuaJIT/src \
Expand Down Expand Up @@ -194,7 +201,7 @@ LOCAL_SRC_FILES += \
# SQLite3
LOCAL_SRC_FILES += deps/Android/sqlite/sqlite3.c

LOCAL_STATIC_LIBRARIES += Curl Freetype Irrlicht OpenAL mbedTLS mbedx509 mbedcrypto Vorbis LuaJIT android_native_app_glue $(PROFILER_LIBS) #LevelDB
LOCAL_STATIC_LIBRARIES += Curl Freetype Irrlicht OpenAL mbedTLS mbedx509 mbedcrypto Vorbis LuaJIT GetText android_native_app_glue $(PROFILER_LIBS) #LevelDB

LOCAL_LDLIBS := -lEGL -lGLESv1_CM -lGLESv2 -landroid -lOpenSLES

Expand Down
4 changes: 4 additions & 0 deletions src/gettext.cpp
Expand Up @@ -127,6 +127,10 @@ void init_gettext(const char *path, const std::string &configured_language,
// Add user specified locale to environment
setenv("LANGUAGE", configured_language.c_str(), 1);

#ifdef __ANDROID__
setenv("LANG", configured_language.c_str(), 1);
#endif

// Reload locale with changed environment
setlocale(LC_ALL, "");
#elif defined(_MSC_VER)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/modalMenu.cpp
Expand Up @@ -268,7 +268,7 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
std::string label = wide_to_utf8(getLabelByID(hovered->getID()));
if (label.empty())
label = "text";
message += gettext(label) + ":";
message += strgettext(label) + ":";

// single line text input
int type = 2;
Expand Down
1 change: 1 addition & 0 deletions src/porting_android.cpp
Expand Up @@ -190,6 +190,7 @@ void initializePathsAndroid()

path_user = path_storage + DIR_DELIM + PROJECT_NAME_C;
path_share = path_storage + DIR_DELIM + PROJECT_NAME_C;
path_locale = path_share + DIR_DELIM + "locale";
path_cache = getAndroidPath(nativeActivity,
app_global->activity->clazz, mt_getAbsPath, "getCacheDir");
migrateCachePath();
Expand Down

0 comments on commit c6eddb0

Please sign in to comment.