Skip to content

Commit

Permalink
Merge branch 'pr/1401' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Laské committed Oct 1, 2023
2 parents 089c88b + 8594e0c commit fb8c8ab
Show file tree
Hide file tree
Showing 22 changed files with 285 additions and 2,833 deletions.
1 change: 0 additions & 1 deletion activities/Fototoon.activity/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
href="lib/sugar-web/graphics/css/sugar-200dpi.css">
<link rel="stylesheet" href="css/activity.css">
<link rel="stylesheet" href="css/libnotify.css">
<link rel="prefetch" type="application/l10n" href="localization.ini">

<link rel="stylesheet" href="css/introjs.css">
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
Expand Down
6 changes: 3 additions & 3 deletions activities/Fototoon.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/datastore","sugar-web/env","textpalette","sugar-web/graphics/menupalette","sugar-web/graphics/journalchooser","lzstring","webL10n","toon","tutorial", "picoModal"], function (activity, datastore, env, textpalette, menupalette, journalchooser, lzstring, l10n, toon, tutorial, picoModal) {
define(["sugar-web/activity/activity","sugar-web/datastore","sugar-web/env","textpalette","sugar-web/graphics/menupalette","sugar-web/graphics/journalchooser","lzstring","l10n","toon","tutorial", "picoModal"], function (activity, datastore, env, textpalette, menupalette, journalchooser, lzstring, l10n, toon, tutorial, picoModal) {


// initialize canvas size
Expand All @@ -9,7 +9,7 @@ define(["sugar-web/activity/activity","sugar-web/datastore","sugar-web/env","tex
env.getEnvironment(function(err, environment) {
var defaultLanguage = (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language;
language = environment.user ? environment.user.language : defaultLanguage;
l10n.language.code = language;
l10n.init(language);
console.log('LANG ' + language);
});

Expand Down Expand Up @@ -271,7 +271,7 @@ define(["sugar-web/activity/activity","sugar-web/datastore","sugar-web/env","tex

// Launch tutorial
document.getElementById("help-button").addEventListener('click', function(e) {
l10n.language.code=language;
l10n.init(language);
var once=1;
window.addEventListener("localized", function() {
if (once) {
Expand Down
4 changes: 2 additions & 2 deletions activities/Fototoon.activity/js/toon.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
define(["easel","sugar-web/datastore","sugar-web/env","webL10n","humane"], function (easel, datastore, env, l10n, humane) {
define(["easel","sugar-web/datastore","sugar-web/env","l10n","humane"], function (easel, datastore, env, l10n, humane) {


env.getEnvironment(function(err, environment) {
var defaultLanguage = (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language;
var language = environment.user ? environment.user.language : defaultLanguage;
l10n.language.code = language;
l10n.init(language);
console.log('LANG ' + language);
});

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

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions activities/Fototoon.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,10 @@
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/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,7 +20,6 @@ define(["webL10n",
activity.setup = function () {
bus.listen();

l10n.start();

function sendPauseEvent() {
var pauseEvent = document.createEvent("CustomEvent");
Expand Down
2 changes: 1 addition & 1 deletion activities/Fototoon.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
2 changes: 1 addition & 1 deletion activities/Fototoon.activity/lib/sugar-web/test/loader.js
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/Fototoon.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 (language) {
Expand Down
Loading

0 comments on commit fb8c8ab

Please sign in to comment.