Skip to content

Commit

Permalink
Merge branch 'pr/1383' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Laské committed Aug 12, 2023
2 parents 78cd332 + 67edca7 commit d1f9d83
Show file tree
Hide file tree
Showing 20 changed files with 284 additions and 2,698 deletions.
8 changes: 4 additions & 4 deletions activities/Abecedarium.activity/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ enyo.kind({
file_size: 0
};
Abcd.datastore.create(metadata, function() {
requirejs(["webL10n"], function (webL10n) {
Abcd.humane.log(webL10n.get('AbecedariumImage'));
requirejs(["l10n"], function (l10n) {
Abcd.humane.log(l10n.get('AbecedariumImage'));
});
console.log("image '"+__$FC(entry.text)+"' saved in journal.")
}, imgAsDataURL);
Expand Down Expand Up @@ -165,8 +165,8 @@ enyo.kind({
file_size: 0
};
Abcd.datastore.create(metadata, function() {
requirejs(["webL10n"], function (webL10n) {
Abcd.humane.log(webL10n.get('AbecedariumSound'));
requirejs(["l10n"], function (l10n) {
Abcd.humane.log(l10n.get('AbecedariumSound'));
});
console.log("sound '"+__$FC(entry.text)+"' saved in journal.");
}, base64);
Expand Down
2 changes: 1 addition & 1 deletion activities/Abecedarium.activity/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
href="lib/sugar-web/graphics/css/sugar-96dpi.css">
<link rel="stylesheet" media="screen and (device-width: 1200px) and (device-height: 900px)"
href="lib/sugar-web/graphics/css/sugar-200dpi.css">
<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>
<link rel="stylesheet" href="css/libnotify.css">
Expand Down
4 changes: 2 additions & 2 deletions activities/Abecedarium.activity/js/activity.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


define(["sugar-web/activity/activity","sugar-web/datastore","tutorial","sugar-web/env","webL10n"], function (activity, datastore, tutorial, env, webL10n) {
define(["sugar-web/activity/activity","sugar-web/datastore","tutorial","sugar-web/env","l10n"], function (activity, datastore, tutorial, env, l10n) {
if (!Abcd) {
Abcd = {};
}
Expand All @@ -20,7 +20,7 @@ define(["sugar-web/activity/activity","sugar-web/datastore","tutorial","sugar-we
// 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);;
if (language == 'fr' || language == 'en' || language == 'es') {
Abcd.context.lang = language;
}
Expand Down
3 changes: 3 additions & 0 deletions activities/Abecedarium.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/Abecedarium.activity/lib/i18next.min.js

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions activities/Abecedarium.activity/lib/l10n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
define(['i18next.min', 'axios.min'], function (i18next, axios) {
const l10n = {};
let initialized = false;

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

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

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);
} else {
l10n.init("en");
}
i18next.changeLanguage(lang);
initialized = true;
triggerLocalizedEvent();
});
} else {
i18next.changeLanguage(lang);
initialized = true;
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",
"sugar-web/activity/shortcut",
define(["sugar-web/activity/shortcut",
"sugar-web/bus",
"sugar-web/env",
"sugar-web/datastore",
"sugar-web/presence",
"sugar-web/presence",
"sugar-web/graphics/icon",
"sugar-web/graphics/activitypalette"], function (
l10n, shortcut, bus, env, datastore, presence, icon, activitypalette) {
"sugar-web/graphics/activitypalette"],
function (shortcut, bus, env, datastore, presence, icon, activitypalette) {


'use strict';

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

l10n.start();


function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
pauseEvent.initCustomEvent('activityPause', false, false, {
Expand Down
2 changes: 1 addition & 1 deletion activities/Abecedarium.activity/lib/sugar-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"volo": {
"baseUrl": "lib",
"dependencies": {
"webL10n": "github:sugarlabs/webL10n",

"mustache": "github:janl/mustache.js/0.7.2",
"text": "github:requirejs/text"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ requirejs.config({
"sugar-web": ".",
"mustache": "lib/mustache",
"text": "lib/text",
"webL10n": "lib/webL10n"

},

// ask Require.js to load these files (all our tests)
Expand Down
2 changes: 1 addition & 1 deletion activities/Abecedarium.activity/lib/tutorial.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["webL10n"], function (l10n) {
define(["l10n"], function (l10n) {
var tutorial = {};

tutorial.start = function () {
Expand Down
Loading

0 comments on commit d1f9d83

Please sign in to comment.