Socket
Book a DemoInstallSign in
Socket

@smarthr/i18n

Package Overview
Dependencies
Maintainers
24
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smarthr/i18n

SmartHR's i18n utility

latest
Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
0
Maintainers
24
Weekly downloads
 
Created
Source

@smarthr/i18n

SmartHRの国際化(i18n)ユーティリティライブラリです。

主な機能

  • ロケールの取得
  • Reactコンポーネント向けの国際化サポート

サブパッケージ

インストール

npm install @smarthr/i18n

利用方法

各サブパッケージの詳細な使い方は、上記リンク先のREADMEをご参照ください。

Next.jsでの使用例

next-intlのGetting startedに従ってnext-intlの環境をセットアップします。 ここではApp Routerでのi18nルーティングを使わないパターン@smarthr/i18nを利用する例を記載します。

request.tsファイルでgetLocaleを利用してアプリケーションがサポートする言語からロケールを決定します。currentLocaleの取得はアプリケーションごとに実装するものとします。

import { getRequestConfig } from 'next-intl/server'
import { getLocale, Locale } from '@smarthr/i18n'
import { getUserLocale } from '@/getUserLocale'

const supportedLocales: Locale[] = ['ja-JP', 'en-US']

export default getRequestConfig(async () => {
  const currentLocale = await getUserLocale()

  const locale = getLocale({
    currentLocale,
    supportedLocales,
  })
  return {
    locale,
    messages: (await import(`./locales/${locale}.json`)).default,
  }
})

layout.tsxNextIntlClientProviderを適用します。

import { NextIntlClientProvider } from 'next-intl'
import { getLocale } from 'next-intl/server'

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode
}>) {
  const locale = await getLocale()
  return (
    <html lang={locale}>
      <body>
        <NextIntlClientProvider>{children}</NextIntlClientProvider>
      </body>
    </html>
  )
}

多言語化を適用したいページでuseNextIntlを使います。 React Server Componentsで使う場合はワークアラウンドを利用します。

import { useNextIntl } from '@smarthr/i18n'

export default function Home() {
  const { formatMessage } = useNextIntl()
  return <div>{formatMessage('Home.greeting')}</div>
}

FAQs

Package last updated on 04 Aug 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