Skip to content

Commit

Permalink
Merge branch 'pr/1479' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Laské committed Jan 11, 2024
2 parents 57e3052 + 43d7f1f commit 8c74992
Show file tree
Hide file tree
Showing 26 changed files with 199 additions and 1,873 deletions.
1 change: 0 additions & 1 deletion activities/MazeWeb.activity/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta charset="utf-8" />
<title>Maze Activity</title>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, viewport-fit=cover"/>
<link rel="prefetch" type="application/l10n" href="locale.ini" />
<link rel="stylesheet" href="css/introjs.css">
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<script src="lib/intro.js"></script>
Expand Down
12 changes: 6 additions & 6 deletions activities/MazeWeb.activity/js/activity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["sugar-web/activity/activity","tween","rAF","activity/directions","sugar-web/graphics/presencepalette", "sugar-web/env", "sugar-web/graphics/icon", "webL10n", "sugar-web/graphics/palette", "rot", "humane", "tutorial"], function (activity, TWEEN, rAF, directions, presencepalette, env, icon, webL10n, palette, ROT, humane, tutorial) {
define(["sugar-web/activity/activity","tween","rAF","activity/directions","sugar-web/graphics/presencepalette", "sugar-web/env", "sugar-web/graphics/icon", "l10n", "sugar-web/graphics/palette", "rot", "humane", "tutorial"], function (activity, TWEEN, rAF, directions, presencepalette, env, icon, l10n, palette, ROT, humane, tutorial) {

requirejs(['domReady!'], function (doc) {
activity.setup();
Expand All @@ -25,7 +25,7 @@ define(["sugar-web/activity/activity","tween","rAF","activity/directions","sugar
// Set current language to Sugarizer
var defaultLanguage = (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language;
var language = environment.user ? environment.user.language : defaultLanguage;
webL10n.language.code = language;
l10n.init(language);

// Shared instances
if (environment.sharedId) {
Expand Down Expand Up @@ -94,7 +94,7 @@ define(["sugar-web/activity/activity","tween","rAF","activity/directions","sugar
oponentEnded++;
var userName = msg.user.name.replace('<', '&lt;').replace('>', '&gt;');
var html = "<img style='height:30px;' src='" + generateXOLogoWithColor(msg.user.colorvalue) + "'>";
humane.log(html + webL10n.get("PlayerEndLevel",{user: userName}));
humane.log(html + l10n.get("PlayerEndLevel",{user: userName}));
break;
}

Expand All @@ -106,10 +106,10 @@ define(["sugar-web/activity/activity","tween","rAF","activity/directions","sugar
var html = "<img style='height:30px;' src='" + generateXOLogoWithColor(msg.user.colorvalue) + "'>";
if (msg.move === 1) {
oponentCount++;
humane.log(html + webL10n.get("PlayerJoin",{user: userName}));
humane.log(html + l10n.get("PlayerJoin",{user: userName}));
} else if (msg.move === -1) {
oponentCount--;
humane.log(html + webL10n.get("PlayerLeave",{user: userName}));
humane.log(html + l10n.get("PlayerLeave",{user: userName}));
}
if (isHost) {
presence.sendMessage(presence.getSharedInfo().id, {
Expand Down Expand Up @@ -464,7 +464,7 @@ define(["sugar-web/activity/activity","tween","rAF","activity/directions","sugar
});
} else {
var waitCount = (oponentCount-oponentEnded-1);
humane.log(webL10n.get((waitCount > 1 ?"PlayersWaitMany":"PlayersWaitOne"), {count: waitCount}));
humane.log(l10n.get((waitCount > 1 ?"PlayersWaitMany":"PlayersWaitOne"), {count: waitCount}));
}

}
Expand Down
3 changes: 3 additions & 0 deletions activities/MazeWeb.activity/lib/axios.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions activities/MazeWeb.activity/lib/i18next.min.js

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions activities/MazeWeb.activity/lib/l10n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
define(['i18next.min', 'axios.min'], function (i18next, axios) {
const l10n = {language: {direction: "ltr"}};

l10n.init = async (lang) => {
await i18next.init({
lng: lang,
fallbackLng: "en",
resources: {}
}).then(() => {
l10n.language.direction = i18next.dir();
l10n.switchTo(lang);
});
};

l10n.get = (key, parameter) => {
return i18next.t(key, parameter);
};

l10n.loadLanguageResource = (lang) => {
return new Promise((resolve, reject) => {
axios.get("./locales/" + lang + ".json").then((response) => {
resolve(response.data);
}).catch((error) => {
console.log("Failed to load " + lang + " language: " + error);
resolve(null); // Resolve with null to indicate failure
});
});
};

l10n.switchTo = (lang) => {
if (!i18next.hasResourceBundle(lang, "translation")) {
console.log("Loading " + lang + " language");
l10n.loadLanguageResource(lang).then((locales) => {
if (locales !== null) {
i18next.addResourceBundle(lang, "translation", locales);
i18next.changeLanguage(lang);
triggerLocalizedEvent();
} else {
l10n.init("en");
}
});
} else {
i18next.changeLanguage(lang);
triggerLocalizedEvent();
}
};


function triggerLocalizedEvent() {
const event = new Event("localized");
window.dispatchEvent(event);
};

return l10n;
});
Loading

0 comments on commit 8c74992

Please sign in to comment.