-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for dictionary and use in Welcome page (#2819)
- Loading branch information
1 parent
3b8909e
commit 74b1527
Showing
5 changed files
with
70 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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,14 @@ | ||
export default { | ||
aboutBruno: 'Opensource IDE for exploring and testing APIs', | ||
collections: 'Collections', | ||
createCollection: 'Create Collection', | ||
openCollection: 'Open Collection', | ||
importCollection: 'Import Collection', | ||
documentation: 'Documentation', | ||
reportIssues: 'Report Issues', | ||
gitHub: 'GitHub', | ||
collectionImportedSuccessfully: 'Collection imported successfully', | ||
errorWhileOpeningCollection: 'An error occurred while opening the collection', | ||
errorWhileImportingCollection: | ||
'An error occurred while importing the collection. Check the logs for more information.' | ||
}; |
This file contains 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,5 @@ | ||
import en from './en.js'; | ||
|
||
export const dictionaries = { | ||
en | ||
}; |
This file contains 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 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,28 @@ | ||
import React from 'react'; | ||
import { useState, useContext } from 'react'; | ||
import { dictionaries } from 'src/dictionaries/index'; | ||
|
||
export const DictionaryContext = React.createContext(); | ||
|
||
const DictionaryProvider = (props) => { | ||
const [language, setLanguage] = useState('en'); | ||
const dictionary = dictionaries[language] ?? dictionaries.en; | ||
|
||
return ( | ||
<DictionaryContext.Provider {...props} value={{ language, setLanguage, dictionary }}> | ||
<>{props.children}</> | ||
</DictionaryContext.Provider> | ||
); | ||
}; | ||
|
||
const useDictionary = () => { | ||
const context = useContext(DictionaryContext); | ||
|
||
if (context === undefined) { | ||
throw new Error(`useDictionary must be used within a DictionaryProvider`); | ||
} | ||
|
||
return context; | ||
}; | ||
|
||
export { useDictionary, DictionaryProvider }; |