Browse Source

fix: added required i18n labels to UI

pull/671/head
Dan Ditomaso 1 year ago
parent
commit
df16cb187e
  1. 2
      src/components/Form/DynamicForm.tsx
  2. 9
      src/components/Map.tsx
  3. 4
      src/components/PageComponents/Messages/MessageInput.tsx
  4. 16
      src/components/PageComponents/Messages/MessageItem.tsx
  5. 34
      src/components/UI/Generator.tsx
  6. 130
      src/components/generic/TimeAgo.tsx
  7. 10
      src/core/hooks/useFavoriteNode.ts
  8. 6
      src/i18n/config.ts
  9. 10
      src/i18n/locales/en/common.json
  10. 11
      src/i18n/locales/en/messages.json
  11. 7
      src/i18n/locales/en/nodes.json
  12. 9
      src/i18n/locales/en/ui.json
  13. 11
      src/pages/Messages.tsx
  14. 9
      src/pages/Nodes/index.tsx

2
src/components/Form/DynamicForm.tsx

@ -208,7 +208,7 @@ export function DynamicForm<T extends FieldValues>({
variant="outline" variant="outline"
disabled={!formState.isValid} disabled={!formState.isValid}
> >
Submit {t("button.submit")}
</Button> </Button>
)} )}
</form> </form>

9
src/components/Map.tsx

@ -1,6 +1,5 @@
import MapGl, { import MapGl, {
AttributionControl, AttributionControl,
GeolocateControl,
type MapRef, type MapRef,
NavigationControl, NavigationControl,
ScaleControl, ScaleControl,
@ -45,11 +44,15 @@ export const Map = ({ children, onLoad }: MapProps) => {
color: darkMode ? "black" : undefined, color: darkMode ? "black" : undefined,
}} }}
/> />
<GeolocateControl {/* { Disabled for now until we can use i18n for the geolocate control} */}
{
/* <GeolocateControl
position="top-right" position="top-right"
i18nIsDynamicList
positionOptions={{ enableHighAccuracy: true }} positionOptions={{ enableHighAccuracy: true }}
trackUserLocation trackUserLocation
/> /> */
}
<NavigationControl position="top-right" showCompass={false} /> <NavigationControl position="top-right" showCompass={false} />
<ScaleControl /> <ScaleControl />
{children} {children}

4
src/components/PageComponents/Messages/MessageInput.tsx

