-
Notifications
You must be signed in to change notification settings - Fork 173
i18n support for sicp #3133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
yihao03
wants to merge
27
commits into
source-academy:master
Choose a base branch
from
yihao03:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
i18n support for sicp #3133
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5b990d8
added router params and button to read and change language in url
yihao03 f796bda
put textbook lang selection into local storage instead of the url
coder114514 da13343
fetch toc based on textbook's lang
coder114514 8546da1
update toc react component whenever textbook lang is changed
coder114514 32df0bd
put the lang switch at the bottom so it does not cover the toc menu
coder114514 ee2eae2
add back the toc.json in the repo as a fallback when there is an erro…
coder114514 9ed14ba
SicpToc.tsx: remove unused imports
coder114514 859f560
Merge branch 'master' into master
martin-henz f02d7dd
Merge branch 'master' into master
martin-henz eb61bfd
Merge branch 'master' into master
RichDom2185 2e63b78
Fix format
RichDom2185 62bc3dc
Refine According to RD's comments
coder114514 7356b7b
Resolve 'yarn build' Errors
coder114514 a1b188a
Merge branch 'master' into master
martin-henz 620e8ff
Merge branch 'master' into master
RichDom2185 255dc72
Update snapshots
RichDom2185 0221f4d
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 17c2745
Update conflicting snapshots post-merge
RichDom2185 276eb7c
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 b9bf2ce
Create SICP language provider
RichDom2185 daab656
Decouple language logic from UI in SiCP page
RichDom2185 1b600e9
Remove second param matcher
RichDom2185 f329360
Use SICP language provider
RichDom2185 52b4d5d
Revert SICP ToC changes and rewrite logic
RichDom2185 89fb07c
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 e1e3b66
Remove validation module from production
RichDom2185 86c2004
Update tests and snapshots
RichDom2185 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createContext, useCallback, useContext, useState } from 'react'; | ||
import { | ||
getSicpLanguageFromLocalStorage, | ||
SICP_DEFAULT_LANGUAGE, | ||
type SicpSupportedLanguage | ||
} from 'src/features/sicp/utils/SicpUtils'; | ||
|
||
type SicpLanguageContext = { | ||
sicpLanguage: SicpSupportedLanguage; | ||
setSicpLanguage: (lang: SicpSupportedLanguage) => void; | ||
}; | ||
|
||
const sicpLanguageContext = createContext<SicpLanguageContext | undefined>(undefined); | ||
|
||
export const useSicpLanguageContext = (): SicpLanguageContext => { | ||
const context = useContext(sicpLanguageContext); | ||
if (!context) { | ||
throw new Error('useSicpLanguageContext must be used inside an SicpLanguageContextProvider'); | ||
} | ||
|
||
return context; | ||
}; | ||
|
||
export const SicpLanguageContextProvider: React.FC<{ children: React.ReactNode }> = ({ | ||
children | ||
}) => { | ||
const [lang, setLang] = useState<SicpSupportedLanguage>( | ||
getSicpLanguageFromLocalStorage() ?? SICP_DEFAULT_LANGUAGE | ||
); | ||
|
||
const handleLangChange = useCallback((newLang: SicpSupportedLanguage) => { | ||
setLang(newLang); | ||
}, []); | ||
|
||
return ( | ||
<sicpLanguageContext.Provider | ||
value={{ | ||
sicpLanguage: lang, | ||
setSicpLanguage: handleLangChange | ||
}} | ||
> | ||
{children} | ||
</sicpLanguageContext.Provider> | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.