# gt-react: General Translation React SDK: useLocaleSelector URL: https://generaltranslation.com/ja/docs/react/api/helpers/use-locale-selector.mdx --- title: useLocaleSelector description: useLocaleSelector フックのAPIリファレンス --- {/* 自動生成: このファイルを直接編集しないでください。代わりに content/docs-templates/ のテンプレートを編集してください。 */} ## 概要 このフックは、現在のロケール、localesの一覧、[`useSetLocale`](/docs/react/api/helpers/use-set-locale)フック、およびロケールのプロパティを取得する関数を返します。 独自のロケールセレクターコンポーネントを作成する際に、手軽に利用できるよう設計されています。 独自実装したくない場合は、代わりに[``](/docs/react/api/components/locale-selector)コンポーネントを使用できます。 ## リファレンス ### 戻り値 現在のロケール、locales の一覧、[`useSetLocale`](/docs/react/api/helpers/use-set-locale) フック、ロケールのプロパティを取得する関数を含むオブジェクト。 *** ## 例 ### `` [``](/docs/react/api/components/locale-selector) コンポーネントの実装例です。 ```jsx export default function LocaleSelector({ locales: _locales, ...props }: { locales?: string[]; [key: string]: any; }): React.JSX.Element | null { // ロケールセレクターのプロパティを取得 const { locale, locales, setLocale, getLocaleProperties } = useLocaleSelector( _locales ? _locales : undefined ); // 表示名を取得 const getDisplayName = (locale: string) => { return capitalizeLanguageName( getLocaleProperties(locale).nativeNameWithRegionCode ); }; // localesが返されない場合は何もレンダリングしないか、適切に処理する if (!locales || locales.length === 0 || !setLocale) { return null; } return ( ); } ``` *** ## 注意事項 * このフックはクライアントサイドでのみ利用できます。 * ロケールコードについて詳しくは[こちら](/docs/core/locales)を参照してください。 ## 次のステップ * [``](/docs/react/api/components/locale-selector) コンポーネントの詳細はこちら。 * [`useLocale`](/docs/react/api/helpers/use-locale) フックの詳細はこちら。