Skip to content

Commit

Permalink
Merge branch 'pr/1416' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Laské committed Nov 28, 2023
2 parents 3be27f8 + 26cb2ae commit 1ee2cf6
Show file tree
Hide file tree
Showing 23 changed files with 322 additions and 3,189 deletions.
1 change: 0 additions & 1 deletion activities/SharedNotes.activity/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta charset="utf-8" />
<title>Shared Notes 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
12 changes: 4 additions & 8 deletions activities/SharedNotes.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", "notepalette", "zoompalette", "sugar-web/graphics/presencepalette", "humane", "tutorial", "sugar-web/env", "webL10n", "sugar-web/graphics/journalchooser", "activity/backgroundColorChooser"], function (activity, datastore, notepalette, zoompalette, presencepalette, humane, tutorial, env, l10n, journalchooser, backgroundColorChooser) {
define(["sugar-web/activity/activity", "sugar-web/datastore", "notepalette", "zoompalette", "sugar-web/graphics/presencepalette", "humane", "tutorial", "sugar-web/env", "l10n", "sugar-web/graphics/journalchooser", "activity/backgroundColorChooser"], function (activity, datastore, notepalette, zoompalette, presencepalette, humane, tutorial, env, l10n, journalchooser, backgroundColorChooser) {
var defaultColor = '#FFF29F';
var isShared = false;
var isHost = false;
Expand Down Expand Up @@ -711,16 +711,13 @@ define(["sugar-web/activity/activity", "sugar-web/datastore", "notepalette", "zo
tutorial.start(tutorial.tourInit);
}, 500);
}
var defaultLanguage = (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language;
var language = environment.user ? environment.user.language : defaultLanguage;
l10n.init(language);
});

// Handle localization
window.addEventListener('localized', function() {
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;
if (l10n_s.language.code != language) {
l10n_s.language.code = language;
};
var oldDefaultText = defaultText;
defaultText = l10n_s.get("YourNewIdea");
nodetextButton.title = l10n_s.get("nodetextTitle");
Expand Down Expand Up @@ -749,7 +746,6 @@ define(["sugar-web/activity/activity", "sugar-web/datastore", "notepalette", "zo
}
}
}
});
}, false);

// --- Cytoscape handling
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['mustache', 'webL10n', 'sugar-web/graphics/journalchooser'], function(mustache, l10n, journalchooser) {
define(['mustache', 'l10n', 'sugar-web/graphics/journalchooser'], function(mustache, l10n, journalchooser) {

function backgroundColorFill() {
featureBackgroundColor.database = [
Expand Down
2 changes: 1 addition & 1 deletion activities/SharedNotes.activity/js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ requirejs.config({

requirejs(["activity/activity"]);

requirejs(["webL10n","sugar-web/env","sugar-web/datastore"], function(l10n, env,datastore) {
requirejs(["l10n","sugar-web/env","sugar-web/datastore"], function(l10n, env,datastore) {
l10n_s = l10n;
});
4 changes: 4 additions & 0 deletions activities/SharedNotes.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/SharedNotes.activity/lib/i18next.min.js

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions activities/SharedNotes.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,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,8 +20,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/SharedNotes.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 1ee2cf6

Please sign in to comment.