mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Webatrice: improve language dropdown (#4589)
* useLocaleSort hook, translate language dropdown * add pt-BR translation * fix pt-BR flag Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
This commit is contained in:
parent
21f7dd5eba
commit
533045445a
10 changed files with 314 additions and 278 deletions
18
webclient/src/hooks/useLocaleSort.ts
Normal file
18
webclient/src/hooks/useLocaleSort.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export function useLocaleSort(arr: string[], valueGetter: (value: string) => string) {
|
||||
const [state] = useState<string[]>(arr);
|
||||
const [sorted, setSorted] = useState<string[]>([]);
|
||||
|
||||
const { i18n } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
const collator = new Intl.Collator(i18n.language);
|
||||
const sorter = (a, b) => collator.compare(valueGetter(a), valueGetter(b));
|
||||
|
||||
setSorted(state.sort(sorter));
|
||||
}, [state, i18n.language]);
|
||||
|
||||
return sorted;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue