-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add details on translation status (#2139)
languages specified in `translatedLocales` - Updates user language preference beta badge text - Adds link to translation contribution docs - Refactors component name --------- Co-authored-by: SuaYoo <[email protected]> Co-authored-by: Henry Wilkinson <[email protected]> Co-authored-by: emma <[email protected]>
- Loading branch information
1 parent
0fb6571
commit ab9edfa
Showing
14 changed files
with
180 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import type { SlSelectEvent } from "@shoelace-style/shoelace"; | ||
import { html } from "lit"; | ||
import { customElement, state } from "lit/decorators.js"; | ||
|
||
import { sourceLocale } from "@/__generated__/locale-codes"; | ||
import { BtrixElement } from "@/classes/BtrixElement"; | ||
import { allLocales, type LocaleCodeEnum } from "@/types/localization"; | ||
import { getLocale, setLocale } from "@/utils/localization"; | ||
import { AppStateService } from "@/utils/state"; | ||
|
||
/** | ||
* Select language that Browsertrix app will be shown in | ||
*/ | ||
@customElement("btrix-user-language-select") | ||
export class LocalePicker extends BtrixElement { | ||
@state() | ||
private localeNames: { [locale: string]: string } = {}; | ||
|
||
firstUpdated() { | ||
this.setLocaleNames(); | ||
} | ||
|
||
private setLocaleNames() { | ||
const localeNames: LocalePicker["localeNames"] = {}; | ||
|
||
// TODO Add browser-preferred languages | ||
// https://github.com/webrecorder/browsertrix/issues/2143 | ||
allLocales.forEach((locale) => { | ||
const name = new Intl.DisplayNames([locale], { | ||
type: "language", | ||
}).of(locale); | ||
|
||
if (!name) return; | ||
|
||
localeNames[locale] = name; | ||
}); | ||
|
||
this.localeNames = localeNames; | ||
} | ||
|
||
render() { | ||
const selectedLocale = | ||
this.appState.userPreferences?.locale || sourceLocale; | ||
|
||
return html` | ||
<sl-dropdown | ||
@sl-select=${this.localeChanged} | ||
placement="top-end" | ||
distance="4" | ||
hoist | ||
> | ||
<sl-button | ||
slot="trigger" | ||
size="small" | ||
caret | ||
?disabled=${(allLocales as unknown as string[]).length < 2} | ||
> | ||
<sl-icon slot="prefix" name="translate"></sl-icon> | ||
<span class="capitalize" | ||
>${this.localeNames[selectedLocale as LocaleCodeEnum]}</span | ||
> | ||
</sl-button> | ||
<sl-menu> | ||
${Object.keys(this.localeNames) | ||
.sort() | ||
.map( | ||
(locale) => | ||
html`<sl-menu-item | ||
class="capitalize" | ||
type="checkbox" | ||
value=${locale} | ||
?checked=${locale === selectedLocale} | ||
> | ||
${this.localeNames[locale]} | ||
</sl-menu-item>`, | ||
)} | ||
</sl-menu> | ||
</sl-dropdown> | ||
`; | ||
} | ||
|
||
async localeChanged(event: SlSelectEvent) { | ||
const newLocale = event.detail.item.value as LocaleCodeEnum; | ||
|
||
AppStateService.partialUpdateUserPreferences({ locale: newLocale }); | ||
|
||
if (newLocale !== getLocale()) { | ||
void setLocale(newLocale); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.