Add localization#49
Conversation
|
😍 |
# Conflicts: # src/components/Scanner/NoPermissionsModal.tsx # src/routes/About.tsx
|
@pajowu PR is ready for review ✌️ |
|
|
||
| # get all locale files and put them into an array | ||
| IFS=$'\n' | ||
| LOCALE_FILES=($(ls src/locale/*.json)) |
There was a problem hiding this comment.
I would shy away from using ls src/locale/*.json (it's weird with some file names, see this)
I would suggest to use LOCALE_FILES=(src/locale/*.json) instead, as it handles a lot of edge cases much better (and is much better to read, since you can skip the IFS parts around it)
|
|
||
| <div style={{ flexGrow: 1 }} /> | ||
| <BigBackButton content={'Zurück'} /> | ||
| <BigBackButton content="Zurück" /> |
| 'N+S': 'Nucleoprotein + Spike', | ||
| }; | ||
|
|
||
| const getReadableAntigen = (antigen: string) => antigenMap[antigen] || antigen; |
There was a problem hiding this comment.
I think you missed a translate call here?
There was a problem hiding this comment.
would consider it a technical term and not translate it
| initialValue?: JSONValue<T> | ||
| ): [typeof state, typeof setState] { | ||
| const [state, setState] = useState<T>( | ||
| () => safeJsonParse(localStorage.getItem(key)) || initialValue |
There was a problem hiding this comment.
You define defaultValue as an argument of the function safeJsonParse, but ignore it here and instead use || initialValue, which will handle edge cases such as falsy JSON values (such as null or []) differently.
I am not saying this is the wrong way, it's just something that should probably be cleaned up before merging.
| import { useNavigate, useParams } from 'react-router'; | ||
| import { get_test, TestData } from './testdata'; | ||
|
|
||
| export type JSONValue<T = any> = |
There was a problem hiding this comment.
Is this really necessary? It just evaluates to any in every place it is used in this project, or am I missing something?
# Conflicts: # .eslintrc.json # package.json # src/components/Result/TestFound.tsx # src/components/Result/TestFoundButLegalThreats.tsx # src/components/Scanner/BarcodeScannerComponent.tsx # src/components/Scanner/HowToOverlay.tsx # src/routes/About.tsx # src/routes/MoreInformation.tsx
This PR adds basic translation capabilities.
Description of change
It adds the
react-intllib to support language specific strings. It also adds ESLint rules to nudge people to replace static strings with dynamic ones. Locale strings have support for basic HTML elements (b,i,ul,p,br).The following components are introduced:
LocaleProviderwhich wraps the app and provides the correct messages for the current locale with EN as a fallback per messageTranslatewhich receives a key and optional some values and renders the appropriate textIt also adds a
useLocalehook to get the current locale and messages, all available locales, and a function to change the active locale.Furthermore it adds a shell script that can be used to e.g. check PRs for divergency in locale keys.
Related Issues
How do I test this?
Is there something controversial in your PR?
defaultMessageprops from theTranslatecomponent to force devs to add new keys to at least one locale file. This promotes locale files to be the source of truth and enabled us to diff against them to find missing translations. On the other hand, it also makes the code harder to read and understand as one has to manually look up all texts from the locale files.Github Workflow
As one cannot add GitHub workflows in a PR, maybe someone with access wants to adds this to
.github/workflows/diff-locale-keys.yml