{"id":11314,"date":"2023-01-16T07:00:51","date_gmt":"2023-01-15T22:00:51","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=11314"},"modified":"2022-12-17T19:58:36","modified_gmt":"2022-12-17T10:58:36","slug":"laravel-inertia-react-%e3%81%a7%e5%a4%9a%e8%a8%80%e8%aa%9e%e5%8c%96%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=11314","title":{"rendered":"Laravel + Inertia + React \u3067\u591a\u8a00\u8a9e\u5316\u3059\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u79c1\u3082\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u597d\u304d\u306a\u4eba\u9593\u3068\u3057\u3066\u5b9a\u671f\u7684\u306b\u500b\u4eba\u30b5\u30a4\u30c8\u3092\u3064\u304f\u3063\u305f\u308a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6b63\u76f4\u306a\u3068\u3053\u308d\u300c<strong>\u9cf4\u304b\u305a\u98db\u3070\u305a<\/strong>\u300d\u306a\u30b5\u30a4\u30c8\u3070\u304b\u308a\u3067\u307b\u3068\u3093\u3069\u7d42\u4e86\u3055\u305b\u3066\u304d\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u500b\u4eba\u958b\u767a\u306f\u306a\u3093\u3068\u3044\u3063\u3066\u3082\u300c\u81ea\u7531\u306b\u3067\u304d\u308b\u300d\u306e\u3067\u8da3\u5473\u3068\u3057\u3066\u7d9a\u3051\u305f\u3044\u3068\u3053\u308d\u3067\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u305d\u3093\u306a\u500b\u4eba\u958b\u767a\u3067\u3042\u3063\u3066\u3082\u4eca\u5f8c\u8996\u91ce\u306b\u5165\u308c\u3066\u304a\u304f\u3079\u304d\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u304c\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">\u591a\u8a00\u8a9e\u5316<\/strong><\/p>\n<p>\u3067\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u306e\u3082\u3001\u307f\u306a\u3055\u3093\u3054\u5b58\u77e5\u306e\u3068\u304a\u308a2022\u5e7411\u6708\u6708\u306b\u51fa\u3055\u308c\u305f\u7d71\u8a08\u3067\u306f\u3001\u51fa\u751f\u6570\u304c77\u4e07\u4eba\u306b\u306a\u308a\u3001\u4eba\u53e3\u304c\u3069\u3093\u3069\u3093\u6e1b\u3063\u3066\u3044\u304f\u305f\u3081\u3001\u4eca\u5f8c\u306f\u56fd\u5916\u30de\u30fc\u30b1\u30c3\u30c8\u3092\u8996\u91ce\u306b\u3044\u308c\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u304b\u3089\u3067\u3059\u3002\uff08\u3057\u304b\u3082\u3001\u56fd\u306e\u4e88\u6e2c\u3088\u308a\u30828\u5e74\u65e9\u304f\u3053\u3046\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3088\u3046\u3067\u3059\ud83d\ude25\uff09<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f\u300c<strong>Laravel + Inertia + React<\/strong>\u300d\u3067\u591a\u8a00\u8a9e\u5316\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u4f55\u304b\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\u3002\ud83d\ude04\u2728<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3405 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png\" alt=\"\" width=\"310\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png 310w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18-291x300.png 291w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u3082\u3057\u3082 JavaScript \u304c\u65e5\u672c\u88fd\u306a\u3089\u3001<br \/>\n\u300cVanilla JS\u300d\u306f\u3001<br \/>\n\u300c\u5c0f\u8c46 JS\u300d\u3068\u547c\u3070\u308c\u3066\u305f\u3093\u3067\u3057\u3087\u3046\u304b\uff1f\uff1f\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 9x\u3001React\u3001Vite\u3001Inertia.js\u3001TailwindCSS<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4eca\u56de\u306f<code>React<\/code>\u5074\u3067\u8868\u793a\u3059\u308b\u30c6\u30ad\u30b9\u30c8\u3092\u591a\u8a00\u8a9e\u5316\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u5bfe\u5fdc\u3059\u308b\u8a00\u8a9e\u306f\u4ee5\u4e0b\u306e\uff13\u3064\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u65e5\u672c\u8a9e<\/li>\n<li>\u82f1\u8a9e<\/li>\n<li>\u4e2d\u56fd\u8a9e<\/li>\n<\/ul>\n<p>\u307e\u305f\u3001\u305b\u3063\u304b\u304f\u306a\u306e\u3067<code>React<\/code>\u3067\u8a00\u8a9e\u3092\u5909\u66f4\u3067\u304d\u308b\u6a5f\u80fd\u3082\u3064\u304f\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u697d\u3057\u3093\u3067\u3084\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u2757<\/p>\n<h1>\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092\u3064\u304f\u308b<\/h1>\n<p>\u307e\u305a\u4eca\u56de\u306e\u6a5f\u80fd\u3092\u3064\u304f\u308b\u306b\u5f53\u305f\u3063\u3066\u5fc5\u8981\u306b\u306a\u308b\u3082\u306e\u304c\u300c<strong>\u7ffb\u8a33\u30c7\u30fc\u30bf<\/strong>\u300d\u3067\u3059\u3002<\/p>\n<p><code>Laravel<\/code>\u306b\u306f<code>JSON<\/code>\u3092\u4f7f\u3063\u305f\u591a\u8a00\u8a9e\u5316\u304c\u306f\u3058\u3081\u304b\u3089\u5099\u308f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u308c\u306b\u5408\u308f\u305b\u3066<code>lang<\/code>\u30d5\u30a9\u30eb\u30c0\u76f4\u4e0b\u306b<code>JSON<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u30bb\u30c3\u30c8\u3057\u3066\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u300c<strong>\u82f1\u6587\u3092\u30ad\u30fc\u3068\u3057\u3066\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3059\u308b<\/strong>\u300d\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><strong>lang\/ja.json<\/strong><\/p>\n<pre>{\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>\"Not Found\": \"\u898b\u3064\u304b\u308a\u307e\u305b\u3093\",<\/strong>\r\n    \r\n    \/\/ \u7701\u7565\r\n}<\/pre>\n<p>\u305d\u3053\u3067\u3001\u4eca\u56de\u306f\u4ee5\u4e0b\uff12\u3064\u306e<code>JSON<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3053\u306e\u4e2d\u306b\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092\u767b\u9332\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>lang\/ja.json<\/strong><\/p>\n<pre><strong>{<\/strong>\r\n<strong>    \"Hi, :user_name, It is now :hours::minutes.\": \"\u3053\u3093\u306b\u3061\u306f\u3001:user_name \u3055\u3093\u3002 \u73fe\u5728\u6642\u523b\u306f\u3001:hours\u6642:minutes\u5206\u3067\u3059\u3002\"<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p><strong>lang\/zh.json<\/strong><\/p>\n<pre><strong>{<\/strong>\r\n<strong>    \"Hi, :user_name, It is now :hours::minutes.\": \"\u4f60\u597d\uff0c:user_name\u3002\u76ee\u524d\u7684\u65f6\u95f4\u662f:hours::minutes\u3002\"<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u203b \u3061\u306a\u307f\u306b\u7ffb\u8a33\u306f <strong><a href=\"https:\/\/www.deepl.com\/\" target=\"_blank\" rel=\"noopener\">DeepL<\/a><\/strong> \u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u3053\u306e\u4e2d\u306b\u5165\u3063\u3066\u3044\u308b\u4ee5\u4e0b\uff13\u3064\u306e\u90e8\u5206\u306f\u5404\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u7f6e\u304d\u63db\u3048\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>:user_name \u2192 \u30e6\u30fc\u30b6\u30fc\u540d<\/li>\n<li>:hours \u2192 \u6642<\/li>\n<li>:minutes \u2192 \u5206<\/li>\n<\/ul>\n<p>\u4f8b\u3048\u3070\u3001\u65e5\u672c\u8a9e\u306e\u5834\u5408\u3060\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u3001<\/p>\n<pre><strong>echo __('Hi, :user_name, It is now :hours::minutes.', [<\/strong>\r\n<strong>    'user_name' =&gt; '\u5c71\u7530\u592a\u90ce',<\/strong>\r\n<strong>    'hours' =&gt; now()-&gt;format('H'),<\/strong>\r\n<strong>    'minutes' =&gt; now()-&gt;format('i'),<\/strong>\r\n<strong>]);<\/strong><\/pre>\n<p>\u51fa\u529b\u306f\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\ud83d\udc47<\/p>\n<pre>\u3053\u3093\u306b\u3061\u306f\u3001\u5c71\u7530\u592a\u90ce \u3055\u3093\u3002 \u73fe\u5728\u6642\u523b\u306f\u300103\u664219\u5206\u3067\u3059\u3002<\/pre>\n<p>\u3067\u306f\u3001\u3053\u306e\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092\u300c<strong>Inertia + React<\/strong>\u300d\u3067\u3082\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u2757<\/p>\n<h1>Laravel\u304b\u3089React\u5074\u3078\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092\u9001\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u306f\u5148\u307b\u3069\u3064\u304f\u3063\u305f\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092<code>React<\/code>\uff08<code>Inertia<\/code>\uff09\u5074\u3078\u9001\u3063\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><strong>app\/Providers\/AppServiceProvider.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Providers;\r\n\r\nuse Illuminate\\Support\\ServiceProvider;\r\n<strong>use Inertia\\Inertia;<\/strong>\r\n\r\nclass AppServiceProvider extends ServiceProvider\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    public function boot()\r\n    {\r\n        <strong>\/\/ \u7ffb\u8a33\u30c7\u30fc\u30bf\u3092 Inertia \u3078\u6e21\u3059<\/strong>\r\n<strong>        $locale_data = [];<\/strong>\r\n<strong>        $locales = ['ja', 'zh']; \/\/ \ud83d\udc48 \u3067\u304d\u308c\u3070 Enum \u3067\u306e\u7ba1\u7406\u304c\u30d9\u30bf\u30fc\u3067\u3059<\/strong>\r\n\r\n<strong>        foreach ($locales as $locale) {<\/strong>\r\n\r\n<strong>            $json_path = lang_path($locale .'.json');<\/strong>\r\n<strong>            $json_content = file_get_contents($json_path);<\/strong>\r\n<strong>            $locale_data[$locale] = json_decode($json_content, true);<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        $default_locale = config('app.locale');<\/strong>\r\n<strong>        $current_locale = request('locale', $default_locale);<\/strong>\r\n\r\n<strong>        Inertia::share('locale', [<\/strong>\r\n<strong>            'currentLocale' =&gt; $current_locale,<\/strong>\r\n<strong>            'localeData' =&gt; $locale_data,<\/strong>\r\n<strong>        ]);<\/strong>\r\n    }\r\n}<\/pre>\n<p>\u203b \u306a\u304a\u3001\u30b3\u30e1\u30f3\u30c8\u306b\u3082\u66f8\u3044\u3066\u3044\u307e\u3059\u304c\u3001\u4f7f\u7528\u3059\u308b\u8a00\u8a9e\u306f<code>Enum<\/code>\u3067\u7ba1\u7406\u3057\u305f\u307b\u3046\u304c\u3044\u3044\u3067\u3059\u3002\u3068\u3044\u3046\u306e\u3082\u5225\u306e\u5834\u6240\u3067\u3082\u4f7f\u3046\u3053\u3068\u304c\u60f3\u5b9a\u3055\u308c\u308b\u306e\u3067\u4e00\u5143\u7ba1\u7406\u3057\u3066\u304a\u304b\u306a\u3044\u3068\u3001\u5f8c\u3067\u30b3\u30fc\u30c9\u3059\u3079\u3066\u3092\u5909\u66f4\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u304f\u306a\u308b\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u3067\u3001<code>Inertia<\/code>\u5074\u3078\u7ffb\u8a33\u30c7\u30fc\u30bf\u304c\u6e21\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u2757<\/p>\n<h1>Inertia + React \u3067\u7ffb\u8a33\u30c7\u30fc\u30bf\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b<\/h1>\n<p>\u6b21\u306b\u3001<code>Inertia<\/code>\u5074\u3078\u9001\u4fe1\u3055\u308c\u305f\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3067\u3059\u304c\u3001\u30b7\u30f3\u30d7\u30eb\u306b\u3044\u3046\u3068<code>props<\/code>\u304b\u3089\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>export default function Index(props) {\r\n\r\n    console.log(<strong>props.locale<\/strong>); \/\/ \ud83d\udc48 \u7ffb\u8a33\u30c7\u30fc\u30bf\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n}<\/pre>\n<p>\u3057\u304b\u3057\u3001\u6bce\u56de\u8a00\u8a9e\u3092\u7279\u5b9a\u3057\u3066\u30bf\u30fc\u30b2\u30c3\u30c8\u306e\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u306e\u306f\u9762\u5012\u3067\u3059 \ud83d\ude2b\uff08\u3057\u304b\u3082\u3001\u3055\u3089\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u3082\u7f6e\u304d\u63db\u3048\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\uff09<\/p>\n<pre>\/\/ \u26a0 \u3053\u308c\u306f\u66f8\u304f\u306e\u304c\u9762\u5012\u306a\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u3059\r\n\r\nexport default function Index(props) {\r\n\r\n    <strong>const currentLocale = props.locale.currentLocale;<\/strong>\r\n<strong>    const text = props.locale.localeData[currentLocale]['Hi, :user_name, It is now :hours::minutes.'] || '';<\/strong>\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n}<\/pre>\n<p>\u305d\u3053\u3067<code>Laravel<\/code>\u306e\u3088\u3046\u306b<code>__()<\/code>\u3001<code>trans()<\/code>\u3068\u3044\u3046\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3092<code>JavaScript<\/code>\u5074\u3067\u767b\u9332\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\uff08\u306a\u304a\u3001<code>__()<\/code>\u3001<code>trans()<\/code>\u306f\u3069\u3061\u3089\u3082\u540c\u3058\u3082\u306e\u3067\u3059\uff09<\/p>\n<p><strong>resources\/js\/app.jsx<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\ncreateInertiaApp({\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    setup({ el, App, props }) {\r\n\r\n        <strong>\/\/ \u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3092\u767b\u9332<\/strong>\r\n<strong>        window.__ = window.trans = (key = null, replace = {}, locale = null) =&gt; {<\/strong>\r\n\r\n<strong>            const {currentLocale, localeData} = props.initialPage.props.locale;<\/strong>\r\n\r\n<strong>            if(locale === null) {<\/strong>\r\n\r\n<strong>                locale = currentLocale;<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>            let translatedText = localeData[locale][key] || key;<\/strong>\r\n\r\n<strong>            for(let key in replace) {<\/strong>\r\n\r\n<strong>                const replacingValue = replace[key];<\/strong>\r\n<strong>                translatedText = translatedText.replace(`:${key}`, replacingValue);<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>            return translatedText;<\/strong>\r\n\r\n<strong>        };<\/strong>\r\n\r\n        return render(&lt;App {...props} \/&gt;, el);\r\n    },\r\n});\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<p>\u3053\u308c\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre>\/\/ \u57fa\u672c\u5f62\r\n<strong>const text = __('Hello!');<\/strong>\r\n<strong>const text = trans('Hello!');<\/strong>\r\n\r\n\/\/ \u30d1\u30e9\u30e1\u30fc\u30bf\u3064\u304d\u306e\u5834\u5408\r\n<strong>const text = __('Hello, :user_name!', [<\/strong>\r\n<strong>    'user_name' =&gt; '\u5c71\u7530\u592a\u90ce'<\/strong>\r\n<strong>]);<\/strong><\/pre>\n<h1>\u7ffb\u8a33\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001\u3053\u3053\u307e\u3067\u3067\u3064\u304f\u3063\u305f\u6a5f\u80fd\u3067\u7ffb\u8a33\u30c7\u30fc\u30bf\u304c\u8868\u793a\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u8a00\u8a9e\u306e\u5207\u308a\u66ff\u3048\u3082\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<h2>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h2>\n<p>\u307e\u305a\u306f\u30eb\u30fc\u30c8\u306b\u4ee5\u4e0b\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>routes\/web.php<\/strong><\/p>\n<pre><strong>Route::get('locale', fn() =&gt; Inertia::render('Locale\/Index'));<\/strong><\/pre>\n<p>\u203b \u306a\u304a\u3001\u4eca\u56de\u306f\u3072\u3068\u3064\u306a\u306e\u3067\u7701\u7565\u5f62\u3067\u66f8\u3044\u3066\u3044\u307e\u3059\u304c\u3001\u8907\u6570\u3042\u308b\u5834\u5408\u306f\u3061\u3083\u3093\u3068\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u66f8\u3044\u305f\u65b9\u304c\u3044\u3044\u3067\u3059\u3002<\/p>\n<h2>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h2>\n<p>\u6b21\u306b\u30d3\u30e5\u30fc\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u3064\u304f\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>resources\/js\/Pages\/Locale\/Index.jsx<\/strong><\/p>\n<pre><strong>export default function Index(props) {<\/strong>\r\n\r\n<strong>    const userName = '\u5c71\u7530\u592a\u90ce';<\/strong>\r\n<strong>    const hours = new Date().getHours();<\/strong>\r\n<strong>    const minutes = new Date().getMinutes();<\/strong>\r\n<strong>    const locales = ['ja', 'en', 'zh'];<\/strong>\r\n<strong>    const handleChangeLocale = locale =&gt; {<\/strong>\r\n\r\n<strong>        location.href = '?locale='+ locale;<\/strong>\r\n\r\n<strong>    };<\/strong>\r\n\r\n<strong>    return (<\/strong>\r\n<strong>        &lt;div className=\"p-5\"&gt;<\/strong>\r\n<strong>            &lt;div className=\"bg-gray-200 p-2 mb-5\"&gt;<\/strong>\r\n<strong>                { __('Hi, :user_name, It is now :hours::minutes.', {<\/strong>\r\n<strong>                    user_name: userName,<\/strong>\r\n<strong>                    hours: hours,<\/strong>\r\n<strong>                    minutes: minutes,<\/strong>\r\n<strong>                }) }<\/strong>\r\n<strong>            &lt;\/div&gt;<\/strong>\r\n\r\n<strong>            Language&lt;br \/&gt;<\/strong>\r\n<strong>            &lt;select onChange={e =&gt; handleChangeLocale(e.target.value)}&gt;<\/strong>\r\n<strong>                &lt;option value=\"\"&gt;&lt;\/option&gt;<\/strong>\r\n<strong>                {locales.map(locale =&gt; (<\/strong>\r\n<strong>                    &lt;option key={locale} value={locale}&gt;{locale}&lt;\/option&gt;<\/strong>\r\n<strong>                ))}<\/strong>\r\n<strong>            &lt;\/select&gt;<\/strong>\r\n<strong>        &lt;\/div&gt;<\/strong>\r\n<strong>    );<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u4f5c\u696d\u306f\u5b8c\u4e86\u3067\u3059\u2757<br \/>\n\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\ud83d\ude04<\/p>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p><code>npm run dev<\/code>\u3092\u5b9f\u884c\u3057\u3066<code>Vite<\/code>\u3092\u8d77\u52d5\u3057\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u300c<strong>http:\/\/******\/locale<\/strong>\u300d\u3078\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3059\u308b\u3068\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11318\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_react_localization_1.png\" alt=\"\" width=\"461\" height=\"157\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_react_localization_1.png 461w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_react_localization_1-300x102.png 300w\" sizes=\"auto, (max-width: 461px) 100vw, 461px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u30d9\u30fc\u30b9\u306f\u82f1\u8a9e\u3067\u3057\u305f\u304c\u3001\u8a00\u8a9e\u8a2d\u5b9a\u304c\u300c<strong>ja<\/strong>\u300d\u306a\u306e\u3067\u65e5\u672c\u8a9e\u3067\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u6b21\u306f\u300c<strong>Language<\/strong>\u300d\u30bb\u30ec\u30af\u30c8\u30dc\u30c3\u30af\u30b9\u3067\u300c<strong>en<\/strong>\u300d\u3092\u9078\u629e\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11317\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_react_localization_2.png\" alt=\"\" width=\"105\" height=\"178\" \/><\/p>\n<p>\u3069\u3046\u306a\u3063\u305f\u3067\u3057\u3087\u3046\u304b\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11316\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_react_localization_3.png\" alt=\"\" width=\"254\" height=\"66\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u81ea\u52d5\u3067\u82f1\u8a9e\u306b\u5207\u308a\u66ff\u308f\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3001\u6b21\u306b\u4e2d\u56fd\u8a9e\uff08<strong>zh<\/strong>\uff09\u306b\u5909\u66f4\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u3046\u307e\u304f\u3044\u304f\u3067\u3057\u3087\u3046\u304b\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11315\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_react_localization_4.png\" alt=\"\" width=\"308\" height=\"61\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_react_localization_4.png 308w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/12\/laravel_react_localization_4-300x59.png 300w\" sizes=\"auto, (max-width: 308px) 100vw, 308px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u3053\u3061\u3089\u3082\u3046\u307e\u304f\u5909\u66f4\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3059\u3079\u3066\u6210\u529f\u3067\u3059\ud83d\ude04\ud83d\udc4d<\/p>\n<h1>\u4f01\u696d\u69d8\u3078\u306e\u3054\u63d0\u6848<\/h1>\n<p>\u4eca\u5f8c\u65e5\u672c\u306e\u4eba\u53e3\u304c\u6975\u7aef\u306b\u6e1b\u3063\u3066\u304f\u308b\u306e\u306f\u51fa\u751f\u6570\u3092\u898b\u308c\u3070\u660e\u3089\u304b\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u3053\u308c\u304b\u3089\u306f\u65e5\u672c\u5411\u3051\u306e\u30b5\u30fc\u30d3\u30b9\u3060\u3051\u3067\u306f\u7acb\u3061\u884c\u304b\u306a\u304f\u306a\u308b\u30b1\u30fc\u30b9\u3082\u5897\u3048\u3066\u304f\u308b\u3053\u3068\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u4eca\u56de\u306e\u3088\u3046\u306b\u30b5\u30a4\u30c8\u3092\u591a\u8a00\u8a9e\u5316\u3059\u308b\u3053\u3068\u3067\u6765\u308b\u3079\u304d\u4e16\u754c\u306b\u30de\u30c3\u30c1\u3057\u305f\u3082\u306e\u3092\u6e96\u5099\u3057\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u3082\u3057\u305d\u3046\u3044\u3063\u305f\u3054\u5e0c\u671b\u3084\u3054\u76f8\u8ac7\u304c\u3054\u3056\u3044\u307e\u3057\u305f\u3089\u3001\u3044\u3064\u3067\u3082\u304a\u6c17\u8efd\u306b\u304a\u554f\u3044\u5408\u308f\u305b\u304b\u3089\u3054\u9023\u7d61\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u304a\u5f85\u3061\u3057\u3066\u304a\u308a\u307e\u3059\u3002\ud83d\ude04<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u4eca\u56de\u306f\u300c<strong>Laravel + Inertia + React<\/strong>\u300d\u3067\u591a\u8a00\u8a9e\u5316\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u7ffb\u8a33\u30c7\u30fc\u30bf\u306f<code>JSON<\/code>\u306a\u306e\u3067\u4ed6\u306e\u76ee\u7684\u306b\u3082\u4f7f\u3044\u3084\u3059\u3044\u3067\u3059\u3057\u3001<code>DeepL<\/code>\u304c\u3042\u308c\u3070\u3042\u308b\u7a0b\u5ea6\u306f\u7cbe\u5ea6\u306e\u9ad8\u3044\u7ffb\u8a33\u30c7\u30fc\u30bf\u3082\u3064\u304f\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u307f\u306a\u3055\u3093\u3082\u3084\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9470 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png\" alt=\"\" width=\"294\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png 294w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13-276x300.png 276w\" sizes=\"auto, (max-width: 294px) 100vw, 294px\" \/>\u300cGo Go \u30ab\u30ec\u30fc\u306f<br \/>\n\u88cf\u5207\u308a\u307e\u305b\u3093\u306a\ud83c\udf5b\u2728\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u79c1\u3082\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u597d\u304d\u306a\u4eba\u9593\u3068\u3057\u3066\u5b9a\u671f\u7684\u306b\u500b\u4eba\u30b5\u30a4\u30c8\u3092\u3064\u304f\u3063\u305f\u308a\u3057\u3066\u3044\u307e\u3059\u3002 \u6b63\u76f4\u306a\u3068\u3053\u308d\u300c\u9cf4\u304b\u305a\u98db\u3070\u305a\u300d\u306a\u30b5\u30a4\u30c8\u3070\u304b\u308a\u3067\u307b\u3068\u3093\u3069\u7d42\u4e86\u3055\u305b\u3066\u304d\u3066\u3044\u308b\u306e\u3067 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=11314\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel + Inertia + React \u3067\u591a\u8a00\u8a9e\u5316\u3059\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":11320,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[247,3,118,249,248],"tags":[],"class_list":["post-11314","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-inertia-js","category-laravel","category-react-js","category-tailwind-css","category-vite"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11314"}],"version-history":[{"count":2,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11314\/revisions"}],"predecessor-version":[{"id":11321,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11314\/revisions\/11321"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/11320"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}