From 0799c9865919edf9870372f178bffe9d13375707 Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Tue, 29 Aug 2023 17:00:53 +0200 Subject: [PATCH] Add lang URL parameter --- README.md | 6 +++--- src/i18n/engine.ts | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dbcdedf..611716f 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ instance-agnostic. Just type in the post text and the instance URL, and click ‘Post!’ Or, open this page with the prefilled `text` URL parameter—it will be -automatically inserted into the text field. The same goes for the `instance` URL -parameter. This can be used to build custom share buttons for the federated -social networks: +automatically inserted into the text field. The same goes for the `instance` and +`lang` URL parameters. This can be used to build custom share buttons for the +federated social networks: ```html diff --git a/src/i18n/engine.ts b/src/i18n/engine.ts index a591ebd..0dc9a0e 100644 --- a/src/i18n/engine.ts +++ b/src/i18n/engine.ts @@ -12,6 +12,11 @@ export function useTranslations(language: string) { } export function findBestLanguage(): string { + const urlLanguage = new URLSearchParams(window.location.search).get("lang"); + if (urlLanguage && urlLanguage in languages) { + return urlLanguage; + } + let browserLanguages = navigator.languages; if (!navigator.languages) browserLanguages = [navigator.language]; for (const language of browserLanguages) {