1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-22 11:24:04 +01:00

Merge pull request #922 from imkero/bugfix/language-with-underline

fix(i18n): correct usage of language str having underline
This commit is contained in:
Philipp C. Heckel 2023-10-19 07:13:39 -04:00 committed by GitHub
commit 43b11de596
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -130,14 +130,20 @@ export const hashCode = (s) => {
return hash; return hash;
}; };
/**
* convert `i18n.language` style str (e.g.: `en_US`) to kebab-case (e.g.: `en-US`),
* which is expected by `<html lang>` and `Intl.DateTimeFormat`
*/
export const getKebabCaseLangStr = (language) => language.replace(/_/g, '-');
export const formatShortDateTime = (timestamp, language) => export const formatShortDateTime = (timestamp, language) =>
new Intl.DateTimeFormat(language, { new Intl.DateTimeFormat(getKebabCaseLangStr(language), {
dateStyle: "short", dateStyle: "short",
timeStyle: "short", timeStyle: "short",
}).format(new Date(timestamp * 1000)); }).format(new Date(timestamp * 1000));
export const formatShortDate = (timestamp, language) => export const formatShortDate = (timestamp, language) =>
new Intl.DateTimeFormat(language, { dateStyle: "short" }).format(new Date(timestamp * 1000)); new Intl.DateTimeFormat(getKebabCaseLangStr(language), { dateStyle: "short" }).format(new Date(timestamp * 1000));
export const formatBytes = (bytes, decimals = 2) => { export const formatBytes = (bytes, decimals = 2) => {
if (bytes === 0) return "0 bytes"; if (bytes === 0) return "0 bytes";

View file

@ -11,7 +11,7 @@ import ActionBar from "./ActionBar";
import Preferences from "./Preferences"; import Preferences from "./Preferences";
import subscriptionManager from "../app/SubscriptionManager"; import subscriptionManager from "../app/SubscriptionManager";
import userManager from "../app/UserManager"; import userManager from "../app/UserManager";
import { expandUrl } from "../app/utils"; import { expandUrl, getKebabCaseLangStr } from "../app/utils";
import ErrorBoundary from "./ErrorBoundary"; import ErrorBoundary from "./ErrorBoundary";
import routes from "./routes"; import routes from "./routes";
import { useAccountListener, useBackgroundProcesses, useConnectionListeners, useWebPushTopics } from "./hooks"; import { useAccountListener, useBackgroundProcesses, useConnectionListeners, useWebPushTopics } from "./hooks";
@ -56,7 +56,7 @@ const App = () => {
); );
useEffect(() => { useEffect(() => {
document.documentElement.setAttribute("lang", i18n.language); document.documentElement.setAttribute("lang", getKebabCaseLangStr(i18n.language));
document.dir = languageDir; document.dir = languageDir;
}, [i18n.language, languageDir]); }, [i18n.language, languageDir]);