Socket
Book a DemoInstallSign in
Socket

@bricco/localization

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bricco/localization

0.1.5
latest
npmnpm
Version published
Weekly downloads
5
25%
Maintainers
2
Weekly downloads
 
Created
Source

Initialization

  • Create a localization file, ie: /src/locales/sv/common.[json|js|ts]

  • Create /src/locales/translations.ts

import { initServerTranslations } from '@bricco/localization';

import { Common as CommonSV } from '@/locales/sv/common';

const dictionaries = {
    en: {},
    sv: CommonSV,
  };

const { t, getLang } = initServerTranslations(dictionaries);

export { dictionaries, getLang, t };

  • Add a /localization.d.ts with this code:
import '@bricco/localization';

import { Common as CommonSV } from '@/locales/sv/common';

declare module '@bricco/localization' {
  interface CustomOptions {
    dictionary: typeof CommonSV;
  }
}

  • Edit your main layout.tsx, ie: /src/app/layout.tsx
import { Localization } from '@bricco/localization';
import { dictionaries } from '@/locales/translations';

...
export default async function RootLayout({ children }: { children: React.ReactNode }): Promise<JSX.Element> {
...
  <body ...>
    <Localization dictionaries={dictionaries}>
      {children}
    </Localization>
  </body>
...
}
  • Optional: Add the language switcher to the Admin menu
      <AdminLayout
        menu={menu}
        languages={[
          { id: 'en', label: 'English' },
          { id: 'sv', label: 'Svenska' },
        ]}
        title={'Example'}
        subTitle="@bricco/next-utils"
      >
        {children}
      </AdminLayout>

Usage

Server components

  import { t } from '@/locales/translations';

Client componets

  import { useTranslation } from '@bricco/localization';

  const { t } = useTranslation();

To translate

  // Will fail to compile TS if "String in english" is missing from @/locales/sv/common.
  console.log(t('String in english'))

FAQs

Package last updated on 17 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.