@ -4,6 +4,7 @@ import type { Types } from "@meshtastic/core";
import { SendIcon } from "lucide-react"; import { SendIcon } from "lucide-react";
import { startTransition, useState } from "react"; import { startTransition, useState } from "react";
import { useMessageStore } from "@core/stores/messageStore/index.ts"; import { useMessageStore } from "@core/stores/messageStore/index.ts";
import { useTranslation } from "react-i18next";
export interface MessageInputProps { export interface MessageInputProps {
onSend: (message: string) => void; onSend: (message: string) => void;
@ -17,6 +18,7 @@ export const MessageInput = ({
maxBytes, maxBytes,
}: MessageInputProps) => { }: MessageInputProps) => {
const { setDraft, getDraft, clearDraft } = useMessageStore(); const { setDraft, getDraft, clearDraft } = useMessageStore();
const { t } = useTranslation();
const calculateBytes = (text: string) => new Blob([text]).size; const calculateBytes = (text: string) => new Blob([text]).size;
@ -59,7 +61,7 @@ export const MessageInput = ({
autoFocus autoFocus
minLength={1} minLength={1}
name="messageInput" name="messageInput"
placeholder="Enter Message" placeholder={t("messages.sendMessage.placeholder")}
autoComplete="off" autoComplete="off"
value={localDraft} value={localDraft}
onChange={handleInputChange} onChange={handleInputChange}

16
src/components/PageComponents/Messages/MessageItem.tsx

@ -56,21 +56,21 @@ export const MessageItem = ({ message }: MessageItemProps) => {
const MESSAGE_STATUS_MAP = useMemo( const MESSAGE_STATUS_MAP = useMemo(
(): Record<MessageState, MessageStatusInfo> => ({ (): Record<MessageState, MessageStatusInfo> => ({
[MessageState.Ack]: { [MessageState.Ack]: {
displayText: t("deliveryStatus.deliveryStatus."), displayText: t("deliveryStatus.delivered.displayText"),
icon: CheckCircle2, icon: CheckCircle2,
ariaLabel: t("deliveryStatus.delivered"), ariaLabel: t("deliveryStatus.delivered.label"),
iconClassName: "text-green-500", iconClassName: "text-green-500",
}, },
[MessageState.Waiting]: { [MessageState.Waiting]: {
displayText: t("deliveryStatus.waiting"), displayText: t("deliveryStatus.waiting.displayText"),
icon: CircleEllipsis, icon: CircleEllipsis,
ariaLabel: t("deliveryStatus.waiting"), ariaLabel: t("deliveryStatus.waiting.label"),
iconClassName: "text-slate-400", iconClassName: "text-slate-400",
}, },
[MessageState.Failed]: { [MessageState.Failed]: {
displayText: t("deliveryStatus.failed"), displayText: t("deliveryStatus.failed.displayText"),
icon: AlertCircle, icon: AlertCircle,
ariaLabel: t("deliveryStatus.failed"), ariaLabel: t("deliveryStatus.failed.label"),
iconClassName: "text-red-500 dark:text-red-400", iconClassName: "text-red-500 dark:text-red-400",
}, },
}), }),
@ -78,9 +78,9 @@ export const MessageItem = ({ message }: MessageItemProps) => {
); );
const UNKNOWN_STATUS = useMemo((): MessageStatusInfo => ({ const UNKNOWN_STATUS = useMemo((): MessageStatusInfo => ({
displayText: t("delveryStatus.unknown"), displayText: t("delveryStatus.unknown.displayText"),
icon: AlertCircle, icon: AlertCircle,
ariaLabel: t("deliveryStatus.unknown"), ariaLabel: t("deliveryStatus.unknown.label"),
iconClassName: "text-red-500 dark:text-red-400", iconClassName: "text-red-500 dark:text-red-400",
}), [t]); }), [t]);

34
src/components/UI/Generator.tsx

@ -8,6 +8,7 @@ import {
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@components/UI/Select.tsx"; } from "@components/UI/Select.tsx";
import { useTranslation } from "react-i18next";
export interface ActionButton { export interface ActionButton {
text: string; text: string;
@ -40,12 +41,7 @@ const Generator = (
variant, variant,
value, value,
actionButtons, actionButtons,
bits = [ bits,
{ text: "256 bit", value: "32", key: "bit256" },
{ text: "128 bit", value: "16", key: "bit128" },
{ text: "8 bit", value: "1", key: "bit8" },
{ text: "Empty", value: "0", key: "empty" },
],
selectChange, selectChange,
inputChange, inputChange,
disabled, disabled,
@ -55,6 +51,30 @@ const Generator = (
}: GeneratorProps, }: GeneratorProps,
) => { ) => {
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
const { t } = useTranslation();
const passwordRequiredBitSize = bits ? bits : [
{
text: t("security.256bit"),
value: "32",
key: "bit256",
},
{
text: t("security.128bit"),
value: "16",
key: "bit128",
},
{
text: t("security.8bit"),
value: "1",
key: "bit8",
},
{
text: t("security.empty"),
value: "0",
key: "bit0",
},
];
// Invokes onChange event on the input element when the value changes from the parent component // Invokes onChange event on the input element when the value changes from the parent component
useEffect(() => { useEffect(() => {
@ -91,7 +111,7 @@ const Generator = (
<SelectValue /> <SelectValue />
</SelectTrigger> </SelectTrigger>
<SelectContent className="w-36"> <SelectContent className="w-36">
{bits.map(({ text, value, key }) => ( {passwordRequiredBitSize.map(({ text, value, key }) => (
<SelectItem key={key} value={value} className="w-36"> <SelectItem key={key} value={value} className="w-36">
{text} {text}
</SelectItem> </SelectItem>

130
src/components/generic/TimeAgo.tsx

@ -5,49 +5,115 @@ import {
TooltipProvider, TooltipProvider,
TooltipTrigger, TooltipTrigger,
} from "@radix-ui/react-tooltip"; } from "@radix-ui/react-tooltip";
import { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
export interface TimeAgoProps { export interface TimeAgoProps {
timestamp: number; timestamp: number | Date;
locale?: string;
tooltipOptions?: Intl.DateTimeFormatOptions;
className?: string;
} }
const getTimeAgo = ( const TIME_UNITS: Array<[Intl.RelativeTimeFormatUnit, number]> = [
unixTimestamp: number, ["year", 31536000],
locale: Intl.LocalesArgument = "en", ["month", 2592000],
): string => { ["day", 86400],
const timestamp = new Date(unixTimestamp); ["hour", 3600],
const diff = (new Date().getTime() - timestamp.getTime()) / 1000; ["minute", 60],
["second", 1],
const minutes = Math.floor(diff / 60); ];
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const months = Math.floor(days / 30);
const years = Math.floor(months / 12);
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
if (years > 0) { const getRelativeTimeParts = (
return rtf.format(0 - years, "year"); date: Date | number,
} ): { value: number; unit: Intl.RelativeTimeFormatUnit } => {
if (months > 0) { const diffInSeconds = (new Date(date).getTime() - Date.now()) / 1000;
return rtf.format(0 - months, "month");
} for (const [unit, secondsInUnit] of TIME_UNITS) {
if (days > 0) { if (Math.abs(diffInSeconds) >= secondsInUnit) {
return rtf.format(0 - days, "day"); const value = Math.round(diffInSeconds / secondsInUnit);
} return { value, unit };
if (hours > 0) {
return rtf.format(0 - hours, "hour");
} }
if (minutes > 0) {
return rtf.format(0 - minutes, "minute");
} }
return rtf.format(Math.floor(0 - diff), "second");
return { value: Math.round(diffInSeconds), unit: "second" };
};
const UPDATE_INTERVALS: Partial<Record<Intl.RelativeTimeFormatUnit, number>> = {
// For long-term units, an hourly update is more than sufficient.
year: 1000 * 60 * 60,
month: 1000 * 60 * 60,
// When the unit is 'day', check hourly to catch the change to the next day.
day: 1000 * 60 * 60,
// When the unit is 'hour', check every thiry seconds to catch the change to the next hour.
hour: 1000 * 30,
// When the unit is 'minute', a 15-second check is a good balance.
minute: 1000 * 15,
// For 'second', a 3-second check keeps it feeling "live" without being excessive.
second: 1000 * 3,
};
export const TimeAgo = ({
timestamp,
locale: localeProp,
tooltipOptions,
className,
}: TimeAgoProps) => {
const { i18n } = useTranslation();
const [timeAgo, setTimeAgo] = useState<string>("");
const locale = useMemo(
() =>
localeProp ||
i18n.language ||
(typeof navigator !== "undefined" ? navigator.language : "en-US"),
[localeProp, i18n.language],
);
const date = useMemo(() => new Date(timestamp), [timestamp]);
const fullDate = useMemo(() => {
const defaultOptions: Intl.DateTimeFormatOptions = {
dateStyle: "full",
timeStyle: "medium",
};
const formatter = new Intl.DateTimeFormat(locale, {
...defaultOptions,
...tooltipOptions,
});
return formatter.format(date);
}, [date, locale, tooltipOptions]);
useEffect(() => {
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
let timerId: number;
const update = () => {
const { value, unit } = getRelativeTimeParts(date);
setTimeAgo(rtf.format(value, unit));
const interval = UPDATE_INTERVALS[unit] || 60000;
timerId = globalThis.setTimeout(update, interval);
};
update();
return () => {
clearTimeout(timerId);
}; };
}, [date, locale]);
export const TimeAgo = ({ timestamp }: TimeAgoProps) => {
return ( return (
<TooltipProvider> <TooltipProvider>
<Tooltip> <Tooltip>
<TooltipTrigger> <TooltipTrigger asChild>
<span>{getTimeAgo(timestamp)}</span> <time dateTime={date.toISOString()} className={className}>
{timeAgo}
</time>
</TooltipTrigger> </TooltipTrigger>
<TooltipPortal> <TooltipPortal>
<TooltipContent <TooltipContent
@ -56,7 +122,7 @@ export const TimeAgo = ({ timestamp }: TimeAgoProps) => {
align="center" align="center"
sideOffset={5} sideOffset={5}
> >
{new Date(timestamp).toLocaleString()} {fullDate}
</TooltipContent> </TooltipContent>
</TooltipPortal> </TooltipPortal>
</Tooltip> </Tooltip>

10
src/core/hooks/useFavoriteNode.ts

@ -1,6 +1,7 @@
import { useCallback } from "react"; import { useCallback } from "react";
import { useDevice } from "@core/stores/deviceStore.ts"; import { useDevice } from "@core/stores/deviceStore.ts";
import { useToast } from "@core/hooks/useToast.ts"; import { useToast } from "@core/hooks/useToast.ts";
import { useTranslation } from "react-i18next";
interface FavoriteNodeOptions { interface FavoriteNodeOptions {
nodeNum: number; nodeNum: number;
@ -9,6 +10,7 @@ interface FavoriteNodeOptions {
export function useFavoriteNode() { export function useFavoriteNode() {
const { updateFavorite, getNode } = useDevice(); const { updateFavorite, getNode } = useDevice();
const { t } = useTranslation("ui");
const { toast } = useToast(); const { toast } = useToast();
const updateFavoriteCB = useCallback( const updateFavoriteCB = useCallback(
@ -19,9 +21,11 @@ export function useFavoriteNode() {
updateFavorite(nodeNum, isFavorite); updateFavorite(nodeNum, isFavorite);
toast({ toast({
title: `${isFavorite ? "Added" : "Removed"} ${ title: t("toast.favoriteNode", {
node?.user?.longName ?? "node" action: isFavorite ? t("button.added") : t("button.removed"),
} ${isFavorite ? "to" : "from"} favorites`, nodeName: node?.user?.longName ?? t("node"),
location: isFavorite ? t("to") : t("from"),
}),
}); });
}, },
[updateFavorite, getNode], [updateFavorite, getNode],

6
src/i18n/config.ts

@ -41,9 +41,9 @@ i18next
fallbackLng: { fallbackLng: {
default: [FALLBACK_LANGUAGE_CODE], default: [FALLBACK_LANGUAGE_CODE],
"en-GB": [FALLBACK_LANGUAGE_CODE], "en-GB": [FALLBACK_LANGUAGE_CODE],
"fi": ["fi-FI"], "fi": ["fi-FI", FALLBACK_LANGUAGE_CODE],
"sv": ["sv-SE"], "sv": ["sv-SE", FALLBACK_LANGUAGE_CODE],
"de": ["de-DE"], "de": ["de-DE", FALLBACK_LANGUAGE_CODE],
}, },
fallbackNS: ["common", "ui", "dialog"], fallbackNS: ["common", "ui", "dialog"],
debug: import.meta.env.MODE === "development", debug: import.meta.env.MODE === "development",

10
src/i18n/locales/en/common.json

@ -24,7 +24,8 @@
"reset": "Reset", "reset": "Reset",
"save": "Save", "save": "Save",
"scanQr": "Scan QR Code", "scanQr": "Scan QR Code",
"traceRoute": "Trace Route" "traceRoute": "Trace Route",
"submit": "Submit"
}, },
"app": { "app": {
"title": "Meshtastic", "title": "Meshtastic",
@ -48,6 +49,7 @@
"raw": "raw", "raw": "raw",
"meter": { "one": "Meter", "plural": "Meters", "suffix": "m" }, "meter": { "one": "Meter", "plural": "Meters", "suffix": "m" },
"minute": { "one": "Minute", "plural": "Minutes" }, "minute": { "one": "Minute", "plural": "Minutes" },
"hour": { "one": "Hour", "plural": "Hours" },
"millisecond": { "millisecond": {
"one": "Millisecond", "one": "Millisecond",
"plural": "Milliseconds", "plural": "Milliseconds",
@ -55,11 +57,16 @@
}, },
"second": { "one": "Second", "plural": "Seconds" }, "second": { "one": "Second", "plural": "Seconds" },
"day": { "one": "Day", "plural": "Days" }, "day": { "one": "Day", "plural": "Days" },
"month": { "one": "Month", "plural": "Months" },
"year": { "one": "Year", "plural": "Years" },
"snr": "SNR", "snr": "SNR",
"volt": { "one": "Volt", "plural": "Volts", "suffix": "V" }, "volt": { "one": "Volt", "plural": "Volts", "suffix": "V" },
"record": { "one": "Records", "plural": "Records" } "record": { "one": "Records", "plural": "Records" }
}, },
"security": { "security": {
"0bit": "Empty",
"8bit": "8 bit",
"128bit": "128 bit",
"256bit": "256 bit" "256bit": "256 bit"
}, },
"unknown": { "unknown": {
@ -71,6 +78,7 @@
"nodeUnknownPrefix": "!", "nodeUnknownPrefix": "!",
"unset": "UNSET", "unset": "UNSET",
"fallbackName": "Meshtastic {{last4}}", "fallbackName": "Meshtastic {{last4}}",
"node": "Node",
"formValidation": { "formValidation": {
"unsavedChanges": "Unsaved changes", "unsavedChanges": "Unsaved changes",
"tooBig": { "tooBig": {

11
src/i18n/locales/en/messages.json

@ -1,6 +1,7 @@
{ {
"page": { "page": {
"title": "Messages: {{chatName}}" "title": "Messages: {{chatName}}",
"placeholder": "Enter Message"
}, },
"emptyState": { "emptyState": {
"title": "Select a Chat", "title": "Select a Chat",
@ -10,7 +11,7 @@
"text": "Select a channel or node to start messaging." "text": "Select a channel or node to start messaging."
}, },
"sendMessage": { "sendMessage": {
"placeholder": "Type your message here...", "placeholder": "Enter your message here...",
"sendButton": "Send" "sendButton": "Send"
}, },
"actionsMenu": { "actionsMenu": {
@ -18,8 +19,7 @@
"replyLabel": "Reply" "replyLabel": "Reply"
}, },
"item": { "deliveryStatus": {
"status": {
"delivered": { "delivered": {
"label": "Message delivered", "label": "Message delivered",
"displayText": "Message delivered" "displayText": "Message delivered"
@ -33,9 +33,8 @@
"displayText": "Unknown state" "displayText": "Unknown state"
}, },
"waiting": { "waiting": {
"ariaLabel": "Sending message", "label": "Sending message",
"displayText": "Waiting for delivery" "displayText": "Waiting for delivery"
} }
} }
} }
}

7
src/i18n/locales/en/nodes.json

@ -47,5 +47,12 @@
"lastHeardStatus": { "lastHeardStatus": {
"never": "Never" "never": "Never"
} }
},
"actions": {
"added": "Added",
"removed": "Removed",
"ignoreNode": "Ignore Node",
"unignoreNode": "Unignore Node",
"requestPosition": "Request Position"
} }
} }

9
src/i18n/locales/en/ui.json

@ -66,6 +66,15 @@
"saveSuccess": { "saveSuccess": {
"title": "Saving Config", "title": "Saving Config",
"description": "The configuration change {{case}} has been saved." "description": "The configuration change {{case}} has been saved."
},
"favoriteNode": {
"title": "Node {{nodeName}} {{action}} {{direction} favorites.",
"action": {
"added": "added",
"removed": "removed",
"to": "to",
"from": "from"
}
} }
}, },
"notifications": { "notifications": {

11
src/pages/Messages.tsx

@ -306,13 +306,16 @@ export const MessagesPage = () => {
return ( return (
<PageLayout <PageLayout
label={`Messages: ${ label={`${
isBroadcast && currentChannel t("page.title", {
chatName: isBroadcast && currentChannel
? getChannelName(currentChannel) ? getChannelName(currentChannel)
: isDirect && otherNode : isDirect && otherNode
? (otherNode.user?.longName ?? t("unknown.longName")) ? (otherNode.user?.longName ?? t("unknown.longName"))
: t("emptyState.title") : t("emptyState.title"),
}`} })
}
`}
rightBar={rightSidebar} rightBar={rightSidebar}
leftBar={leftSidebar} leftBar={leftSidebar}
actions={isDirect && otherNode actions={isDirect && otherNode

9
src/pages/Nodes/index.tsx

@ -31,6 +31,7 @@ import {
} from "@components/generic/Filter/useFilterNode.ts"; } from "@components/generic/Filter/useFilterNode.ts";
import { FilterControl } from "@components/generic/Filter/FilterControl.tsx"; import { FilterControl } from "@components/generic/Filter/FilterControl.tsx";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import useLang from "@core/hooks/useLang.ts";
export interface DeleteNoteDialogProps { export interface DeleteNoteDialogProps {
open: boolean; open: boolean;
@ -39,6 +40,7 @@ export interface DeleteNoteDialogProps {
const NodesPage = (): JSX.Element => { const NodesPage = (): JSX.Element => {
const { t } = useTranslation("nodes"); const { t } = useTranslation("nodes");
const { currentLanguage } = useLang();
const { getNodes, hardware, connection, hasNodeError, setDialogOpen } = const { getNodes, hardware, connection, hasNodeError, setDialogOpen } =
useDevice(); useDevice();
const { setNodeNumDetails } = useAppStore(); const { setNodeNumDetails } = useAppStore();
@ -168,7 +170,12 @@ const NodesPage = (): JSX.Element => {
<Mono> <Mono>
{node.lastHeard === 0 {node.lastHeard === 0
? <p>{t("nodesTable.lastHeardStatus.never")}</p> ? <p>{t("nodesTable.lastHeardStatus.never")}</p>
: <TimeAgo timestamp={node.lastHeard * 1000} />} : (
<TimeAgo
timestamp={node.lastHeard * 1000}
locale={currentLanguage?.code}
/>
)}
</Mono> </Mono>
), ),
sortValue: node.lastHeard, sortValue: node.lastHeard,

Loading…
Cancel
Save