Skip to content

Commit 002fca8

Browse files
committed
fix(cloud-function): try strict language pick first
1 parent 8d53b5a commit 002fca8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • cloud-function/src/internal/locale-utils

cloud-function/src/internal/locale-utils/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ export function getLocale(
102102

103103
// Each header in request.headers is always a list of objects.
104104
const value = getAcceptLanguage(request);
105+
// Try a strict match first so that e.g. `zh-TW` resolves to `zh-TW`
106+
// rather than the first `zh-*` entry in the supported list. Fall back to
107+
// a loose match so that e.g. `en-GB` still resolves to `en-US`.
105108
const locale =
106109
value &&
107-
acceptLanguageParser.pick(validLocalesList, value, { loose: true });
110+
(acceptLanguageParser.pick(validLocalesList, value) ||
111+
acceptLanguageParser.pick(validLocalesList, value, { loose: true }));
108112
return locale || fallback;
109113
}
110114

0 commit comments

Comments
 (0)