mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Simple localization support and currency selector.
Summary: - Grist document has a associated "locale" setting that affects how currency is formatted. - Currency selector for number format. Test Plan: not done Reviewers: dsagal Reviewed By: dsagal Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D2977
This commit is contained in:
16
app/server/lib/ServerLocale.ts
Normal file
16
app/server/lib/ServerLocale.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import {parse as languageParser} from "accept-language-parser";
|
||||
import {Request} from 'express';
|
||||
import {locales} from 'app/common/Locales';
|
||||
|
||||
/**
|
||||
* Returns the locale from a request, falling back to `defaultLocale`
|
||||
* if unable to determine the locale.
|
||||
*/
|
||||
export function localeFromRequest(req: Request, defaultLocale: string = 'en-US') {
|
||||
const language = languageParser(req.headers["accept-language"] as string)[0];
|
||||
if (!language) { return defaultLocale; }
|
||||
|
||||
const locale = `${language.code}-${language.region}`;
|
||||
const supports = locales.some(l => l.code === locale);
|
||||
return supports ? locale : defaultLocale;
|
||||
}
|
||||
Reference in New Issue
Block a user