Skip to content

Commit

Permalink
Merge branch 'pr/1457' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Laské committed Jan 9, 2024
2 parents f3814c8 + 7d03948 commit 4908316
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 1,716 deletions.
1 change: 0 additions & 1 deletion activities/Implode.activity/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta charset="utf-8" />
<title>Implode 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" media="not screen and (device-width: 1200px) and (device-height: 900px)"
href="lib/sugar-web/graphics/css/sugar-96dpi.css">
<link rel="stylesheet" media="screen and (device-width: 1200px) and (device-height: 900px)"
Expand Down
22 changes: 11 additions & 11 deletions activities/Implode.activity/js/activity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["sugar-web/activity/activity", "sugar-web/env", "picoModal", "webL10n", "tutorial"], function (activity, env, picoModal, webL10n, tutorial) {
define(["sugar-web/activity/activity", "sugar-web/env", "picoModal", "l10n", "tutorial"], function (activity, env, picoModal, l10n, tutorial) {

// Manipulate the DOM only when it is ready.
requirejs(['domReady!'], function (doc) {
Expand Down Expand Up @@ -736,8 +736,8 @@ define(["sugar-web/activity/activity", "sugar-web/env", "picoModal", "webL10n",
}

function lose(){
var continue_button_title = webL10n.get("Continue");
var msg_content = webL10n.get("StuckMessage");
var continue_button_title = l10n.get("Continue");
var msg_content = l10n.get("StuckMessage");
picoModal({
content:"<div style = 'width:400px;margin-bottom:60px'>" +
"<div style='width:40vw;float:left;margin-left:20px;'>" +
Expand Down Expand Up @@ -927,7 +927,7 @@ define(["sugar-web/activity/activity", "sugar-web/env", "picoModal", "webL10n",
// 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);

// Load from datastore
if (!environment.objectId) {
Expand Down Expand Up @@ -1042,13 +1042,13 @@ define(["sugar-web/activity/activity", "sugar-web/env", "picoModal", "webL10n",

// Process localize event
window.addEventListener("localized", function() {
document.getElementById("new-game").title = webL10n.get("NewGame");
document.getElementById("replay").title = webL10n.get("Replay");
document.getElementById("undo").title = webL10n.get("Undo");
document.getElementById("redo").title = webL10n.get("Redo");
document.getElementById("easy").title = webL10n.get("Easy");
document.getElementById("medium").title = webL10n.get("Medium");
document.getElementById("hard").title = webL10n.get("Hard");
document.getElementById("new-game").title = l10n.get("NewGame");
document.getElementById("replay").title = l10n.get("Replay");
document.getElementById("undo").title = l10n.get("Undo");
document.getElementById("redo").title = l10n.get("Redo");
document.getElementById("easy").title = l10n.get("Easy");
document.getElementById("medium").title = l10n.get("Medium");
document.getElementById("hard").title = l10n.get("Hard");
});

});
Expand Down
3 changes: 3 additions & 0 deletions activities/Implode.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/Implode.activity/lib/i18next.min.js

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions activities/Implode.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;
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
define(["webL10n",
define([
"sugar-web/activity/shortcut",
"sugar-web/bus",
"sugar-web/env",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (
l10n, shortcut, bus, env, datastore, presence, icon, activitypalette) {
shortcut, bus, env, datastore, presence, icon, activitypalette) {

'use strict';

Expand All @@ -22,8 +22,6 @@ define(["webL10n",
activity.setup = function () {
bus.listen();

l10n.start();

function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
1 change: 0 additions & 1 deletion activities/Implode.activity/lib/sugar-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"volo": {
"baseUrl": "lib",
"dependencies": {
"webL10n": "github:sugarlabs/webL10n",
"mustache": "github:janl/mustache.js/0.7.2",
"text": "github:requirejs/text"
}
Expand Down
Loading

0 comments on commit 4908316

Please sign in to comment.