Skip to content

Commit

Permalink
Rename to getMessagesWithFallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
sawyerh committed Dec 6, 2023
1 parent d79bb65 commit 6af1c77
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/.storybook/I18nStoryWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NextIntlClientProvider } from "next-intl";
import React from "react";

import { defaultLocale, formats } from "../src/i18n/config";
import { getMessages } from "../src/i18n/getMessages";
import { getMessagesWithFallbacks } from "../src/i18n/getMessagesWithFallbacks";

const I18nStoryWrapper = (
Story: React.ComponentType,
Expand All @@ -20,7 +20,7 @@ const I18nStoryWrapper = (
<NextIntlClientProvider
formats={formats}
locale={locale}
messages={getMessages(locale)}
messages={getMessagesWithFallbacks(locale)}
>
<Story />
</NextIntlClientProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const localeToMessages = {
* Get all messages for the given locale. If any translations are missing
* from the current locale, the missing key will fallback to the default locale
*/
export function getMessages(requestedLocale: string = defaultLocale) {
export function getMessagesWithFallbacks(
requestedLocale: string = defaultLocale
) {
if (requestedLocale in localeToMessages === false) {
console.error(
"Unsupported locale was requested. Falling back to the default locale.",
Expand Down
4 changes: 2 additions & 2 deletions app/src/i18n/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getRequestConfig } from "next-intl/server";

import { formats } from "./config";
import { getMessages } from "./getMessages";
import { getMessagesWithFallbacks } from "./getMessagesWithFallbacks";

/**
* I18n config for server components.
Expand All @@ -11,6 +11,6 @@ import { getMessages } from "./getMessages";
export default getRequestConfig(({ locale }) => {
return {
formats,
messages: getMessages(locale),
messages: getMessagesWithFallbacks(locale),
};
});
4 changes: 2 additions & 2 deletions app/tests/react-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { render as _render, RenderOptions } from "@testing-library/react";
import { defaultLocale, formats } from "src/i18n/config";
import { getMessages } from "src/i18n/getMessages";
import { getMessagesWithFallbacks } from "src/i18n/getMessagesWithFallbacks";

import { NextIntlClientProvider } from "next-intl";

Expand All @@ -18,7 +18,7 @@ const GlobalProviders = ({ children }: { children: React.ReactNode }) => {
return (
<NextIntlClientProvider
locale={defaultLocale}
messages={getMessages(defaultLocale)}
messages={getMessagesWithFallbacks(defaultLocale)}
formats={formats}
>
{children}
Expand Down

0 comments on commit 6af1c77

Please sign in to comment.