Using App Connect with JavaScript Functions

I am trying to figure out if integrating i18next library is worth the time or if I should go the custom route

I can’t manage to parse an AC variable into a JS object.

<!DOCTYPE html>
<html lang="en">

<head>
	<base href="/">
	<script src="dmxAppConnect/dmxAppConnect.js"></script>
	<script src="https://unpkg.com/i18next/dist/umd/i18next.min.js"></script>
	<script>
		i18next.init({
		interpolation: {
			prefix : '**',
			suffix : '**'
		},
		lng: 'en',
		debug: true,
		resources: {
			en: {
				translation: {
					"key": "**what** has **count** oranges"
				}
			}
		}
	}).then(dmx.Formatter('string', 't', function (key, temp) {
		return i18next.t(key, temp);
	}));
	</script>
</head>

<body is="dmx-app" id="i18ntest">

	<dmx-value id="count" dmx-bind:value="20"></dmx-value>
	<dmx-value id="name" dmx-bind:value="'Lisa Smith'"></dmx-value>

	<p>{{ "key".t({ what: "Lisa"+" Smith", count: 10+10}) }}</p>
	<p>{{ "key".t({ what: dmx.parse('name.value'), count: dmx.parse('count.value')}) }}</p>

	<script>
		var callback = function(){
		console.log(dmx.parse("name.value")+" and "+dmx.parse('count.value'));
		};

		if (
			document.readyState === "complete" ||
			(document.readyState !== "loading" && !document.documentElement.doScroll)
		) {
		callback();
		} 
		else {
			document.addEventListener("DOMContentLoaded", callback);
		}		
	</script>

	<script>
		console.log(dmx.parse("name.value")+" and "+dmx.parse('count.value'));
	</script>

</body>
</html>

Will render on page:

image

Will output to console:

Clearly dmx.parse needs to wait for the page to be ready to be useful.

Any solution so I can send AC bindings to the i18next library as parameters?

i18ntest.php.zip (1.2 KB)