Skip to content

Commit

Permalink
[PFX-829] Remove @hapi/accept from intl plugin (#1006)
Browse files Browse the repository at this point in the history
* chore: replace hapi/accept with negotiator

* chore: add changelog

* chore: change to use language
  • Loading branch information
jpina1-godaddy authored Jan 13, 2025
1 parent 49fffa8 commit 00ad46c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
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.

6 changes: 3 additions & 3 deletions packages/gasket-plugin-intl/lib/utils/get-preferred-locale.js
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.language(locales));
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

0 comments on commit 00ad46c

Please sign in to comment.