Skip to content

Commit

Permalink
Remove deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Nov 14, 2023
1 parent 00f0998 commit 967f903
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 161 deletions.
4 changes: 2 additions & 2 deletions packages/next-intl/src/server/getFormatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getFormatterImpl = cache(async (locale: string) => {
* The formatter automatically receives the request config, but
* you can override it by passing in additional options.
*/
export default async function getFormatter(opts?: {locale?: string} | string) {
const locale = await resolveLocaleArg('getFormatter', opts);
export default async function getFormatter(opts?: {locale?: string}) {
const locale = await resolveLocaleArg(opts);
return getFormatterImpl(locale);
}
4 changes: 2 additions & 2 deletions packages/next-intl/src/server/getMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getMessagesImpl = cache(async (locale: string) => {
return config.messages;
});

export default async function getMessages(opts?: {locale?: string} | string) {
const locale = await resolveLocaleArg('getMessages', opts);
export default async function getMessages(opts?: {locale?: string}) {
const locale = await resolveLocaleArg(opts);
return getMessagesImpl(locale);
}
4 changes: 2 additions & 2 deletions packages/next-intl/src/server/getNow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getNowImpl = cache(async (locale: string) => {
return config.now;
});

export default async function getNow(opts?: {locale?: string} | string) {
const locale = await resolveLocaleArg('getNow', opts);
export default async function getNow(opts?: {locale?: string}) {
const locale = await resolveLocaleArg(opts);
return getNowImpl(locale);
}
4 changes: 2 additions & 2 deletions packages/next-intl/src/server/getTimeZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getTimeZoneImpl = cache(async (locale: string) => {
return config.timeZone;
});

export default async function getTimeZone(opts?: {locale?: string} | string) {
const locale = await resolveLocaleArg('getTimeZone', opts);
export default async function getTimeZone(opts?: {locale?: string}) {
const locale = await resolveLocaleArg(opts);
return getTimeZoneImpl(locale);
}
124 changes: 0 additions & 124 deletions packages/next-intl/src/server/getTranslator.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions packages/next-intl/src/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ export {default as getMessages} from './getMessages';
export {default as getLocale} from './getLocale';

export {setRequestLocale as unstable_setRequestLocale} from './RequestLocale';

// TODO: Remove
export {default as getTranslator} from './getTranslator';
33 changes: 7 additions & 26 deletions packages/next-intl/src/server/resolveLocaleArg.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
import {cache} from 'react';
import getLocale from './getLocale';

// TODO: Remove

const deprecate = cache((fnName: string, locale: string) => {
console.error(
`\nDEPRECATION WARNING: Passing a locale as a string to \`${fnName}\` has been deprecated in favor of passing an object with a \`locale\` property instead:
${fnName}({locale: '${locale}'});
See https://github.com/amannn/next-intl/pull/600\n`
);
});

export default function resolveLocaleArg(
fnName: string,
optsOrDeprecatedLocale?: {locale?: string} | string
) {
if (typeof optsOrDeprecatedLocale === 'string') {
deprecate(fnName, optsOrDeprecatedLocale);
return optsOrDeprecatedLocale;
export default function resolveLocaleArg(opts?: {
locale?: string;
}): Promise<string> {
if (opts?.locale) {
return Promise.resolve(opts.locale);
} else {
return getLocale();
}

if (optsOrDeprecatedLocale?.locale) {
return optsOrDeprecatedLocale.locale;
}

return getLocale();
}

0 comments on commit 967f903

Please sign in to comment.