Skip to content

Commit ac38225

Browse files
committed
Merge branch 'release-2.16.6' into release
2 parents ccb7575 + 07a99fe commit ac38225

File tree

11 files changed

+124
-25
lines changed

11 files changed

+124
-25
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Issues with these labels are a great place to start!
5353
- [Need Steps to Reproduce](https://github.com/processing/p5.js-web-editor/labels/Needs%20Steps%20to%20Reproduce)
5454
- [Ready for Work](https://github.com/processing/p5.js-web-editor/labels/Ready%20for%20Work)
5555

56-
A breakdown of what each label means can be found in the [Preparing an Issue Guide](#preparing-an-issue).
56+
A breakdown of what each label means can be found in the [Preparing an Issue Guide](../contributor_docs/preparing_an_issue.md).
5757

5858
When approaching these issues, know that it's okay to not know how to fix an issue! Feel free to ask questions about to approach the problem. We are all here to learn and make something awesome. Someone from the community will help you out, and asking questions is a great way to learn about the p5.js editor, its file structure, and development process.
5959

@@ -83,7 +83,7 @@ Before submitting a pull request, make sure that:
8383
---
8484

8585
## Ideas for Getting Started
86-
* Use the [p5.js Editor](https://editor.p5js.org)! Find a bug? Think of something you think would add to the project? Reference the [Preparing an Issue Guide](#preparing-an-issue) and open an issue.
86+
* Use the [p5.js Editor](https://editor.p5js.org)! Find a bug? Think of something you think would add to the project? Reference the [Preparing an Issue Guide](../contributor_docs/preparing_an_issue.md) and open an issue.
8787
* Expand an existing issue. Sometimes issues are missing steps to reproduce, or need suggestions for potential solutions. Sometimes they need another voice saying, "this is really important!"
8888
* Try getting the project running locally on your computer by following the [installation steps](./../contributor_docs/installation.md).
8989
* Look through the documentation in the [developer docs](../contributor_docs/) and the [development guide](./../contributor_docs/development.md). Is there anything that could be expanded? Is there anything missing?

client/i18n.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
enIN
2222
} from 'date-fns/locale';
2323

24+
import getPreferredLanguage from './utils/language-utils';
25+
2426
const fallbackLng = ['en-US'];
2527

2628
export const availableLanguages = [
@@ -42,6 +44,21 @@ export const availableLanguages = [
4244
'ur'
4345
];
4446

47+
const detectedLanguage = getPreferredLanguage(
48+
availableLanguages,
49+
fallbackLng[0]
50+
);
51+
52+
let initialLanguage = detectedLanguage;
53+
54+
// if user has a saved preference (e.g., from redux or window.__INITIAL_STATE__), use that
55+
if (
56+
window.__INITIAL_STATE__?.preferences?.language &&
57+
availableLanguages.includes(window.__INITIAL_STATE__.preferences.language)
58+
) {
59+
initialLanguage = window.__INITIAL_STATE__.preferences.language;
60+
}
61+
4562
export function languageKeyToLabel(lang) {
4663
const languageMap = {
4764
be: 'বাংলা',
@@ -104,7 +121,7 @@ i18n
104121
// .use(LanguageDetector)// to detect the language from currentBrowser
105122
.use(Backend) // to fetch the data from server
106123
.init({
107-
lng: 'en-US',
124+
lng: initialLanguage,
108125
fallbackLng, // if user computer language is not on the list of available languages, than we will be using the fallback language specified earlier
109126
debug: false,
110127
backend: options,

client/modules/IDE/components/Header/Nav.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ const AuthenticatedUserMenu = () => {
378378
{t('Nav.Auth.MyAssets')}
379379
</MenubarItem>
380380
<MenubarItem id="account-settings" href="/account">
381-
{t('Preferences.Settings')}
381+
{t('Nav.Auth.MyAccount')}
382382
</MenubarItem>
383383
<MenubarItem id="account-logout" onClick={() => dispatch(logoutUser())}>
384384
{t('Nav.Auth.LogOut')}

client/modules/IDE/hooks/useP5Version.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const p5Versions = [
1212
'2.0.2',
1313
'2.0.1',
1414
'2.0.0',
15+
'1.11.8',
1516
'1.11.7',
1617
'1.11.6',
1718
'1.11.5',

client/modules/IDE/reducers/preferences.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as ActionTypes from '../../../constants';
2+
import i18n from '../../../i18n';
23

34
export const initialState = {
45
tabIndex: 0,
@@ -11,7 +12,7 @@ export const initialState = {
1112
gridOutput: false,
1213
theme: 'light',
1314
autorefresh: false,
14-
language: 'en-US',
15+
language: i18n.language,
1516
autocloseBracketsQuotes: true,
1617
autocompleteHinter: false
1718
};

client/modules/User/components/AccountForm.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function AccountForm() {
176176
</Field>
177177
)}
178178
<Button type="submit" disabled={submitting || invalid}>
179-
{t('AccountForm.SubmitSaveAllSettings')}
179+
{t('AccountForm.SaveAccountDetails')}
180180
</Button>
181181
</form>
182182
)}

client/modules/User/components/AccountForm.unit.test.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ describe('<AccountForm />', () => {
6161
it('handles form submission and calls updateSettings', async () => {
6262
subject();
6363

64-
const saveAllSettingsButton = screen.getByRole('button', {
65-
name: /save all settings/i
64+
const saveAccountDetailsButton = screen.getByRole('button', {
65+
name: /save account details/i
6666
});
6767

6868
const currentPasswordElement = screen.getByLabelText(/current password/i);
@@ -81,7 +81,7 @@ describe('<AccountForm />', () => {
8181
});
8282

8383
await act(async () => {
84-
fireEvent.click(saveAllSettingsButton);
84+
fireEvent.click(saveAccountDetailsButton);
8585
});
8686

8787
await waitFor(() => {
@@ -92,8 +92,8 @@ describe('<AccountForm />', () => {
9292
it('Save all setting button should get disabled while submitting and enable when not submitting', async () => {
9393
subject();
9494

95-
const saveAllSettingsButton = screen.getByRole('button', {
96-
name: /save all settings/i
95+
const saveAccountDetailsButton = screen.getByRole('button', {
96+
name: /save account details/i
9797
});
9898

9999
const currentPasswordElement = screen.getByLabelText(/current password/i);
@@ -110,12 +110,12 @@ describe('<AccountForm />', () => {
110110
value: 'newPassword'
111111
}
112112
});
113-
expect(saveAllSettingsButton).not.toHaveAttribute('disabled');
113+
expect(saveAccountDetailsButton).not.toHaveAttribute('disabled');
114114

115115
await act(async () => {
116-
fireEvent.click(saveAllSettingsButton);
116+
fireEvent.click(saveAccountDetailsButton);
117117
await waitFor(() => {
118-
expect(saveAllSettingsButton).toHaveAttribute('disabled');
118+
expect(saveAccountDetailsButton).toHaveAttribute('disabled');
119119
});
120120
});
121121
});

client/utils/language-utils.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Utility functions for language detection and handling
3+
*/
4+
5+
function getPreferredLanguage(supportedLanguages = [], defaultLanguage = 'en') {
6+
if (typeof navigator === 'undefined') {
7+
return defaultLanguage;
8+
}
9+
10+
const normalizeLanguage = (langCode) => langCode.toLowerCase().trim();
11+
12+
const normalizedSupported = supportedLanguages.map(normalizeLanguage);
13+
14+
if (navigator.languages && navigator.languages.length) {
15+
const matchedLang = navigator.languages.find((browserLang) => {
16+
const normalizedBrowserLang = normalizeLanguage(browserLang);
17+
18+
const hasExactMatch =
19+
normalizedSupported.findIndex(
20+
(lang) => lang === normalizedBrowserLang
21+
) !== -1;
22+
23+
if (hasExactMatch) {
24+
return true;
25+
}
26+
27+
const languageOnly = normalizedBrowserLang.split('-')[0];
28+
const hasLanguageOnlyMatch =
29+
normalizedSupported.findIndex(
30+
(lang) => lang === languageOnly || lang.startsWith(`${languageOnly}-`)
31+
) !== -1;
32+
33+
return hasLanguageOnlyMatch;
34+
});
35+
36+
if (matchedLang) {
37+
const normalizedMatchedLang = normalizeLanguage(matchedLang);
38+
const exactMatchIndex = normalizedSupported.findIndex(
39+
(lang) => lang === normalizedMatchedLang
40+
);
41+
42+
if (exactMatchIndex !== -1) {
43+
return supportedLanguages[exactMatchIndex];
44+
}
45+
46+
const languageOnly = normalizedMatchedLang.split('-')[0];
47+
const languageOnlyMatchIndex = normalizedSupported.findIndex(
48+
(lang) => lang === languageOnly || lang.startsWith(`${languageOnly}-`)
49+
);
50+
51+
if (languageOnlyMatchIndex !== -1) {
52+
return supportedLanguages[languageOnlyMatchIndex];
53+
}
54+
}
55+
}
56+
57+
if (navigator.language) {
58+
const normalizedNavLang = normalizeLanguage(navigator.language);
59+
const exactMatchIndex = normalizedSupported.findIndex(
60+
(lang) => lang === normalizedNavLang
61+
);
62+
63+
if (exactMatchIndex !== -1) {
64+
return supportedLanguages[exactMatchIndex];
65+
}
66+
67+
const languageOnly = normalizedNavLang.split('-')[0];
68+
const languageOnlyMatchIndex = normalizedSupported.findIndex(
69+
(lang) => lang === languageOnly || lang.startsWith(`${languageOnly}-`)
70+
);
71+
72+
if (languageOnlyMatchIndex !== -1) {
73+
return supportedLanguages[languageOnlyMatchIndex];
74+
}
75+
}
76+
77+
return defaultLanguage;
78+
}
79+
80+
export default getPreferredLanguage;

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "p5.js-web-editor",
3-
"version": "2.16.5",
3+
"version": "2.16.6",
44
"description": "The web editor for p5.js.",
55
"scripts": {
66
"clean": "rimraf dist",

translations/locales/en-US/translations.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@
367367
"CurrentPasswordARIA": "Current Password",
368368
"NewPassword": "New Password",
369369
"NewPasswordARIA": "New Password",
370-
"SubmitSaveAllSettings": "Save All Settings"
370+
"SaveAccountDetails": "Save Account Details"
371371
},
372372
"AccountView": {
373373
"SocialLogin": "Social Login",
374374
"SocialLoginDescription": "Use your GitHub or Google account to log into the p5.js Web Editor.",
375375
"Title": "p5.js Web Editor | Account Settings",
376-
"Settings": "Account Settings",
376+
"Settings": "My Account",
377377
"AccountTab": "Account",
378378
"AccessTokensTab": "Access Tokens"
379379
},

0 commit comments

Comments
 (0)