Add lang URL parameter
This commit is contained in:
parent
8ea6921b12
commit
0799c98659
2 changed files with 8 additions and 3 deletions
|
@ -8,9 +8,9 @@ instance-agnostic. Just type in the post text and the instance URL, and click
|
||||||
‘Post!’
|
‘Post!’
|
||||||
|
|
||||||
Or, open this page with the prefilled `text` URL parameter—it will be
|
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
|
automatically inserted into the text field. The same goes for the `instance` and
|
||||||
parameter. This can be used to build custom share buttons for the federated
|
`lang` URL parameters. This can be used to build custom share buttons for the
|
||||||
social networks:
|
federated social networks:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<a href="https://s2f.kytta.dev/?text=Hello%20world!&instance=mastodon.xyz">
|
<a href="https://s2f.kytta.dev/?text=Hello%20world!&instance=mastodon.xyz">
|
||||||
|
|
|
@ -12,6 +12,11 @@ export function useTranslations(language: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findBestLanguage(): 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;
|
let browserLanguages = navigator.languages;
|
||||||
if (!navigator.languages) browserLanguages = [navigator.language];
|
if (!navigator.languages) browserLanguages = [navigator.language];
|
||||||
for (const language of browserLanguages) {
|
for (const language of browserLanguages) {
|
||||||
|
|
Reference in a new issue