Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PFX-829] Remove @hapi/accept from intl plugin #1006

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const debug = require('debug')('gasket:plugin:intl:utils');
const accept = require('@hapi/accept');
const { getIntlConfig } = require('../configure');
const Negotiator = require('negotiator');

/**
* Capitalize the first letter of a string.
Expand Down Expand Up @@ -35,12 +35,12 @@ function getLocaleFromHeaders(gasket, req, locales, defaultLocale) {
let preferredLocale = defaultLocale;
/** @type {string} */
const acceptLanguage = req.headers['accept-language'];

const negotiator = new Negotiator(req);
if (acceptLanguage) {
debug(`Received accept-language of ${acceptLanguage}`);
try {
// Get highest or highest from locales if configured
preferredLocale = formatLocale(accept.language(acceptLanguage, locales));
preferredLocale = formatLocale(negotiator.languages(locales)[0]);
jpina1-godaddy marked this conversation as resolved.
Show resolved Hide resolved
debug(`Using ${preferredLocale} as starting locale`);
} catch (error) {
gasket.logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"homepage": "https://github.com/godaddy/gasket/tree/main/packages/gasket-plugin-intl",
"dependencies": {
"@gasket/request": "^7.1.0",
"@hapi/accept": "^6.0.3",
"debug": "^4.3.4",
"fs-extra": "^10.0.0",
"glob": "^8.1.0",
"intl": "^1.2.5",
"negotiator": "^1.0.0",
"semver": "^7.6.3"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('getPreferredLocale', () => {
describe('when accept-language header is malformed', function () {

beforeEach(function () {
req.headers['accept-language'] = 'fr-CH;+malformed';
req.headers['accept-language'] = ';fr-CH';
});

it('logs a debug message', async function () {
Expand Down
3 changes: 3 additions & 0 deletions packages/gasket-react-intl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# `@gasket/react-intl`

- Replace happ/accept with negotiator ([#1006])

### 7.1.0

- Aligned version releases across all packages
Expand Down Expand Up @@ -211,3 +213,4 @@
[#670]: https://github.com/godaddy/gasket/pull/670
[#696]: https://github.com/godaddy/gasket/pull/696
[#779]: https://github.com/godaddy/gasket/pull/779
[#1006]: https://github.com/godaddy/gasket/pull/1006
Loading