mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-22 04:54:18 +00:00
✨ Highlight missing localizations
This commit is contained in:
parent
9954d8af1d
commit
1520e42070
3 changed files with 36 additions and 3 deletions
|
@ -9,7 +9,7 @@
|
||||||
* "{number} km radius"
|
* "{number} km radius"
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
const LOCALIZATION = {
|
export default {
|
||||||
// 🇮🇹
|
// 🇮🇹
|
||||||
it: {
|
it: {
|
||||||
appName: "N.E.S.T.",
|
appName: "N.E.S.T.",
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import React from "react"
|
import React, { useCallback } from "react"
|
||||||
import useLocalStorageState from "../../hooks/useLocalStorageState"
|
import useLocalStorageState from "../../hooks/useLocalStorageState"
|
||||||
import ContextLanguage from "../../contexts/ContextLanguage"
|
import ContextLanguage from "../../contexts/ContextLanguage"
|
||||||
import LocalizationStrings from "../../LocalizationStrings"
|
import LocalizationStrings from "../../LocalizationStrings"
|
||||||
|
import Style from "./GlobalLanguage.module.css"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +17,29 @@ import LocalizationStrings from "../../LocalizationStrings"
|
||||||
export default function GlobalLanguage({ children }) {
|
export default function GlobalLanguage({ children }) {
|
||||||
const [lang, setLang] = useLocalStorageState("language", "it")
|
const [lang, setLang] = useLocalStorageState("language", "it")
|
||||||
|
|
||||||
const strings = LocalizationStrings[lang]
|
const getString = useCallback(
|
||||||
|
(target, name) => {
|
||||||
|
const languageStrings = LocalizationStrings[lang]
|
||||||
|
const defaultStrings = LocalizationStrings["it"]
|
||||||
|
|
||||||
|
if(languageStrings.hasOwnProperty(name)) {
|
||||||
|
return languageStrings[name]
|
||||||
|
}
|
||||||
|
else if(defaultStrings.hasOwnProperty(name)) {
|
||||||
|
console.warn("Missing ", lang, " localization for string ", name)
|
||||||
|
return <i className={Style.MissingLocalization}>{defaultStrings[name]}</i>
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.warn("Missing string ", name)
|
||||||
|
return <i className={Style.MissingString}>MISSING STRING</i>
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[lang]
|
||||||
|
)
|
||||||
|
|
||||||
|
const strings = new Proxy({}, {get: getString})
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContextLanguage.Provider value={{ lang, setLang, strings }}>
|
<ContextLanguage.Provider value={{ lang, setLang, strings }}>
|
||||||
|
|
10
nest_frontend/components/providers/GlobalLanguage.module.css
Normal file
10
nest_frontend/components/providers/GlobalLanguage.module.css
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
.MissingLocalization {
|
||||||
|
background-color: darkorange;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.MissingString {
|
||||||
|
background-color: red;
|
||||||
|
color: white;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
Loading…
Reference in a new issue