[Libreoffice-commits] online.git: loleaflet/js loleaflet/Makefile.am loleaflet/util
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Nov 12 20:58:08 UTC 2018
loleaflet/Makefile.am | 22 ++++++
loleaflet/js/global.js | 13 +++
loleaflet/util/create-l10n-all-js.pl | 114 +++++++++++++++++++++++++++++++++++
3 files changed, 146 insertions(+), 3 deletions(-)
New commits:
commit 6d2a60643b93a5652ebe8e87f8d7a9c8982999d2
Author: Tor Lillqvist <tml at collabora.com>
AuthorDate: Fri Nov 9 22:28:46 2018 +0200
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Mon Nov 12 22:55:03 2018 +0200
Make l10n of the messages from our JS code work in the mobile app
The l10n-for-node code does not work in the app. Instead of loading
the required JSON files at run-time, include all those translations
that seem complete enough as JavaScript code in the bundle.js. Use a
manaully curated list of translations, in a Perl script that generates
the JavaScript code in question.
Change-Id: I45d5cda477140ee63bb3fc8d9f1f4260bcdb97a7
diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index 9b61070c2..25db749f6 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -3,9 +3,26 @@ DRAW_VERSION=0.2.4
L10N_PO = $(wildcard $(srcdir)/po/*.po)
+if !ENABLE_IOSAPP
if !ENABLE_GTKAPP
L10N_JSON = $(patsubst $(srcdir)/po/%.po,$(builddir)/dist/l10n/%.json,$(L10N_PO))
endif
+endif
+
+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 \
+ $(srcdir)/util/po2json.py $$F -o $$F.json; \
+ done
+ @mkdir -p $(dir $@)
+ perl $(srcdir)/util/create-l10n-all-js.pl >$@
+ for F in $(wildcard $(srcdir)/po/ui-*.po); do \
+ rm $$F.json; \
+ done
+endif
JQUERY_UI_IMAGE_PATH = node_modules/jquery-ui/themes/ui-lightness/images
JQUERY_UI_IMAGES = $(wildcard $(JQUERY_UI_IMAGE_PATH)/*.png)
@@ -15,7 +32,9 @@ LOLEAFLET_IMAGES_SRC = $(shell find $(srcdir)/images -name '*.*')
LOLEAFLET_IMAGES_DST = $(patsubst $(srcdir)/%,$(builddir)/dist/%,$(LOLEAFLET_IMAGES_SRC))
LOLEAFLET_L10N_SRC = $(shell find $(srcdir)/l10n -name '*.*')
+if !ENABLE_IOSAPP
LOLEAFLET_L10N_DST = $(patsubst $(srcdir)/l10n/%,$(builddir)/dist/l10n/%,$(LOLEAFLET_L10N_SRC))
+endif
LOLEAFLET_DRAW_JS_SRC = $(shell find $(srcdir)/plugins/draw-$(DRAW_VERSION)/src -name '*.js')
LOLEAFLET_DRAW_JS_DST = $(patsubst $(srcdir)/plugins/%.js,$(builddir)/dist/plugins/%.js,$(LOLEAFLET_DRAW_JS_SRC))
@@ -186,8 +205,9 @@ $(builddir)/dist/bundle.js: $(NODE_MODULES_JS_SRC) \
$(srcdir)/js/toolbar.js \
$(srcdir)/js/main.js
@echo "Uglify loleaflet js files..."
- @NODE_PATH=$(abs_builddir)/node_modules $(NODE) node_modules/uglify-js/bin/uglifyjs \
+ NODE_PATH=$(abs_builddir)/node_modules $(NODE) node_modules/uglify-js/bin/uglifyjs \
$(srcdir)/js/global.js \
+ $(L10N_IOS_ALL_JS) \
$(NODE_MODULES_JS) \
$(srcdir)/js/w2ui-1.5.rc1.js \
$(builddir)/build/dist/loleaflet-src.js \
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index 9640a44dd..a0e4c2ce1 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -30,8 +30,17 @@ global.getParameterByName = function (name) {
global._ = function (string) {
// In the mobile app case we can't use the stuff from l10n-for-node, as that assumes HTTP.
- // So bail out for now.
- if (window.ThisIsAMobileApp) {
+ if (window.ThisIsTheiOSApp) {
+ // We use another approach just for iOS for now.
+ if (window.LOCALIZATIONS.hasOwnProperty(string)) {
+ // window.webkit.messageHandlers.debug.postMessage('_(' + string + '): YES: ' + window.LOCALIZATIONS[string]);
+ return window.LOCALIZATIONS[string];
+ } else {
+ // window.webkit.messageHandlers.debug.postMessage('_(' + string + '): NO');
+ return string;
+ }
+ } else if (window.ThisIsAMobileApp) {
+ // And bail out without translations on other mobile platforms.
return string;
} else {
return string.toLocaleString();
diff --git a/loleaflet/util/create-l10n-all-js.pl b/loleaflet/util/create-l10n-all-js.pl
new file mode 100644
index 000000000..293cdb1e9
--- /dev/null
+++ b/loleaflet/util/create-l10n-all-js.pl
@@ -0,0 +1,114 @@
+#!/bin/perl -w
+
+use strict;
+
+sub readwhole($) {
+ my ($file) = @_;
+ local $/;
+ open(my $fh, '<', $file) || die "Cannot open $file";
+ return <$fh>;
+}
+
+sub insert($) {
+ my ($locale) = @_;
+ my $ui = readwhole("po/ui-$locale.po.json");
+ # Different convention: Change underscore to hyphen.
+ $locale =~ s/_/-/;
+ my $uno = readwhole("l10n/uno/$locale.json");
+ my $locore = readwhole("l10n/locore/$locale.json");
+ # Merge the fields of all three objects into one. The result of
+ # po2json.py starts with "{" not followed by a newline and ends
+ # with a "}" without any final newline. The json files that are in
+ # the repo start with "{\n" and end with "}\n".
+ return substr($ui, 0, length($ui)-1) . ",\n" . substr($uno, 2, length($uno)-4) . ",\n" . substr($locore, 2, length($locore)-3);
+}
+
+# The list of locales handled in the JavaScript we output below is
+# based on a quick glance at the sizes of the translations. Only
+# translations that are "large enough" (more complete) are included. A
+# woefully incomplete translation is worse than no translation at all.
+
+print "\
+window.LANG = window.getParameterByName('lang');
+window.webkit.messageHandlers.debug.postMessage('LANG is ' + window.LANG);
+
+var onlylang = window.LANG;
+var hyphen = onlylang.indexOf('-');
+if (hyphen > 0) {
+ onlylang = onlylang.substring(0, hyphen);
+}
+var underscore = onlylang.indexOf('_');
+if (underscore > 0) {
+ onlylang = onlylang.substring(0, underscore);
+}
+
+if (false) {
+ ;
+} else if (onlylang == 'am') {
+ window.LOCALIZATIONS = " . insert('am') . ";
+} else if (onlylang == 'ar') {
+ window.LOCALIZATIONS = " . insert('ar') . ";
+} else if (onlylang == 'bg') {
+ window.LOCALIZATIONS = " . insert('bg') . ";
+} else if (onlylang == 'ca') {
+ window.LOCALIZATIONS = " . insert('ca') . ";
+} else if (onlylang == 'cs') {
+ window.LOCALIZATIONS = " . insert('cs') . ";
+} else if (onlylang == 'cy') {
+ window.LOCALIZATIONS = " . insert('cy') . ";
+} else if (onlylang == 'da') {
+ window.LOCALIZATIONS = " . insert('da') . ";
+} else if (onlylang == 'de') {
+ window.LOCALIZATIONS = " . insert('de') . ";
+} else if (onlylang == 'el') {
+ window.LOCALIZATIONS = " . insert('el') . ";
+} else if (window.LANG == 'en_GB') {
+ window.LOCALIZATIONS = " . insert('en_GB') . ";
+} else if (onlylang == 'eo') {
+ window.LOCALIZATIONS = " . insert('eo') . ";
+} else if (onlylang == 'es') {
+ window.LOCALIZATIONS = " . insert('es') . ";
+} else if (onlylang == 'eu') {
+ window.LOCALIZATIONS = " . insert('eu') . ";
+} else if (onlylang == 'et') {
+ window.LOCALIZATIONS = " . insert('et') . ";
+} else if (onlylang == 'fr') {
+ window.LOCALIZATIONS = " . insert('fr') . ";
+} else if (onlylang == 'gd') {
+ window.LOCALIZATIONS = " . insert('gd') . ";
+} else if (onlylang == 'gl') {
+ window.LOCALIZATIONS = " . insert('gl') . ";
+} else if (onlylang == 'hr') {
+ window.LOCALIZATIONS = " . insert('hr') . ";
+} else if (onlylang == 'hu') {
+ window.LOCALIZATIONS = " . insert('hu') . ";
+} else if (onlylang == 'is') {
+ window.LOCALIZATIONS = " . insert('is') . ";
+} else if (onlylang == 'it') {
+ window.LOCALIZATIONS = " . insert('it') . ";
+} else if (onlylang == 'nb') {
+ window.LOCALIZATIONS = " . insert('nb') . ";
+} else if (onlylang == 'nl') {
+ window.LOCALIZATIONS = " . insert('nl') . ";
+} else if (onlylang == 'nn') {
+ window.LOCALIZATIONS = " . insert('nn') . ";
+} else if (window.LANG == 'pt_BR') {
+ window.LOCALIZATIONS = " . insert('pt_BR') . ";
+} else if (onlylang == 'pt') {
+ window.LOCALIZATIONS = " . insert('pt') . ";
+} else if (onlylang == 'ru') {
+ window.LOCALIZATIONS = " . insert('ru') . ";
+} else if (onlylang == 'sk') {
+ window.LOCALIZATIONS = " . insert('sk') . ";
+} else if (onlylang == 'sv') {
+ window.LOCALIZATIONS = " . insert('sv') . ";
+} else if (onlylang == 'tr') {
+ window.LOCALIZATIONS = " . insert('tr') . ";
+} else if (onlylang == 'uk') {
+ window.LOCALIZATIONS = " . insert('uk') . ";
+} else if (window.LANG == 'zh_TW') {
+ window.LOCALIZATIONS = " . insert('zh_TW') . ";
+} else {
+ window.LOCALIZATIONS = {};
+}
+";
More information about the Libreoffice-commits
mailing list