Skip to content

Commit c6eddb0

Browse files
Pevernowsfan5oleastre
authoredAug 8, 2021
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>
1 parent 4a3728d commit c6eddb0

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed
 

‎.github/workflows/android.yml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
uses: actions/setup-java@v1
2929
with:
3030
java-version: 1.8
31+
- name: Install deps
32+
run: sudo apt-get update; sudo apt-get install -y --no-install-recommends gettext
3133
- name: Build with Gradle
3234
run: cd android; ./gradlew assemblerelease
3335
- name: Save armeabi artifact

‎android/app/build.gradle

+7-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ task prepareAssets() {
7676
copy {
7777
from "${projRoot}/games/${gameToCopy}" into "${assetsFolder}/games/${gameToCopy}"
7878
}
79-
/*copy {
80-
// ToDo: fix broken locales
81-
from "${projRoot}/po" into "${assetsFolder}/po"
82-
}*/
79+
fileTree("${projRoot}/po").include("**/*.po").forEach { poFile ->
80+
def moPath = "${assetsFolder}/locale/${poFile.parentFile.name}/LC_MESSAGES/"
81+
file(moPath).mkdirs()
82+
exec {
83+
commandLine 'msgfmt', '-o', "${moPath}/minetest.mo", poFile
84+
}
85+
}
8386
copy {
8487
from "${projRoot}/textures" into "${assetsFolder}/textures"
8588
}

‎android/native/jni/Android.mk

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ LOCAL_MODULE := OpenAL
4747
LOCAL_SRC_FILES := deps/Android/OpenAL-Soft/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libopenal.a
4848
include $(PREBUILT_STATIC_LIBRARY)
4949

50+
include $(CLEAR_VARS)
51+
LOCAL_MODULE := GetText
52+
LOCAL_SRC_FILES := deps/Android/GetText/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libintl.a
53+
include $(PREBUILT_STATIC_LIBRARY)
54+
5055
include $(CLEAR_VARS)
5156
LOCAL_MODULE := Vorbis
5257
LOCAL_SRC_FILES := deps/Android/Vorbis/${NDK_TOOLCHAIN_VERSION}/$(APP_ABI)/libvorbis.a
@@ -64,6 +69,7 @@ LOCAL_CFLAGS += \
6469
-DUSE_FREETYPE=1 \
6570
-DUSE_LEVELDB=0 \
6671
-DUSE_LUAJIT=1 \
72+
-DUSE_GETTEXT=1 \
6773
-DVERSION_MAJOR=${versionMajor} \
6874
-DVERSION_MINOR=${versionMinor} \
6975
-DVERSION_PATCH=${versionPatch} \
@@ -89,6 +95,7 @@ LOCAL_C_INCLUDES := \
8995
deps/Android/Freetype/include \
9096
deps/Android/Irrlicht/include \
9197
deps/Android/LevelDB/include \
98+
deps/Android/GetText/include \
9299
deps/Android/libiconv/include \
93100
deps/Android/libiconv/libcharset/include \
94101
deps/Android/LuaJIT/src \
@@ -194,7 +201,7 @@ LOCAL_SRC_FILES += \
194201
# SQLite3
195202
LOCAL_SRC_FILES += deps/Android/sqlite/sqlite3.c
196203

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

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

‎src/gettext.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ void init_gettext(const char *path, const std::string &configured_language,
127127
// Add user specified locale to environment
128128
setenv("LANGUAGE", configured_language.c_str(), 1);
129129

130+
#ifdef __ANDROID__
131+
setenv("LANG", configured_language.c_str(), 1);
132+
#endif
133+
130134
// Reload locale with changed environment
131135
setlocale(LC_ALL, "");
132136
#elif defined(_MSC_VER)

‎src/gui/modalMenu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
268268
std::string label = wide_to_utf8(getLabelByID(hovered->getID()));
269269
if (label.empty())
270270
label = "text";
271-
message += gettext(label) + ":";
271+
message += strgettext(label) + ":";
272272

273273
// single line text input
274274
int type = 2;

‎src/porting_android.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ void initializePathsAndroid()
190190

191191
path_user = path_storage + DIR_DELIM + PROJECT_NAME_C;
192192
path_share = path_storage + DIR_DELIM + PROJECT_NAME_C;
193+
path_locale = path_share + DIR_DELIM + "locale";
193194
path_cache = getAndroidPath(nativeActivity,
194195
app_global->activity->clazz, mt_getAbsPath, "getCacheDir");
195196
migrateCachePath();

0 commit comments

Comments
 (0)
Please sign in to comment.