Try to make l10n work again in the iOS app

In real Online, after recent commits localisation of messages in our
JavaScript is handled in the FileServer code. Calls to the _ function
in JavaScript being served are replaced with the translated string. We
can't do that in the mobile apps (without some re-work, and I doubt we
want to spend time on that now, there are more pressing problems). In
real Online, the _ function in global.js thus actually dead code.

But in the mobile apps, we don't have any FileServer, and we do want
the _ function to work as before, and we do want to include the
l10n-all.js file in the bundle.js.

Of course, if profiling eventually indicates that doing that *is* a
problem from performance and/or memory usage point of view, we do need
to re-work this. But for now I just want things to roughly work as
they did in the iOS app.

Change-Id: Ib77020010867e7aabaf68bbb892d150d15708213
This commit is contained in:
Tor Lillqvist 2019-03-06 14:17:53 +02:00
parent 97970bc081
commit 318efba053
2 changed files with 13 additions and 10 deletions

View file

@ -138,7 +138,6 @@ LANGUAGES = \
if ENABLE_IOSAPP
L10N_IOS_ALL_JS = $(builddir)/dist/l10n-all.js
L10N_JSON = $(L10N_IOS_ALL_JS)
$(L10N_IOS_ALL_JS) : $(wildcard $(srcdir)/po/ui-*.po) $(shell find $(srcdir)/l10n -name '*.*')
for F in $(wildcard $(srcdir)/po/ui-*.po); do \
@ -265,6 +264,7 @@ ADMIN_BUNDLE = $(builddir)/dist/admin-bundle.js
endif
build-loleaflet: | \
$(L10N_IOS_ALL_JS) \
$(LOLEAFLET_MO_DST) \
$(LOLEAFLET_IMAGES_DST) \
$(JQUERY_LIGHTNESS_DIST_IMAGES) \
@ -348,6 +348,7 @@ $(builddir)/dist/bundle.js: $(NODE_MODULES_JS_SRC) \
$(srcdir)/js/main.js
@echo "Uglify loleaflet js files..."
NODE_PATH=$(abs_builddir)/node_modules $(NODE) node_modules/uglify-js/bin/uglifyjs \
$(L10N_IOS_ALL_JS) \
$(NODE_MODULES_JS) \
$(srcdir)/js/jquery.mCustomScrollbar.js \
$(srcdir)/js/w2ui-1.5.rc1.js \

View file

@ -53,9 +53,11 @@
String.locale = 'en';
}
global._ = function (string) {
// In the mobile app case we can't use the stuff from l10n-for-node, as that assumes HTTP.
if (window.ThisIsTheiOSApp) {
// In the mobile app case we don't use any "server-side" localisation. For real Online, what
// looks like calls to a _ function are in fact replaced by Online's file server with the
// translation.
if (window.ThisIsTheiOSApp) {
global._ = function (string) {
// We use another approach just for iOS for now.
if (window.LOCALIZATIONS.hasOwnProperty(string)) {
// window.postMobileDebug('_(' + string + '): YES: ' + window.LOCALIZATIONS[string]);
@ -68,13 +70,13 @@
// window.postMobileDebug('_(' + string + '): NO');
return string;
}
} else if (window.ThisIsAMobileApp) {
// And bail out without translations on other mobile platforms.
return string;
} else {
return string.toLocaleString();
}
};
} else if (window.ThisIsAMobileApp) {
// Bail out without translations on other mobile platforms for now.
global._ = function (string) {
return string;
}
}
var docParams, wopiParams;
var filePath = global.getParameterByName('file_path');