mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Trim langs from accept header
This commit is contained in:
@@ -107,7 +107,7 @@ export const randomLang = () => _.shuffle(["en-US", "nl-NL"])[0]!;
|
||||
|
||||
export const asLANGs = (acceptLanguageHeader: string | undefined) => {
|
||||
const z = acceptLanguageHeader?.split(";")[0];
|
||||
return z && z != "" ? z.split(",") : [];
|
||||
return z && z != "" ? z.split(",").map(it => it.trim()) : [];
|
||||
};
|
||||
|
||||
export type I8N = (...langs: string[]) => Lang;
|
||||
|
||||
@@ -21,6 +21,15 @@ describe("i8n", () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
describe("when there are multiple in the accept-langauge header with spaces", () => {
|
||||
it("should split them out and return them", () => {
|
||||
expect(asLANGs("es-ES, es, en-US;q=0.9, en;q=0.8")).toEqual([
|
||||
"es-ES",
|
||||
"es",
|
||||
"en-US",
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("langs", () => {
|
||||
|
||||
Reference in New Issue
Block a user