git -C '/home/opc/rocketa.git' show 09cc738 -- app/Translation/DatabaseLoader.phpcommit 09cc738e17d1ad148bf2243e1f04aefe8cde1fc5
Author: Satoshi Ujihara <satoshi_ujihara@fivegate.jp>
Date: Thu Oct 9 10:19:51 2025 +0900
翻訳機能追加+成果受け取りの余計な機能を削除
diff --git a/app/Translation/DatabaseLoader.php b/app/Translation/DatabaseLoader.php
new file mode 100644
index 0000000..f22fda0
--- /dev/null
+++ b/app/Translation/DatabaseLoader.php
@@ -0,0 +1,101 @@
+<?php
+namespace App\Translation;
+
+use Illuminate\Contracts\Translation\Loader;
+use App\Models\Translation;
+use Illuminate\Support\Facades\Request;
+
+class DatabaseLoader implements Loader
+{
+ /**
+ * Load the messages for the given locale and group.
+ *
+ * @param string $locale
+ * @param string $group
+ * @param string|null $namespace
+ * @return array
+ */
+ public function load($locale, $group, $namespace = null)
+ {
+ $model = new Translation();
+ $host = Request::getHost();
+ $table = $this->getTableBySubdomain($host);
+ $model->setTableName($table);
+
+ if ($group === '*') {
+ // JSON翻訳用: 全件取得
+ $records = $model->where('locale', $locale)
+ ->pluck('value', 'key')
+ ->toArray();
+
+ return $records;
+ }
+
+ // 通常 group.key の形式
+ $records = $model->where('locale', $locale)
+ ->where('key', 'like', "$group.%")
+ ->pluck('value', 'key')
+ ->toArray();
+
+ // "messages.welcome" -> "welcome"
+ $translations = [];
+ foreach ($records as $key => $value) {
+ $key = str_replace($group . '.', '', $key);
+ $translations[$key] = $value;
+ }
+
+ return $translations;
+ }
+
+ protected function getTableBySubdomain($host)
+ {
+ switch ($host) {
+ case 'amin.rocket-a.com':
+ return 'translations';
+ case 'client.rocket-a.com':
+ return 'translation_clients';
+ case 'media.rocket-a.com':
+ return 'translation_medias';
+ default:
+ return 'translations';
+ }
+ }
+
+ /**
+ * Add a new namespace to the loader.
+ *
+ * @param string $namespace
+ * @param string $hint
+ * @return void
+ */
+ public function addNamespace($namespace, $hint) {}
+
+ /**
+ * Get the array of registered namespaces.
+ *
+ * @return array
+ */
+ public function namespaces()
+ {
+ return [];
+ }
+
+ /**
+ * Add a new JSON path to the loader.
+ *
+ * @param string $path
+ * @return void
+ */
+ public function addJsonPath($path) {}
+
+ /**
+ * Load the messages from the given JSON paths.
+ *
+ * @param string $locale
+ * @return array
+ */
+ public function loadJsonPaths($locale)
+ {
+ return [];
+ }
+}
\ No newline at end of file